annotate libinterp/corefcn/data.cc @ 32045:f18da620ab4d stable

Fix floating point exception when Sparse array reshaped to 0x0 (bug #64080) * Sparse.cc (reshape): Test for empty matrix (number of rows or columns equal to 0) and immediately return constructed, but unfilled, empty sparse matrix. * data.cc (Freshape): Add BIST test for bug #64080.
author Rik <rik@octave.org>
date Thu, 20 Apr 2023 18:58:57 -0700
parents 073cc98750c6
children 39700c1ea93e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ////////////////////////////////////////////////////////////////////////
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 //
31706
597f3ee61a48 update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 31611
diff changeset
3 // Copyright (C) 1994-2023 The Octave Project Developers
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
4 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 // See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 // distribution or <https://octave.org/copyright/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
7 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
8 // This file is part of Octave.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
9 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
10 // Octave is free software: you can redistribute it and/or modify it
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
11 // under the terms of the GNU General Public License as published by
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
12 // the Free Software Foundation, either version 3 of the License, or
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
13 // (at your option) any later version.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
14 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
15 // Octave is distributed in the hope that it will be useful, but
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
18 // GNU General Public License for more details.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
19 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
20 // You should have received a copy of the GNU General Public License
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
21 // along with Octave; see the file COPYING. If not, see
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
22 // <https://www.gnu.org/licenses/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ////////////////////////////////////////////////////////////////////////
523
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
31605
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 31603
diff changeset
69 OCTAVE_BEGIN_NAMESPACE(octave)
29958
32c3a5805893 move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29955
diff changeset
70
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1940
diff changeset
71 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
72 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
73 @deftypefn {} {@var{tf} =} all (@var{x})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
74 @deftypefnx {} {@var{tf} =} all (@var{x}, @var{dim})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
75 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
76 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
77
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
78 For a matrix argument, return a row vector of logical ones and zeros with each
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
79 element indicating whether all of the elements of the corresponding column of
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
80 the matrix are nonzero. For example:
21966
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 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
83 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
84 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
85 @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
86 @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
87 @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
88
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
89 If the optional argument @var{dim} is supplied, work along dimension @var{dim}.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
90 @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
91 @end deftypefn */)
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
92 {
20943
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
93 int nargin = args.length ();
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
94
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
95 if (nargin < 1 || nargin > 2)
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
96 print_usage ();
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
97
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
98 int dim = (nargin == 1 ? -1
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
99 : args(1).xint_value ("all: DIM must be an integer")-1);
20943
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
100
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
101 if (dim < -1)
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
102 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
103
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
104 return ovl (args(0).all (dim));
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
105 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
106
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
107 /*
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
108 %!test
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
109 %! 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
110 %! x(1,1) = 0;
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
111 %! 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
112 %! 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
113 %! 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
114 %! 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
115
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
116 %!test
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
117 %! 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
118 %! x(1,1) = 0;
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
119 %! 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
120 %! 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
121 %! 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
122 %! 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
123
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
124 %!error all ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
125 %!error all (1, 2, 3)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
126 */
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
127
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1940
diff changeset
128 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
129 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
130 @deftypefn {} {@var{tf} =} any (@var{x})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
131 @deftypefnx {} {@var{tf} =} any (@var{x}, @var{dim})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
132 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
133 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
134
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
135 For a matrix argument, return a row vector of logical ones and zeros with each
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
136 element indicating whether any of the elements of the corresponding column of
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
137 the matrix are nonzero. For example:
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
138
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
139 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
140 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
141 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
142 @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
143 @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
144 @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
145
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
146 If the optional argument @var{dim} is supplied, work along dimension @var{dim}.
31375
96f751f8392c doc: grammar check documentation ahead of 8.1 release.
Rik <rik@octave.org>
parents: 31369
diff changeset
147 For example:
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
148
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
149 @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 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
151 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
152 @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
153 @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
154 @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
155 @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
156 @end deftypefn */)
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
157 {
20943
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
158 int nargin = args.length ();
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
159
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
160 if (nargin < 1 || nargin > 2)
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
161 print_usage ();
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
162
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
163 int dim = (nargin == 1 ? -1
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
164 : args(1).xint_value ("any: DIM must be an integer")-1);
20943
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
165
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
166 if (dim < -1)
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
167 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
168
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
169 return ovl (args(0).any (dim));
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
170 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
171
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
172 /*
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
173 %!test
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
174 %! 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
175 %! x(3,3) = 1;
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
176 %! 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
177 %! 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
178 %! 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
179 %! 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
180
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
181 %!test
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
182 %! 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
183 %! x(3,3) = 1;
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
184 %! 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
185 %! 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
186 %! 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
187 %! 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
188
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
189 %!error any ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
190 %!error any (1, 2, 3)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
191 */
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
192
649
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
193 // 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
194
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1940
diff changeset
195 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
196 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
197 @deftypefn {} {@var{angle} =} atan2 (@var{y}, @var{x})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
198 Compute atan (@var{y} / @var{x}) for corresponding elements of @var{y} and
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
199 @var{x}.
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
200
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
201 @var{y} and @var{x} must match in size and orientation. The signs of elements
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
202 of @var{y} and @var{x} are used to determine the quadrants of each resulting
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
203 value.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
204
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
205 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
206 @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
207 @end deftypefn */)
649
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
208 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
209 if (args.length () != 2)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
210 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
211
4233
ccfdb55c8156 [project @ 2002-12-20 22:43:54 by jwe]
jwe
parents: 4176
diff changeset
212 octave_value retval;
649
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
213
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23585
diff changeset
214 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
215 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
216
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23585
diff changeset
217 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
218 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
219
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
220 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
221 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
222
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
223 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
224 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
225 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
226 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
227 else
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents: 10405
diff changeset
228 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
229 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
230 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
231 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
232 }
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
233 }
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
234 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
235 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
236 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
237 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
238 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
239 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
240 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
241 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
242 retval = binmap<double> (m0, m1, std::atan2, "atan2");
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents: 10405
diff changeset
243 }
7494
bd2bd04e68ca Treat integer types for mod/rem correctly
David Bateman <dbateman@free.fr>
parents: 7433
diff changeset
244 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
245 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
246 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
247 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
248 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
249 }
649
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
250 }
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
251
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
252 return retval;
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
253 }
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
254
7506
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
255 /*
7741
72c0489653ac fix tests
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
256 %!assert (size (atan2 (zeros (0, 2), zeros (0, 2))), [0, 2])
72c0489653ac fix tests
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
257 %!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
258 %!assert (size (atan2 (rand (2, 3, 4), 1)), [2, 3, 4])
72c0489653ac fix tests
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
259 %!assert (size (atan2 (1, rand (2, 3, 4))), [2, 3, 4])
72c0489653ac fix tests
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
260 %!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
261
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
262 %!test
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
263 %! rt2 = sqrt (2);
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
264 %! rt3 = sqrt (3);
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
265 %! 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
266 %! 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
267 %! 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
268 %! 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
269
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
270 %!test
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
271 %! rt2 = sqrt (2);
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
272 %! rt3 = sqrt (3);
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
273 %! 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
274 %! 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
275 %! 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
276 %! 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
277
18789
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
278 ## Test sparse implementations
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
279 %!shared xs
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
280 %! xs = sparse (0:3);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
281 %!test
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
282 %! y = atan2 (1, xs);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
283 %! assert (issparse (y), false);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
284 %! assert (nnz (y), 4);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
285 %! 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
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 (0, 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), 0);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
290 %! 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
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 (xs, 1);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
293 %! assert (issparse (y));
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
294 %! assert (nnz (y), 3);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
295 %! 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
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, 0);
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, 0)));
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, sparse (ones (1, 4)));
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, ones (1,4))));
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 (zeros (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, zeros (1,4))));
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
311
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
312 %!error atan2 ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
313 %!error atan2 (1, 2, 3)
7506
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
314 */
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
315
10538
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
316 static octave_value
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
317 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
318 {
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
319 octave_value retval;
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
320
18100
6a71e5030df5 Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents: 17915
diff changeset
321 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
322 octave_value arg1 = y;
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23585
diff changeset
323 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
324 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
325 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
326 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
327
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
328 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
329 arg0 = arg0.abs ();
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
330 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
331 arg1 = arg1.abs ();
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
332
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
333 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
334 {
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
335 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
336 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
337 else
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
338 {
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
339 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
340 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
341 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
342 }
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
343 }
10538
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
344 else
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
345 {
21118
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
346 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
347 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
348 else if (arg0.issparse () || arg1.issparse ())
10538
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
349 {
21118
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
350 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
351 SparseMatrix m1 = arg1.sparse_matrix_value ();
23625
b0a2367823f5 Use hypot, hypotf from C++ std library.
Rik <rik@octave.org>
parents: 23599
diff changeset
352 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
353 }
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
354 else
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
355 {
21118
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
356 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
357 NDArray a1 = arg1.array_value ();
23625
b0a2367823f5 Use hypot, hypotf from C++ std library.
Rik <rik@octave.org>
parents: 23599
diff changeset
358 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
359 }
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
360 }
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
361
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
362 return retval;
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
363 }
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
364
7631
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
365 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
366 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
367 @deftypefn {} {@var{h} =} hypot (@var{x}, @var{y})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
368 @deftypefnx {} {@var{h} =} hypot (@var{x}, @var{y}, @var{z}, @dots{})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
369 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
370 @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
371
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
372 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
373 @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
374 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
375
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
376 @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
377 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
378
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
379 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
380 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
381 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
382 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
383 @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
384 @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
385 @end deftypefn */)
7631
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
386 {
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
387 int nargin = args.length ();
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
388
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
389 if (nargin < 2)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
390 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
391
7631
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
392 octave_value retval;
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
393
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents: 10405
diff changeset
394 if (nargin == 2)
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
395 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
396 else
10538
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
397 {
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
398 retval = args(0);
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
399
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
400 for (int i = 1; i < nargin; i++)
10538
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
401 retval = do_hypot (retval, args(i));
7631
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
402 }
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
403
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
404 return retval;
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
405 }
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
406
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
407 /*
7741
72c0489653ac fix tests
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
408 %!assert (size (hypot (zeros (0, 2), zeros (0, 2))), [0, 2])
72c0489653ac fix tests
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
409 %!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
410 %!assert (size (hypot (rand (2, 3, 4), 1)), [2, 3, 4])
72c0489653ac fix tests
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
411 %!assert (size (hypot (1, rand (2, 3, 4))), [2, 3, 4])
72c0489653ac fix tests
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
412 %!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
413 %!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
414 %!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
415
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
416 ## Test sparse implementations
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
417 %!shared xs
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
418 %! xs = sparse (0:3);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
419 %!test
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
420 %! y = hypot (1, xs);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
421 %! assert (nnz (y), 4);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
422 %! 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
423 %!test
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
424 %! y = hypot (0, xs);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
425 %! assert (nnz (y), 3);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
426 %! assert (y, xs);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
427 %!test
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
428 %! y = hypot (xs, 1);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
429 %! assert (nnz (y), 4);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
430 %! 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
431 %!test
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
432 %! y = hypot (xs, 0);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
433 %! assert (nnz (y), 3);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
434 %! assert (y, xs);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
435 %!test
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
436 %! 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
437 %! assert (nnz (y), 1);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
438 %! 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
439 %!test
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
440 %! 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
441 %! assert (nnz (y), 1);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
442 %! 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
443
7631
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
444 */
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
445
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
446 template <typename T, typename ET>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
447 void
9813
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
448 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
449 {
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
450 f = Array<T>(x.dims ());
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
451 e = Array<ET>(x.dims ());
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
452 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
453 {
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
454 int exp;
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
455 f.xelem (i) = math::log2 (x(i), exp);
9813
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
456 e.xelem (i) = exp;
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
457 }
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
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
460 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
461 doc: /* -*- texinfo -*-
29817
ba571657651a Improve documentation for log2 function (bug #60817).
Rik <rik@octave.org>
parents: 29654
diff changeset
462 @deftypefn {} {@var{y} =} log2 (@var{x})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
463 @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
464 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
465
29817
ba571657651a Improve documentation for log2 function (bug #60817).
Rik <rik@octave.org>
parents: 29654
diff changeset
466 If called with one output, compute the base-2 logarithm such that
ba571657651a Improve documentation for log2 function (bug #60817).
Rik <rik@octave.org>
parents: 29654
diff changeset
467 @tex
ba571657651a Improve documentation for log2 function (bug #60817).
Rik <rik@octave.org>
parents: 29654
diff changeset
468 $2^y = x$.
ba571657651a Improve documentation for log2 function (bug #60817).
Rik <rik@octave.org>
parents: 29654
diff changeset
469 @end tex
ba571657651a Improve documentation for log2 function (bug #60817).
Rik <rik@octave.org>
parents: 29654
diff changeset
470 @ifnottex
ba571657651a Improve documentation for log2 function (bug #60817).
Rik <rik@octave.org>
parents: 29654
diff changeset
471 @code{2^@var{y} = @var{x}}.
ba571657651a Improve documentation for log2 function (bug #60817).
Rik <rik@octave.org>
parents: 29654
diff changeset
472 @end ifnottex
ba571657651a Improve documentation for log2 function (bug #60817).
Rik <rik@octave.org>
parents: 29654
diff changeset
473
ba571657651a Improve documentation for log2 function (bug #60817).
Rik <rik@octave.org>
parents: 29654
diff changeset
474 If called with two output arguments, split @var{x} into binary mantissa
ba571657651a Improve documentation for log2 function (bug #60817).
Rik <rik@octave.org>
parents: 29654
diff changeset
475 (@var{f}) and exponent (@var{e}) such that
ba571657651a Improve documentation for log2 function (bug #60817).
Rik <rik@octave.org>
parents: 29654
diff changeset
476 @tex
ba571657651a Improve documentation for log2 function (bug #60817).
Rik <rik@octave.org>
parents: 29654
diff changeset
477 $x = f \cdot 2^e$
ba571657651a Improve documentation for log2 function (bug #60817).
Rik <rik@octave.org>
parents: 29654
diff changeset
478 @end tex
ba571657651a Improve documentation for log2 function (bug #60817).
Rik <rik@octave.org>
parents: 29654
diff changeset
479 @ifnottex
ba571657651a Improve documentation for log2 function (bug #60817).
Rik <rik@octave.org>
parents: 29654
diff changeset
480 @code{@var{x} = @var{f} * 2^@var{e}}
ba571657651a Improve documentation for log2 function (bug #60817).
Rik <rik@octave.org>
parents: 29654
diff changeset
481 @end ifnottex
ba571657651a Improve documentation for log2 function (bug #60817).
Rik <rik@octave.org>
parents: 29654
diff changeset
482 where
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
483 @tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
484 ${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
485 @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
486 @ifnottex
29817
ba571657651a Improve documentation for log2 function (bug #60817).
Rik <rik@octave.org>
parents: 29654
diff changeset
487 @w{@code{1/2 <= abs (@var{f}) < 1}}
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
488 @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
489 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
490 @tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
491 $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
492 @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
493 @ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
494 @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
495 @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
496 @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
497 @end deftypefn */)
9813
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
498 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
499 if (args.length () != 1)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
500 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
501
9813
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
502 octave_value_list retval;
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
503
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
504 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
505 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
506 else if (args(0).is_single_type ())
9813
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
507 {
23582
0cc2011d800e maint: Deprecate is_real_type and replace with isreal.
Rik <rik@octave.org>
parents: 23581
diff changeset
508 if (args(0).isreal ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
509 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
510 FloatNDArray f;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
511 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
512 // 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
513 FloatMatrix e;
9813
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
514 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
515 retval = ovl (f, e);
9813
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
516 }
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
517 else if (args(0).iscomplex ())
9813
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
518 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
519 FloatComplexNDArray f;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
520 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
521 // 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
522 FloatNDArray e;
9813
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
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);
9813
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
525 }
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
526 }
23582
0cc2011d800e maint: Deprecate is_real_type and replace with isreal.
Rik <rik@octave.org>
parents: 23581
diff changeset
527 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
528 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
529 NDArray f;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
530 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
531 // 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
532 Matrix e;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
533 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
534 retval = ovl (f, e);
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
535 }
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
536 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
537 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
538 ComplexNDArray f;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
539 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
540 // 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
541 NDArray e;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
542 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
543 retval = ovl (f, e);
9813
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
544 }
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
545 else
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21078
diff changeset
546 err_wrong_type_arg ("log2", args(0));
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 return retval;
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
549 }
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
550
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
551 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
552 %!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
553 %!assert (log2 (Inf), Inf)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
554 %!assert (isnan (log2 (NaN)))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
555 %!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
556 %!assert (log2 (complex (0,Inf)), Inf + log2 (i))
9813
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
557
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
558 %!test
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
559 %! [f, e] = log2 ([0,-1; 2,-4; Inf,-Inf]);
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
560 %! 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
561 %! assert (e(1:2,:), [0,1;2,3]);
9813
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
562
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
563 %!test
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
564 %! [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
565 %! 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
566 %! 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
567
23573
1b4f4ec53b4a use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents: 23572
diff changeset
568 %!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
569 */
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
570
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
571 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
572 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
573 @deftypefn {} {@var{r} =} rem (@var{x}, @var{y})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
574 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
575
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
576 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
577
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
578 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
579 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
580 @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
581
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
582 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
583 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
584
26292
d00577d95369 doc: Add warning note about integers exceeding flintmax to mod, rem (bug #55238).
Rik <rik@octave.org>
parents: 26199
diff changeset
585 Programming Notes: When calculating with floating point numbers (double,
d00577d95369 doc: Add warning note about integers exceeding flintmax to mod, rem (bug #55238).
Rik <rik@octave.org>
parents: 26199
diff changeset
586 single), values within a few eps of an integer will be rounded to that
d00577d95369 doc: Add warning note about integers exceeding flintmax to mod, rem (bug #55238).
Rik <rik@octave.org>
parents: 26199
diff changeset
587 integer before computation for compatibility with @sc{matlab}. Any floating
d00577d95369 doc: Add warning note about integers exceeding flintmax to mod, rem (bug #55238).
Rik <rik@octave.org>
parents: 26199
diff changeset
588 point integers greater than @code{flintmax} (2^53 for double) will not compute
d00577d95369 doc: Add warning note about integers exceeding flintmax to mod, rem (bug #55238).
Rik <rik@octave.org>
parents: 26199
diff changeset
589 correctly. For larger integer values convert the input to @code{uint64} before
d00577d95369 doc: Add warning note about integers exceeding flintmax to mod, rem (bug #55238).
Rik <rik@octave.org>
parents: 26199
diff changeset
590 calling this function.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
591
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
592 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
593
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
594 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
595 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
596 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
597 rem (@var{x}, 0) = 0 if @var{x} is an integer variable
26292
d00577d95369 doc: Add warning note about integers exceeding flintmax to mod, rem (bug #55238).
Rik <rik@octave.org>
parents: 26199
diff changeset
598 rem (@var{x}, @var{y}) returns a value with the signbit from @var{x}
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
599 @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
600 @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
601
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
602 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
603 @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
604 @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
605 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
606 @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
607 @end deftypefn */)
4311
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
608 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
609 if (args.length () != 2)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
610 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
611
4311
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
612 octave_value retval;
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
613
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23585
diff changeset
614 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
615 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
616
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23585
diff changeset
617 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
618 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
619
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
620 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
621 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
622
23580
2230f9e10fb3 maint: Deprecate is_integer_type and replace with isinteger.
Rik <rik@octave.org>
parents: 23579
diff changeset
623 if (args(0).isinteger () || args(1).isinteger ())
4311
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
624 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
625 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
626 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
627 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
628 btyp0 = btyp1;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
629 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
630 btyp1 = btyp0;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
631
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
632 if (btyp0 != btyp1)
26107
05dfcb24ef12 Supply missing arguments to variable length *printf functions (bug #55046).
Rik <rik@octave.org>
parents: 26046
diff changeset
633 error ("rem: cannot combine %s and %s",
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
634 args(0).class_name ().c_str (),
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
635 args(1).class_name ().c_str ());
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
636
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
637 switch (btyp0)
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
638 {
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
639 #define MAKE_INT_BRANCH(X) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
640 case btyp_ ## X: \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
641 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
642 X##NDArray a0 = args(0).X##_array_value (); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
643 X##NDArray a1 = args(1).X##_array_value (); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
644 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
645 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
646 break
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
647
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
648 MAKE_INT_BRANCH (int8);
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
649 MAKE_INT_BRANCH (int16);
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
650 MAKE_INT_BRANCH (int32);
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
651 MAKE_INT_BRANCH (int64);
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
652 MAKE_INT_BRANCH (uint8);
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
653 MAKE_INT_BRANCH (uint16);
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
654 MAKE_INT_BRANCH (uint32);
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
655 MAKE_INT_BRANCH (uint64);
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
656
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
657 #undef MAKE_INT_BRANCH
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
658
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
659 default:
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
660 panic_impossible ();
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
661 }
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 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
664 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
665 if (args(0).is_scalar_type () && args(1).is_scalar_type ())
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
666 retval = 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
667 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
668 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
669 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
670 FloatNDArray a1 = args(1).float_array_value ();
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
671 retval = binmap<float> (a0, a1, math::rem<float>, "rem");
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
672 }
4311
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
673 }
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
674 else
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
675 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
676 if (args(0).is_scalar_type () && args(1).is_scalar_type ())
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
677 retval = 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
678 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
679 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
680 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
681 SparseMatrix m1 = args(1).sparse_matrix_value ();
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
682 retval = binmap<double> (m0, m1, math::rem<double>, "rem");
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
683 }
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents: 10405
diff changeset
684 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
685 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
686 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
687 NDArray a1 = args(1).array_value ();
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
688 retval = binmap<double> (a0, a1, math::rem<double>, "rem");
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
689 }
4311
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
690 }
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
691
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
692 return retval;
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
693 }
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
694
7506
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
695 /*
19118
9c5a17d5fc19 Deprecate fmod function.
Rik <rik@octave.org>
parents: 19079
diff changeset
696 %!assert (size (rem (zeros (0, 2), zeros (0, 2))), [0, 2])
9c5a17d5fc19 Deprecate fmod function.
Rik <rik@octave.org>
parents: 19079
diff changeset
697 %!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
698 %!assert (size (rem (rand (2, 3, 4), 1)), [2, 3, 4])
9c5a17d5fc19 Deprecate fmod function.
Rik <rik@octave.org>
parents: 19079
diff changeset
699 %!assert (size (rem (1, rand (2, 3, 4))), [2, 3, 4])
9c5a17d5fc19 Deprecate fmod function.
Rik <rik@octave.org>
parents: 19079
diff changeset
700 %!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
701
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
702 %!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
703 %!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
704 %!assert (rem ([0, 1, 2], [0, 0, 1]), [NaN, NaN, 0])
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
705 %!assert (rem (uint8 ([1, 2, 3; -1, -2, -3]), uint8 (2)),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
706 %! uint8 ([1, 0, 1; -1, 0, -1]))
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
707 %!assert (uint8 (rem ([1, 2, 3; -1, -2, -3], 2 * ones (2, 3))),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
708 %! 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
709 %!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
710
18789
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
711 ## Test sparse implementations
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
712 %!shared xs
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
713 %! xs = sparse (0:3);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
714 %!test
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
715 %! 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
716 %! 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
717 %! 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
718 %!test
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
719 %! 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
720 %! assert (nnz (y), 1);
0cefba1a1030 Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents: 20232
diff changeset
721 %! 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
722 %!test
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
723 %! y = rem (xs, 2);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
724 %! assert (nnz (y), 2);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
725 %! 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
726 %!test
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
727 %! y = rem (xs, 1);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
728 %! assert (nnz (y), 0);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
729 %! 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
730 %!test
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
731 %! 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
732 %! assert (nnz (y), 3);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
733 %! 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
734 %!test
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
735 %! 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
736 %! assert (nnz (y), 1);
0cefba1a1030 Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents: 20232
diff changeset
737 %! 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
738
23573
1b4f4ec53b4a use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents: 23572
diff changeset
739 %!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
740 %!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
741
1b4f4ec53b4a use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents: 23572
diff changeset
742 %!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
743
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
744 %!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
745 %!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
746 %!error rem ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
747 %!error rem (1, 2, 3)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
748 %!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
749 %!error rem (i, 1)
7506
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
750 */
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
751
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
752 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
753 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
754 @deftypefn {} {@var{m} =} mod (@var{x}, @var{y})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
755 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
756
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
757 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
758
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
759 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
760 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
761 @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
762
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
763 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
764 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
765 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
766 @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
767
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
768 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
769 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
770
26292
d00577d95369 doc: Add warning note about integers exceeding flintmax to mod, rem (bug #55238).
Rik <rik@octave.org>
parents: 26199
diff changeset
771 Programming Notes: When calculating with floating point numbers (double,
d00577d95369 doc: Add warning note about integers exceeding flintmax to mod, rem (bug #55238).
Rik <rik@octave.org>
parents: 26199
diff changeset
772 single), values within a few eps of an integer will be rounded to that
d00577d95369 doc: Add warning note about integers exceeding flintmax to mod, rem (bug #55238).
Rik <rik@octave.org>
parents: 26199
diff changeset
773 integer before computation for compatibility with @sc{matlab}. Any floating
d00577d95369 doc: Add warning note about integers exceeding flintmax to mod, rem (bug #55238).
Rik <rik@octave.org>
parents: 26199
diff changeset
774 point integers greater than @code{flintmax} (2^53 for double) will not compute
d00577d95369 doc: Add warning note about integers exceeding flintmax to mod, rem (bug #55238).
Rik <rik@octave.org>
parents: 26199
diff changeset
775 correctly. For larger integer values convert the input to @code{uint64} before
d00577d95369 doc: Add warning note about integers exceeding flintmax to mod, rem (bug #55238).
Rik <rik@octave.org>
parents: 26199
diff changeset
776 calling this function.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
777
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
778 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
779
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
780 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
781 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
782 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
783 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
784 @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
785 @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
786
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
787 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
788 @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
789 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
790 @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
791 @end deftypefn */)
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
792 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
793 if (args.length () != 2)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
794 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
795
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
796 octave_value retval;
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
797
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23585
diff changeset
798 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
799 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
800
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23585
diff changeset
801 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
802 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
803
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
804 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
805 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
806
23580
2230f9e10fb3 maint: Deprecate is_integer_type and replace with isinteger.
Rik <rik@octave.org>
parents: 23579
diff changeset
807 if (args(0).isinteger () || args(1).isinteger ())
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
808 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
809 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
810 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
811 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
812 btyp0 = btyp1;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
813 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
814 btyp1 = btyp0;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
815
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
816 if (btyp0 != btyp1)
26107
05dfcb24ef12 Supply missing arguments to variable length *printf functions (bug #55046).
Rik <rik@octave.org>
parents: 26046
diff changeset
817 error ("mod: cannot combine %s and %s",
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
818 args(0).class_name ().c_str (),
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
819 args(1).class_name ().c_str ());
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
820
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
821 switch (btyp0)
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
822 {
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
823 #define MAKE_INT_BRANCH(X) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
824 case btyp_ ## X: \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
825 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
826 X##NDArray a0 = args(0).X##_array_value (); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
827 X##NDArray a1 = args(1).X##_array_value (); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
828 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
829 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
830 break
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
831
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
832 MAKE_INT_BRANCH (int8);
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
833 MAKE_INT_BRANCH (int16);
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
834 MAKE_INT_BRANCH (int32);
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
835 MAKE_INT_BRANCH (int64);
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
836 MAKE_INT_BRANCH (uint8);
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
837 MAKE_INT_BRANCH (uint16);
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
838 MAKE_INT_BRANCH (uint32);
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
839 MAKE_INT_BRANCH (uint64);
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
840
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
841 #undef MAKE_INT_BRANCH
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
842
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
843 default:
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
844 panic_impossible ();
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
845 }
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
846 }
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
847 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
848 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
849 if (args(0).is_scalar_type () && args(1).is_scalar_type ())
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
850 retval = 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
851 else
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
852 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
853 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
854 FloatNDArray a1 = args(1).float_array_value ();
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
855 retval = binmap<float> (a0, a1, math::mod<float>, "mod");
10436
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 else
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
859 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
860 if (args(0).is_scalar_type () && args(1).is_scalar_type ())
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
861 retval = 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
862 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
863 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
864 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
865 SparseMatrix m1 = args(1).sparse_matrix_value ();
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
866 retval = binmap<double> (m0, m1, math::mod<double>, "mod");
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
867 }
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
868 else
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
869 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
870 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
871 NDArray a1 = args(1).array_value ();
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
872 retval = binmap<double> (a0, a1, math::mod<double>, "mod");
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
873 }
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
874 }
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
875
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
876 return retval;
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
877 }
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
878
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
879 /*
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
880 ## empty input test
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
881 %!assert (isempty (mod ([], [])))
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
882
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
883 ## 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
884 %!assert (mod (5, 3), 2)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
885 %!assert (mod (-5, 3), 1)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
886 %!assert (mod (0, 3), 0)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
887 %!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
888 %!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
889 %!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
890
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
891 ## x mod 0 tests
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
892 %!assert (mod (5, 0), 5)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
893 %!assert (mod (-5, 0), -5)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
894 %!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
895 %!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
896 %!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
897 %!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
898
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
899 ## mixed scalar/matrix tests
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
900 %!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
901 %!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
902 %!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
903 %!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
904 %!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
905
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
906 ## integer types
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
907 %!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
908 %!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
909 %!assert (mod (uint8 ([1:5]), uint8 (0)), uint8 ([1:5]))
28930
2883b3d08b7e maint: Remove unnecessary parentheses bracketing %!error BIST tests.
Rik <rik@octave.org>
parents: 28919
diff changeset
910 %!error mod (uint8 (5), int8 (4))
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
911
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
912 ## mixed integer/real types
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
913 %!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
914 %!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
915 %!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
916
903c1a3df301 Add additional tests for mod with non-integer real values.
Rik <octave@nomad.inbox5.com>
parents: 11242
diff changeset
917 ## non-integer real numbers
903c1a3df301 Add additional tests for mod with non-integer real values.
Rik <octave@nomad.inbox5.com>
parents: 11242
diff changeset
918 %!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
919 %!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
920
23573
1b4f4ec53b4a use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents: 23572
diff changeset
921 %!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
922 %!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
923
1b4f4ec53b4a use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents: 23572
diff changeset
924 %!assert <*42627> (mod (0.94, 0.01), 0.0)
25858
1f52a96c8c21 Fix mod operation for signed integer types (bug #54602).
Gene Harvey <gharveymn@gmail.com>
parents: 25578
diff changeset
925
1f52a96c8c21 Fix mod operation for signed integer types (bug #54602).
Gene Harvey <gharveymn@gmail.com>
parents: 25578
diff changeset
926 %!assert <*54602> (mod (int8 (125), int8 (-25)), int8 (0))
1f52a96c8c21 Fix mod operation for signed integer types (bug #54602).
Gene Harvey <gharveymn@gmail.com>
parents: 25578
diff changeset
927 %!assert <*54602> (mod (int8 (-125), int8 (-25)), int8 (0))
25860
60fd3c44769f Fix BIST test in cset 1f52a96c8c21.
Rik <rik@octave.org>
parents: 25858
diff changeset
928 %!assert <*54602> (mod (int8 (-125), int8 (0)), int8 (-125))
25858
1f52a96c8c21 Fix mod operation for signed integer types (bug #54602).
Gene Harvey <gharveymn@gmail.com>
parents: 25578
diff changeset
929 %!assert <*54602> (mod (int8 (0), int8 (-25)), int8 (0))
1f52a96c8c21 Fix mod operation for signed integer types (bug #54602).
Gene Harvey <gharveymn@gmail.com>
parents: 25578
diff changeset
930
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
931 */
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
932
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
933 #define DATA_REDUCTION(FCN) \
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 int nargin = args.length (); \
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 if (nargin < 1 || nargin > 2) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
938 print_usage (); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
939 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
940 octave_value retval; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
941 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
942 octave_value arg = args(0); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
943 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
944 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
945 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
946 if (dim < -1) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
947 error (#FCN ": invalid dimension argument = %d", dim + 1); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
948 \
23582
0cc2011d800e maint: Deprecate is_real_type and replace with isreal.
Rik <rik@octave.org>
parents: 23581
diff changeset
949 if (arg.isreal ()) \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
950 { \
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
951 if (arg.issparse ()) \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
952 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
953 SparseMatrix tmp = arg.sparse_matrix_value (); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
954 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
955 retval = tmp.FCN (dim); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
956 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
957 else if (arg.is_single_type ()) \
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 FloatNDArray tmp = arg.float_array_value (); \
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 retval = tmp.FCN (dim); \
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 else \
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 NDArray tmp = arg.array_value (); \
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 retval = tmp.FCN (dim); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
968 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
969 } \
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
970 else if (arg.iscomplex ()) \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
971 { \
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
972 if (arg.issparse ()) \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
973 { \
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
974 SparseComplexMatrix tmp = arg.sparse_complex_matrix_value (); \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
975 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
976 retval = tmp.FCN (dim); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
977 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
978 else if (arg.is_single_type ()) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
979 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
980 FloatComplexNDArray tmp \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
981 = arg.float_complex_array_value (); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
982 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
983 retval = tmp.FCN (dim); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
984 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
985 else \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
986 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
987 ComplexNDArray tmp = arg.complex_array_value (); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
988 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
989 retval = tmp.FCN (dim); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
990 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
991 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
992 else \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
993 err_wrong_type_arg (#FCN, arg); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
994 \
3723
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
995 return retval
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
996
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1940
diff changeset
997 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
998 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
999 @deftypefn {} {@var{y} =} cumprod (@var{x})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
1000 @deftypefnx {} {@var{y} =} cumprod (@var{x}, @var{dim})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1001 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
1002
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1003 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
1004 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
1005
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1006 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1007 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1008 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
1009 @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
1010 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
1011 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
1012 @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
1013 @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
1014 @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
1015 @end deftypefn */)
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1016 {
3723
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
1017 DATA_REDUCTION (cumprod);
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1018 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1019
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1020 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1021 %!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
1022 %!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
1023 %!assert (cumprod ([i, 2+i, -3+2i, 4]), [i, -1+2i, -1-8i, -4-32i])
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1024 %!assert (cumprod ([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i]),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1025 %! [1, 2, 3; i, 4i, 9i; -1+i, -8+8i, -27+27i])
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1026
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1027 %!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
1028 %!assert (cumprod (single ([-1; -2; -3])), single ([-1; 2; -6]))
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1029 %!assert (cumprod (single ([i, 2+i, -3+2i, 4])),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1030 %! single ([i, -1+2i, -1-8i, -4-32i]))
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1031 %!assert (cumprod (single ([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i])),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1032 %! single ([1, 2, 3; i, 4i, 9i; -1+i, -8+8i, -27+27i]))
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1033
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1034 %!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
1035 %!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
1036
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1037 %!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
1038 %!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
1039
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1040 %!error cumprod ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1041 */
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1042
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1940
diff changeset
1043 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
1044 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
1045 @deftypefn {} {@var{y} =} cumsum (@var{x})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
1046 @deftypefnx {} {@var{y} =} cumsum (@var{x}, @var{dim})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
1047 @deftypefnx {} {@var{y} =} cumsum (@dots{}, "native")
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
1048 @deftypefnx {} {@var{y} =} cumsum (@dots{}, "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
1049 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
1050
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1051 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
1052 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
1053
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1054 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1055 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1056 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
1057 @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
1058 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
1059 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
1060 @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
1061 @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
1062
28960
e5a1087f15d5 doc: Use @xref, @pxref rather than "see @code{}" in TexInfo in libinterp/
Rik <rik@octave.org>
parents: 28930
diff changeset
1063 For an explanation of the optional parameters @qcode{"native"} and
e5a1087f15d5 doc: Use @xref, @pxref rather than "see @code{}" in TexInfo in libinterp/
Rik <rik@octave.org>
parents: 28930
diff changeset
1064 @qcode{"double"}, @pxref{XREFsum,,@code{sum}}.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1065 @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
1066 @end deftypefn */)
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1067 {
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1068 int nargin = args.length ();
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1069
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1070 bool isnative = false;
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1071 bool isdouble = false;
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1072
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1073 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
1074 {
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1075 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
1076
19743
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
1077 if (str == "native")
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
1078 isnative = true;
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
1079 else if (str == "double")
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
1080 isdouble = true;
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
1081 else
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
1082 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
1083
21062
d9c1884d1aaa maint: Eliminate space between variable and decrement '--' operator.
Rik <rik@octave.org>
parents: 21055
diff changeset
1084 nargin--;
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1085 }
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1086
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1087 if (nargin < 1 || nargin > 2)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1088 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1089
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1090 int dim = -1;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1091 if (nargin == 2)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1092 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1093 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
1094 if (dim < 0)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1095 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
1096 }
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1097
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
1098 octave_value retval;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
1099 octave_value arg = args(0);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
1100
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1101 switch (arg.builtin_type ())
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1102 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1103 case btyp_double:
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
1104 if (arg.issparse ())
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1105 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
1106 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1107 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
1108 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1109 case btyp_complex:
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
1110 if (arg.issparse ())
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1111 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
1112 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1113 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
1114 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1115 case btyp_float:
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1116 if (isdouble)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1117 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
1118 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1119 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
1120 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1121 case btyp_float_complex:
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1122 if (isdouble)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1123 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
1124 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1125 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
1126 break;
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1127
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
1128 #define MAKE_INT_BRANCH(X) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
1129 case btyp_ ## X: \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
1130 if (isnative) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
1131 retval = arg.X ## _array_value ().cumsum (dim); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
1132 else \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
1133 retval = arg.array_value ().cumsum (dim); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
1134 break;
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1135
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1136 MAKE_INT_BRANCH (int8);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1137 MAKE_INT_BRANCH (int16);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1138 MAKE_INT_BRANCH (int32);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1139 MAKE_INT_BRANCH (int64);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1140 MAKE_INT_BRANCH (uint8);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1141 MAKE_INT_BRANCH (uint16);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1142 MAKE_INT_BRANCH (uint32);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1143 MAKE_INT_BRANCH (uint64);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1144
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1145 #undef MAKE_INT_BRANCH
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1146
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1147 case btyp_bool:
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
1148 if (arg.issparse ())
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1149 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1150 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
1151 if (isnative)
26357
bba4b338757d data.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents: 26292
diff changeset
1152 retval = (cs != 0.0);
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1153 else
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1154 retval = cs;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1155 }
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1156 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1157 {
22773
7f70e420e342 deprecate boolNDArray::sum and boolNDArray::cumsum
John W. Eaton <jwe@octave.org>
parents: 22763
diff changeset
1158 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
1159 if (isnative)
26357
bba4b338757d data.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents: 26292
diff changeset
1160 retval = (cs != 0.0);
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1161 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1162 retval = cs;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1163 }
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1164 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1165
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1166 default:
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21078
diff changeset
1167 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
1168 }
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1169
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1170 return retval;
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1171 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1172
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1173 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1174 %!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
1175 %!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
1176 %!assert (cumsum ([i, 2+i, -3+2i, 4]), [i, 2+2i, -1+4i, 3+4i])
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1177 %!assert (cumsum ([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i]),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1178 %! [1, 2, 3; 1+i, 2+2i, 3+3i; 2+2i, 4+4i, 6+6i])
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1179
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1180 %!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
1181 %!assert (cumsum (single ([-1; -2; -3])), single ([-1; -3; -6]))
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1182 %!assert (cumsum (single ([i, 2+i, -3+2i, 4])),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1183 %! single ([i, 2+2i, -1+4i, 3+4i]))
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1184 %!assert (cumsum (single ([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i])),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1185 %! single ([1, 2, 3; 1+i, 2+2i, 3+3i; 2+2i, 4+4i, 6+6i]))
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1186
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1187 %!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
1188 %!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
1189
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1190 %!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
1191 %!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
1192
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1193 %!error cumsum ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1194 */
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1195
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1940
diff changeset
1196 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
1197 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
1198 @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
1199 @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
1200 @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
1201 @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
1202 @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
1203 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
1204
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1205 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
1206 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
1207 @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
1208 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
1209
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1210 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1211 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1212 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
1213 @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
1214 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
1215 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
1216 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
1217 @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
1218 @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
1219
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1220 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1221 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
1222 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
1223 columns.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1224
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1225 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
1226 @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
1227 @end deftypefn */)
523
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 int nargin = args.length ();
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1230
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1231 if (nargin < 1 || nargin > 3)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1232 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1233
4233
ccfdb55c8156 [project @ 2002-12-20 22:43:54 by jwe]
jwe
parents: 4176
diff changeset
1234 octave_value retval;
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1235
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1236 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
1237 retval = args(0).diag ();
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1238 else if (nargin == 2)
7620
36594d5bbe13 Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents: 7618
diff changeset
1239 {
21041
63374982750b Usage of corresponding value extractor for octave_idx_type. Improves support
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 21014
diff changeset
1240 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
1241
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20700
diff changeset
1242 retval = args(0).diag (k);
7620
36594d5bbe13 Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents: 7618
diff changeset
1243 }
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1244 else
12570
1a93988610a3 Reverse changset cc8ccdfec424. Restore 3-input form of diag().
Rik <octave@nomad.inbox5.com>
parents: 12567
diff changeset
1245 {
1a93988610a3 Reverse changset cc8ccdfec424. Restore 3-input form of diag().
Rik <octave@nomad.inbox5.com>
parents: 12567
diff changeset
1246 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
1247
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1248 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
1249 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
1250
27325
983dab0902f7 More explicit error messages for invalid 2nd and 3rd inputs to diag().
Rik <rik@octave.org>
parents: 27324
diff changeset
1251 octave_idx_type m = args(1).xidx_type_value ("diag: invalid dimension M");
983dab0902f7 More explicit error messages for invalid 2nd and 3rd inputs to diag().
Rik <rik@octave.org>
parents: 27324
diff changeset
1252 octave_idx_type n = args(2).xidx_type_value ("diag: invalid dimension N");
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1253
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1254 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
1255 }
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1256
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1257 return retval;
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1258 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1259
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
1260 /*
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
1261
14843
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1262 %!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
1263 %!assert (diag ([1; 2; 3], 1), [0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0])
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1264 %!assert (diag ([1; 2; 3], 2),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1265 %! [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])
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1266 %!assert (diag ([1; 2; 3],-1),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1267 %! [0 0 0 0; 1 0 0 0; 0 2 0 0; 0 0 3 0])
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1268 %!assert (diag ([1; 2; 3],-2),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1269 %! [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])
14843
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1270
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1271 %!assert (diag ([1, 0, 0; 0, 2, 0; 0, 0, 3]), [1; 2; 3])
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1272 %!assert (diag ([0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0], 1),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1273 %! [1; 2; 3])
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1274 %!assert (diag ([0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0], -1),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1275 %! [1; 2; 3])
14843
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1276 %!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
1277 %!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
1278
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1279 %!assert (full (diag (single ([1; 2; 3]))),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1280 %! single ([1, 0, 0; 0, 2, 0; 0, 0, 3]))
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1281 %!assert (diag (single ([1; 2; 3]), 1),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1282 %! single ([0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0]))
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1283 %!assert (diag (single ([1; 2; 3]), 2),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1284 %! 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]))
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1285 %!assert (diag (single ([1; 2; 3]),-1),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1286 %! single ([0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0]))
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1287 %!assert (diag (single ([1; 2; 3]),-2),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1288 %! 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]))
14843
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1289
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1290 %!assert (diag (single ([1, 0, 0; 0, 2, 0; 0, 0, 3])), single ([1; 2; 3]))
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1291 %!assert (diag (single ([0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0]), 1),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1292 %! single ([1; 2; 3]))
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1293 %!assert (diag (single ([0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0]), -1),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1294 %! single ([1; 2; 3]))
14843
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1295
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1296 %!assert (diag (int8 ([1; 2; 3])), int8 ([1, 0, 0; 0, 2, 0; 0, 0, 3]))
30402
1ef9fca2db06 maint: strip trailing spaces from codebase.
Rik <rik@octave.org>
parents: 30391
diff changeset
1297 %!assert (diag (int8 ([1; 2; 3]), 1),
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1298 %! int8 ([0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0]))
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1299 %!assert (diag (int8 ([1; 2; 3]), 2),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1300 %! 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]))
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1301 %!assert (diag (int8 ([1; 2; 3]),-1),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1302 %! int8 ([0 0 0 0; 1 0 0 0; 0 2 0 0; 0 0 3 0]))
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1303 %!assert (diag (int8 ([1; 2; 3]),-2),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1304 %! 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]))
14843
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1305
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1306 %!assert (diag (int8 ([1, 0, 0; 0, 2, 0; 0, 0, 3])), int8 ([1; 2; 3]))
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1307 %!assert (diag (int8 ([0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0]), 1),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1308 %! int8 ([1; 2; 3]))
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1309 %!assert (diag (int8 ([0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0]), -1),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1310 %! 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
1311
27325
983dab0902f7 More explicit error messages for invalid 2nd and 3rd inputs to diag().
Rik <rik@octave.org>
parents: 27324
diff changeset
1312 %!assert (diag (1, 3, 3), diag ([1, 0, 0]))
983dab0902f7 More explicit error messages for invalid 2nd and 3rd inputs to diag().
Rik <rik@octave.org>
parents: 27324
diff changeset
1313 %!assert (diag (i, 3, 3), diag ([i, 0, 0]))
983dab0902f7 More explicit error messages for invalid 2nd and 3rd inputs to diag().
Rik <rik@octave.org>
parents: 27324
diff changeset
1314 %!assert (diag (single (1), 3, 3), diag ([single(1), 0, 0]))
983dab0902f7 More explicit error messages for invalid 2nd and 3rd inputs to diag().
Rik <rik@octave.org>
parents: 27324
diff changeset
1315 %!assert (diag (single (i), 3, 3), diag ([single(i), 0, 0]))
983dab0902f7 More explicit error messages for invalid 2nd and 3rd inputs to diag().
Rik <rik@octave.org>
parents: 27324
diff changeset
1316 %!assert (diag ([1, 2], 3, 3), diag ([1, 2, 0]))
983dab0902f7 More explicit error messages for invalid 2nd and 3rd inputs to diag().
Rik <rik@octave.org>
parents: 27324
diff changeset
1317 %!assert (diag ([1, 2]*i, 3, 3), diag ([1, 2, 0]*i))
983dab0902f7 More explicit error messages for invalid 2nd and 3rd inputs to diag().
Rik <rik@octave.org>
parents: 27324
diff changeset
1318 %!assert (diag (single ([1, 2]), 3, 3), diag (single ([1, 2, 0])))
983dab0902f7 More explicit error messages for invalid 2nd and 3rd inputs to diag().
Rik <rik@octave.org>
parents: 27324
diff changeset
1319 %!assert (diag (single ([1, 2]*i), 3, 3), diag (single ([1, 2, 0]*i)))
983dab0902f7 More explicit error messages for invalid 2nd and 3rd inputs to diag().
Rik <rik@octave.org>
parents: 27324
diff changeset
1320
23573
1b4f4ec53b4a use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents: 23572
diff changeset
1321 %!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
1322 %!assert <*37411> (diag (diag ([5, 2, 3])(:,1), 2), [0 0 5 0 0; zeros(4, 5)])
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1323 %!assert <*37411> (diag (diag ([5, 2, 3])(:,1), -2),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1324 %! [[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
1325
14490
3959f3f81e33 Initialise memory in non-square diag call (bug #35946)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14171
diff changeset
1326 ## 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
1327 %!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
1328 %!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
1329 %!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
1330 %!assert (diag ({1,2}, 3, 4), {1,[],[],[]; [],2,[],[]; [],[],[],[]})
27323
1582a6140275 Stop segfault when calling 3-input form of diag with cell arrays (bug #56711).
Rik <rik@octave.org>
parents: 27081
diff changeset
1331 %!assert <*56711> (diag ({1,2,3}, 2, 1), {1; []})
14490
3959f3f81e33 Initialise memory in non-square diag call (bug #35946)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14171
diff changeset
1332
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
1333 ## 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
1334 %!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
1335 %!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
1336 %!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
1337
22737
7abc25e6206a maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22708
diff changeset
1338 ## Test input validation
14491
5bd9e47e9277 maint: periodic merge of stable to default
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14429 14490
diff changeset
1339 %!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
1340 %!error <Invalid call to diag> diag (1,2,3,4)
27325
983dab0902f7 More explicit error messages for invalid 2nd and 3rd inputs to diag().
Rik <rik@octave.org>
parents: 27324
diff changeset
1341 %!error <V must be a vector> diag (ones (2), 3, 3)
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1342 %!error diag (1:3, -4, 3)
27325
983dab0902f7 More explicit error messages for invalid 2nd and 3rd inputs to diag().
Rik <rik@octave.org>
parents: 27324
diff changeset
1343 %!error diag (1:3, 4, -3)
983dab0902f7 More explicit error messages for invalid 2nd and 3rd inputs to diag().
Rik <rik@octave.org>
parents: 27324
diff changeset
1344
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
1345 */
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
1346
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1940
diff changeset
1347 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
1348 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
1349 @deftypefn {} {@var{y} =} prod (@var{x})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
1350 @deftypefnx {} {@var{y} =} prod (@var{x}, @var{dim})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
1351 @deftypefnx {} {@var{y} =} prod (@dots{}, "native")
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
1352 @deftypefnx {} {@var{y} =} prod (@dots{}, "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
1353 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
1354
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1355 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
1356
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1357 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
1358 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
1359 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
1360 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
1361
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1362 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
1363
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1364 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1365 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1366 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
1367 @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
1368 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
1369 @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
1370 @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
1371 @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
1372
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1373 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
1374 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
1375 @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
1376 @end deftypefn */)
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1377 {
18725
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1378 int nargin = args.length ();
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1379
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1380 bool isnative = false;
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1381 bool isdouble = false;
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1382
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1383 if (nargin > 1 && args(nargin - 1).is_string ())
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1384 {
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1385 std::string str = args(nargin - 1).string_value ();
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1386
19743
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
1387 if (str == "native")
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
1388 isnative = true;
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
1389 else if (str == "double")
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
1390 isdouble = true;
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
1391 else
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
1392 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
1393
21062
d9c1884d1aaa maint: Eliminate space between variable and decrement '--' operator.
Rik <rik@octave.org>
parents: 21055
diff changeset
1394 nargin--;
18725
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1395 }
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1396
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1397 if (nargin < 1 || nargin > 2)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1398 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1399
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
1400 octave_value retval;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
1401
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1402 octave_value arg = args(0);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1403
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1404 int dim = -1;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1405 if (nargin == 2)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1406 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1407 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
1408 if (dim < 0)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1409 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
1410 }
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1411
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1412 switch (arg.builtin_type ())
18725
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1413 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1414 case btyp_double:
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
1415 if (arg.issparse ())
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1416 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
1417 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1418 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
1419 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1420 case btyp_complex:
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
1421 if (arg.issparse ())
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1422 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
1423 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1424 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
1425 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1426 case btyp_float:
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1427 if (isdouble)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1428 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
1429 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1430 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
1431 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1432 case btyp_float_complex:
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1433 if (isdouble)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1434 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
1435 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1436 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
1437 break;
18725
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1438
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
1439 #define MAKE_INT_BRANCH(X) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
1440 case btyp_ ## X: \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
1441 if (isnative) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
1442 retval = arg.X ## _array_value ().prod (dim); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
1443 else \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
1444 retval = arg.array_value ().prod (dim); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
1445 break;
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1446
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1447 MAKE_INT_BRANCH (int8);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1448 MAKE_INT_BRANCH (int16);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1449 MAKE_INT_BRANCH (int32);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1450 MAKE_INT_BRANCH (int64);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1451 MAKE_INT_BRANCH (uint8);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1452 MAKE_INT_BRANCH (uint16);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1453 MAKE_INT_BRANCH (uint32);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1454 MAKE_INT_BRANCH (uint64);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1455
18725
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1456 #undef MAKE_INT_BRANCH
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1457
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
1458 // GAGME: Accursed Matlab compatibility...
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1459 case btyp_char:
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1460 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
1461 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1462
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1463 case btyp_bool:
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
1464 if (arg.issparse ())
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1465 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1466 if (isnative)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1467 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
1468 else
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1469 retval = arg.sparse_matrix_value ().prod (dim);
18725
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1470 }
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1471 else if (isnative)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1472 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
1473 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1474 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
1475 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1476
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1477 default:
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21078
diff changeset
1478 err_wrong_type_arg ("prod", arg);
18725
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1479 }
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1480
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1481 return retval;
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1482 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1483
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1484 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1485 %!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
1486 %!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
1487 %!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
1488 %!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
1489
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1490 %!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
1491 %!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
1492 %!assert (prod (single ([i, 2+i, -3+2i, 4])), single (-4 - 32i))
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1493 %!assert (prod (single ([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i])),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1494 %! single ([-1+i, -8+8i, -27+27i]))
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1495
22737
7abc25e6206a maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22708
diff changeset
1496 ## Test sparse
18725
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1497 %!assert (prod (sparse ([1, 2, 3])), sparse (6))
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1498 %!assert (prod (sparse ([-1; -2; -3])), sparse (-6))
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1499 ## Commented out until bug #42290 is fixed
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1500 #%!assert (prod (sparse ([i, 2+i, -3+2i, 4])), sparse (-4 - 32i))
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1501 #%!assert (prod (sparse ([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i])),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1502 #%! sparse ([-1+i, -8+8i, -27+27i]))
18725
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1503
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1504 %!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
1505 %!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
1506 %!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
1507 %!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
1508 %!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
1509 %!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
1510 %!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
1511 %!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
1512 %!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
1513 %!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
1514 %!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
1515 %!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
1516 %!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
1517 %!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
1518
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1519 %!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
1520 %!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
1521 %!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
1522 %!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
1523 %!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
1524 %!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
1525 %!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
1526 %!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
1527 %!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
1528 %!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
1529 %!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
1530 %!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
1531 %!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
1532 %!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
1533
22737
7abc25e6206a maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22708
diff changeset
1534 ## Test "double" type argument
18725
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1535 %!assert (prod (single ([1, 2, 3]), "double"), 6)
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1536 %!assert (prod (single ([-1; -2; -3]), "double"), -6)
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1537 %!assert (prod (single ([i, 2+i, -3+2i, 4]), "double"), -4 - 32i)
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1538 %!assert (prod (single ([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i]), "double"),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1539 %! [-1+i, -8+8i, -27+27i])
18725
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1540
22737
7abc25e6206a maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22708
diff changeset
1541 ## Test "native" type argument
18725
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1542 %!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
1543 %!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
1544 %!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
1545 %!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
1546 %!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
1547 %!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
1548
22737
7abc25e6206a maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22708
diff changeset
1549 ## Test input validation
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1550 %!error prod ()
18725
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1551 %!error prod (1,2,3)
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1552 %!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
1553 */
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1554
10758
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1555 static bool
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1556 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
1557 {
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1558 int n_args = args.length ();
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1559 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
1560 if (args(i).numel () != 1)
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1561 return false;
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1562
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1563 return true;
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1564 }
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1565
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
1566 template <typename TYPE, typename T>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
1567 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
1568 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
1569 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
1570 int dim)
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10498
diff changeset
1571 {
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10498
diff changeset
1572 int n_args = args.length ();
10758
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1573 if (! (equal_types<T, char>::value
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1574 || equal_types<T, octave_value>::value)
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1575 && 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
1576 {
10758
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1577 // Optimize all scalars case.
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1578 dim_vector dv (1, 1);
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1579 if (dim == -1 || dim == -2)
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1580 dim = -dim - 1;
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1581 else if (dim >= 2)
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1582 dv.resize (dim+1, 1);
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1583 dv(dim) = n_args;
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1584
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1585 result.clear (dv);
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1586
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1587 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
1588 {
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1589 octave_quit ();
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 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
1592 }
10533
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10498
diff changeset
1593 }
10758
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1594 else
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_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
1597
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1598 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
1599 {
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1600 octave_quit ();
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1601
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1602 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
1603 }
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1604
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1605 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
1606 }
10533
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10498
diff changeset
1607 }
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10498
diff changeset
1608
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
1609 template <typename TYPE, typename T>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
1610 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
1611 single_type_concat (Sparse<T>& result,
10498
8615b55b5caf fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents: 10436
diff changeset
1612 const octave_value_list& args,
8615b55b5caf fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents: 10436
diff changeset
1613 int dim)
8615b55b5caf fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents: 10436
diff changeset
1614 {
10533
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10498
diff changeset
1615 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
1616 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
1617
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1618 for (int j = 0; j < n_args; j++)
10498
8615b55b5caf fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents: 10436
diff changeset
1619 {
8615b55b5caf fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents: 10436
diff changeset
1620 octave_quit ();
8615b55b5caf fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents: 10436
diff changeset
1621
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1622 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
1623 }
10533
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10498
diff changeset
1624
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1625 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
1626 }
8615b55b5caf fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents: 10436
diff changeset
1627
10533
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10498
diff changeset
1628 // Dispatcher.
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
1629 template <typename TYPE>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
1630 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
1631 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
1632 {
10533
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10498
diff changeset
1633 TYPE result;
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10498
diff changeset
1634
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10498
diff changeset
1635 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
1636
8615b55b5caf fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents: 10436
diff changeset
1637 return result;
8615b55b5caf fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents: 10436
diff changeset
1638 }
8615b55b5caf fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents: 10436
diff changeset
1639
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
1640 template <typename MAP>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
1641 static void
10758
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1642 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
1643 const octave_value_list& args,
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1644 int dim)
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1645 {
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1646 int n_args = args.length ();
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1647 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
1648
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1649 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
1650 {
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1651 octave_quit ();
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1652
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1653 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
1654 }
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1655
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1656 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
1657 }
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1658
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1659 static octave_map
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1660 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
1661 int dim)
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1662 {
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1663 octave_map result;
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1664 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
1665 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
1666 else
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1667 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
1668
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1669 return result;
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1670 }
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1671
4824
4829055e154f [project @ 2004-03-08 18:16:04 by jwe]
jwe
parents: 4806
diff changeset
1672 static octave_value
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1673 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
1674 {
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1675 octave_value retval;
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1676
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1677 // 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
1678 // 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
1679 // type.
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 std::string cname = ov.class_name ();
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1682
31105
670a0d878af1 eliminate WHO arguments from interpreter-private functions
John W. Eaton <jwe@octave.org>
parents: 30934
diff changeset
1683 symbol_table& symtab = __get_symbol_table__ ();
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23592
diff changeset
1684
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23592
diff changeset
1685 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
1686
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1687 if (fcn.is_defined ())
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1688 {
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20726
diff changeset
1689 octave_value_list result;
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20726
diff changeset
1690
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20726
diff changeset
1691 try
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20726
diff changeset
1692 {
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
1693 result = feval (fcn, ovl (ov), 1);
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20726
diff changeset
1694 }
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
1695 catch (execution_exception& ee)
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20726
diff changeset
1696 {
29163
8f67ad8b3103 maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents: 29117
diff changeset
1697 error (ee, "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
1698 cname.c_str ());
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20726
diff changeset
1699 }
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20726
diff changeset
1700
21885
0806871e3e1e maint: Prefer is_empty() rather than "length () == 0".
Rik <rik@octave.org>
parents: 21782
diff changeset
1701 if (result.empty ())
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1702 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
1703 cname.c_str ());
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1704
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1705 retval = result(0);
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1706 }
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1707 else
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1708 {
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1709 // 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
1710 // dispatch type.
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1711
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23592
diff changeset
1712 fcn = symtab.find_method (dtype, dtype);
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1713
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
1714 if (! fcn.is_defined ())
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
1715 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
1716
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
1717 octave_value_list result;
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
1718
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
1719 try
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1720 {
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
1721 result = feval (fcn, ovl (ov), 1);
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
1722 }
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
1723 catch (execution_exception& ee)
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
1724 {
29163
8f67ad8b3103 maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents: 29117
diff changeset
1725 error (ee, "%s constructor failed for %s argument", dtype.c_str (),
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
1726 cname.c_str ());
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1727 }
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
1728
21885
0806871e3e1e maint: Prefer is_empty() rather than "length () == 0".
Rik <rik@octave.org>
parents: 21782
diff changeset
1729 if (result.empty ())
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
1730 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
1731 cname.c_str ());
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1732
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1733 retval = result(0);
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1734 }
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1735
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1736 return retval;
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 octave_value
29959
9e35973fb6c0 * data.h, data.cc (do_class_concat): Pass string argument by const reference.
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
1740 do_class_concat (const octave_value_list& ovl,
9e35973fb6c0 * data.h, data.cc (do_class_concat): Pass string argument by const reference.
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
1741 const std::string& cattype, int dim)
4806
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1742 {
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1743 octave_value retval;
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1744
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1745 // Get dominant type for list
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1746
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
1747 std::string dtype = get_dispatch_type (ovl);
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
1748
31105
670a0d878af1 eliminate WHO arguments from interpreter-private functions
John W. Eaton <jwe@octave.org>
parents: 30934
diff changeset
1749 symbol_table& symtab = __get_symbol_table__ ();
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23592
diff changeset
1750
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23592
diff changeset
1751 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
1752
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1753 if (fcn.is_defined ())
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1754 {
20726
25d676f9619c Preface error() messages with name of function when possible.
Rik <rik@octave.org>
parents: 20720
diff changeset
1755 // 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
1756
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20726
diff changeset
1757 octave_value_list tmp2;
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20726
diff changeset
1758
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20726
diff changeset
1759 try
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1760 {
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
1761 tmp2 = feval (fcn, ovl, 1);
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20726
diff changeset
1762 }
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
1763 catch (execution_exception& ee)
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20726
diff changeset
1764 {
29163
8f67ad8b3103 maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents: 29117
diff changeset
1765 error (ee, "%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
1766 }
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1767
21885
0806871e3e1e maint: Prefer is_empty() rather than "length () == 0".
Rik <rik@octave.org>
parents: 21782
diff changeset
1768 if (tmp2.empty ())
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20726
diff changeset
1769 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
1770 cattype.c_str ());
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1771
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1772 retval = tmp2(0);
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1773 }
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1774 else
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1775 {
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1776 // 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
1777 // 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
1778 // default operation for octave_class values.
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1779
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1780 octave_idx_type j = 0;
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1781 octave_idx_type len = ovl.length ();
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1782 octave_value_list tmp (len, octave_value ());
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1783 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
1784 {
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1785 octave_value elt = ovl(k);
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 std::string t1_type = elt.class_name ();
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1788
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1789 if (t1_type == dtype)
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1790 tmp(j++) = elt;
23587
0c468af9dc00 maint: Deprecate is_object and replace with isobject.
Rik <rik@octave.org>
parents: 23586
diff changeset
1791 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
1792 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
1793 }
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1794
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1795 tmp.resize (j);
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1796
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1797 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
1798
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1799 std::string cname = tmp(0).class_name ();
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1800 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
1801
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1802 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
1803 }
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1804
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1805 return retval;
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1806 }
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1807
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1808 static octave_value
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1809 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
1810 {
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1811 octave_value retval;
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1812
20811
5979314bb15a Fix BIST tests for rows.
Rik <rik@octave.org>
parents: 20810
diff changeset
1813 // 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
1814 // 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
1815 // counts.
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1816 octave_value_list args = xargs;
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1817
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
1818 int n_args = args.length ();
4806
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1819
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1820 if (n_args == 0)
5714
24f6a13878c2 [project @ 2006-03-23 21:46:09 by jwe]
jwe
parents: 5677
diff changeset
1821 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
1822 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
1823 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
1824 else if (n_args > 1)
4824
4829055e154f [project @ 2004-03-08 18:16:04 by jwe]
jwe
parents: 4806
diff changeset
1825 {
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1826 std::string result_type;
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1827
19399
2304ddfd736f Restore warning Octave:num-to-str missing since 3.2.4 (bug #43814).
Rik <rik@octave.org>
parents: 18869
diff changeset
1828 bool all_strings_p = true;
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1829 bool all_sq_strings_p = true;
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1830 bool all_dq_strings_p = true;
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1831 bool all_real_p = true;
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1832 bool all_cmplx_p = true;
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1833 bool any_sparse_p = false;
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1834 bool any_cell_p = false;
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1835 bool any_class_p = false;
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1836
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1837 bool first_elem_is_struct = false;
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1838
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1839 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
1840 {
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1841 if (i == 0)
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1842 {
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1843 result_type = args(i).class_name ();
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1844
23584
7ed6b258db91 maint: Deprecate is_map and replace with isstruct.
Rik <rik@octave.org>
parents: 23583
diff changeset
1845 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
1846 }
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1847 else
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
1848 result_type = 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
1849
19399
2304ddfd736f Restore warning Octave:num-to-str missing since 3.2.4 (bug #43814).
Rik <rik@octave.org>
parents: 18869
diff changeset
1850 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
1851 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
1852 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
1853 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
1854 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
1855 all_dq_strings_p = false;
23582
0cc2011d800e maint: Deprecate is_real_type and replace with isreal.
Rik <rik@octave.org>
parents: 23581
diff changeset
1856 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
1857 all_real_p = false;
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
1858 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
1859 || args(i).isreal ()))
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1860 all_cmplx_p = false;
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
1861 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
1862 any_sparse_p = true;
23576
00e518162fda maint: Deprecate is_cell and replace with iscell.
Rik <rik@octave.org>
parents: 23575
diff changeset
1863 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
1864 any_cell_p = true;
23587
0c468af9dc00 maint: Deprecate is_object and replace with isobject.
Rik <rik@octave.org>
parents: 23586
diff changeset
1865 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
1866 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
1867 }
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1868
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1869 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
1870 {
22895
0ab9eecbb165 Concatenate empty matrices/cells in cat() the same as the parser (bug #49759).
Rik <rik@octave.org>
parents: 22853
diff changeset
1871 int j = 0;
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1872 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
1873 {
23576
00e518162fda maint: Deprecate is_cell and replace with iscell.
Rik <rik@octave.org>
parents: 23575
diff changeset
1874 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
1875 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
1876 else
0ab9eecbb165 Concatenate empty matrices/cells in cat() the same as the parser (bug #49759).
Rik <rik@octave.org>
parents: 22853
diff changeset
1877 {
23577
80c42f4cca13 maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents: 23576
diff changeset
1878 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
1879 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
1880 else
0ab9eecbb165 Concatenate empty matrices/cells in cat() the same as the parser (bug #49759).
Rik <rik@octave.org>
parents: 22853
diff changeset
1881 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
1882 }
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1883 }
22895
0ab9eecbb165 Concatenate empty matrices/cells in cat() the same as the parser (bug #49759).
Rik <rik@octave.org>
parents: 22853
diff changeset
1884 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
1885 args.resize (n_args);
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1886 }
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1887
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1888 if (any_class_p)
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1889 {
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
1890 retval = do_class_concat (args, fname, dim);
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1891 }
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1892 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
1893 {
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1894 if (any_sparse_p)
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
1895 {
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1896 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
1897 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
1898 else
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1899 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
1900 }
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
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1902 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1903 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
1904 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
1905 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
1906 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
1907 }
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 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
1910 {
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1911 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
1912 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
1913 else
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1914 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
1915 }
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1916 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
1917 {
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23449
diff changeset
1918 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
1919
19399
2304ddfd736f Restore warning Octave:num-to-str missing since 3.2.4 (bug #43814).
Rik <rik@octave.org>
parents: 18869
diff changeset
1920 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
1921 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
1922 "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
1923 else
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
1924 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
1925
2304ddfd736f Restore warning Octave:num-to-str missing since 3.2.4 (bug #43814).
Rik <rik@octave.org>
parents: 18869
diff changeset
1926 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
1927
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1928 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
1929 }
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1930 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
1931 {
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1932 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
1933 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
1934 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
1935 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
1936 }
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1937 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
1938 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
1939 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
1940 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
1941 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
1942 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
1943 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
1944 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
1945 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
1946 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
1947 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
1948 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
1949 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
1950 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
1951 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
1952 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
1953 else if (result_type == "cell")
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1954 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
1955 else if (result_type == "struct")
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1956 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
1957 else
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1958 {
20218
b2100e1659ac maint: Use cuddled parentheses when indexing dimension_vectors.
Rik <rik@octave.org>
parents: 20183
diff changeset
1959 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
1960
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1961 // Default concatenation.
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1962 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
1963 = &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
1964
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1965 if (dim == -1 || dim == -2)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1966 {
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1967 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
1968 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
1969 }
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1970
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1971 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
1972 {
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1973 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
1974 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
1975 }
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1976
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1977 // 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
1978 // 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
1979 // 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
1980 // 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
1981 // 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
1982 // 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
1983 // 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
1984 //
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1985 // 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
1986 //
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
1987 // tmp = type_info::lookup_type (args(1).type_name());
24540
46440078d73b don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents: 24536
diff changeset
1988 //
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21730
diff changeset
1989 // 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
1990 // 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
1991
18112
b560bac0fca2 maint: Don't use space between 'args' and '(' when doing indexing.
Rik <rik@octave.org>
parents: 18100
diff changeset
1992 octave_value tmp = args(0);
30390
a61e1a0f6024 maint: style check C++ files in libinterp/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 30377
diff changeset
1993 tmp = tmp.resize (dim_vector (0, 0)).resize (dv);
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1994
21660
53728df3e4c9 maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents: 21602
diff changeset
1995 int dv_len = dv.ndims ();
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1996 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
1997
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1998 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
1999 {
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
2000 // 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
2001 // 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
2002 // the right type.
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
2003 tmp = cat_op (tmp, args(j), ra_idx);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
2004
18112
b560bac0fca2 maint: Don't use space between 'args' and '(' when doing indexing.
Rik <rik@octave.org>
parents: 18100
diff changeset
2005 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
2006
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
2007 if (dim >= dv_len)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
2008 {
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
2009 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
2010 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
2011
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
2012 break;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
2013 }
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
2014 else
21660
53728df3e4c9 maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents: 21602
diff changeset
2015 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
2016 }
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
2017 retval = tmp;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
2018 }
4806
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
2019 }
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
2020 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
2021 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
2022
4806
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
2023 return retval;
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
2024 }
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
2025
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
2026 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
2027 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2028 @deftypefn {} {@var{A} =} horzcat (@var{array1}, @var{array2}, @dots{}, @var{arrayN})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2029 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
2030 @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
2031
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2032 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
2033 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
2034
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2035 @example
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2036 @var{A} = [ @var{array1}, @var{array2}, @dots{} ]
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2037 @end example
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2038
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2039 This syntax is slightly more efficient because the Octave parser can
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2040 concatenate the arrays without the overhead of a function call.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2041 @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
2042 @end deftypefn */)
4806
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
2043 {
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
2044 return do_cat (args, -2, "horzcat");
4806
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
2045 }
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
2046
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
2047 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2048 ## 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
2049 %!test
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2050 %! warning ("off", "Octave:num-to-str", "local");
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
2051 %! assert (horzcat ("", 65* ones (1,10)), "AAAAAAAAAA");
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
2052 %! 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
2053
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2054 %!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
2055 %!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
2056 %!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
2057 %!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
2058 %!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
2059 %!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
2060 %!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
2061 %!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
2062 %!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
2063 %!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
2064 %!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
2065 %!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
2066 %!test
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2067 %! 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
2068 %! 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
2069
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2070 %!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
2071 %!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
2072 %!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
2073 %!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
2074 %!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
2075 %!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
2076 %!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
2077 %!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
2078 %!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
2079 %!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
2080 %!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
2081 %!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
2082 %!test
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2083 %! 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
2084 %! 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
2085
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2086 %!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
2087 %!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
2088 %!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
2089 %!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
2090 %!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
2091 %!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
2092 %!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
2093 %!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
2094 %!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
2095 %!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
2096 %!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
2097 %!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
2098 %!test
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2099 %! 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
2100 %! 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
2101
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2102 %!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
2103 %!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
2104 %!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
2105 %!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
2106 %!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
2107 %!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
2108 %!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
2109 %!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
2110 %!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
2111 %!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
2112 %!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
2113 %!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
2114 %!test
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2115 %! 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
2116 %! 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
2117
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2118 %!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
2119 %!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
2120 %!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
2121 %!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
2122 %!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
2123 %!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
2124 %!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
2125 %!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
2126 %!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
2127 %!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
2128 %!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
2129 %!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
2130 %!test
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2131 %! 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
2132 %! 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
2133
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2134 %!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
2135 %!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
2136 %!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
2137 %!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
2138 %!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
2139 %!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
2140 %!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
2141 %!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
2142 %!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
2143 %!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
2144 %!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
2145 %!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
2146 %!test
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2147 %! 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
2148 %! 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
2149
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2150 %!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
2151 %!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
2152 %!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
2153 %!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
2154 %!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
2155 %!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
2156 %!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
2157 %!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
2158 %!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
2159 %!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
2160 %!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
2161 %!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
2162 %!test
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2163 %! 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
2164 %! 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
2165
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2166 %!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
2167 %!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
2168 %!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
2169 %!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
2170 %!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
2171 %!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
2172 %!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
2173 %!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
2174 %!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
2175 %!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
2176 %!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
2177 %!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
2178 %!test
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2179 %! 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
2180 %! 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
2181
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2182 %!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
2183 %!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
2184 %!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
2185 %!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
2186 %!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
2187 %!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
2188 %!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
2189 %!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
2190 %!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
2191 %!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
2192 %!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
2193 %!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
2194 %!test
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2195 %! 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
2196 %! 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
2197
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2198 %!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
2199 %!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
2200 %!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
2201 %!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
2202 %!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
2203 %!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
2204 %!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
2205 %!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
2206 %!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
2207 %!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
2208 %!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
2209 %!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
2210 %!test
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2211 %! 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
2212 %! 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
2213
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2214 %!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
2215 %!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
2216 %!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
2217 %!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
2218 %!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
2219 %!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
2220 %!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
2221 %!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
2222 %!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
2223 %!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
2224 %!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
2225 %!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
2226 %!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
2227
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2228 %!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
2229 %!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
2230 %!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
2231 %!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
2232 %!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
2233 %!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
2234 %!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
2235 %!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
2236 %!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
2237 %!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
2238 %!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
2239 %!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
2240 %!test
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2241 %! 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
2242 %! 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
2243
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2244 %!test
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2245 %! 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
2246 %! 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
2247 %! 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
2248 %! 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
2249 %! 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
2250 %! 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
2251 %! 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
2252 %! 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
2253 %! 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
2254 %! 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
2255 %! 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
2256 %! 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
2257 %! 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
2258 %! 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
2259
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2260 %!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
2261
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2262 %!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
2263
28915
c40a367a84c0 maint: Use Octave convention of space after function name in libinterp/.
Rik <rik@octave.org>
parents: 28888
diff changeset
2264 %!test <*39041> assert (class (horzcat (cell (0), struct ())), "cell")
c40a367a84c0 maint: Use Octave convention of space after function name in libinterp/.
Rik <rik@octave.org>
parents: 28888
diff changeset
2265 %!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
2266 */
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
2267
4806
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
2268 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
2269 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2270 @deftypefn {} {@var{A} =} vertcat (@var{array1}, @var{array2}, @dots{}, @var{arrayN})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2271 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
2272 @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
2273
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2274 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
2275 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
2276
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2277 @example
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2278 @var{A} = [ @var{array1}; @var{array2}; @dots{} ]
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2279 @end example
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2280
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2281 This syntax is slightly more efficient because the Octave parser can
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2282 concatenate the arrays without the overhead of a function call.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2283 @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
2284 @end deftypefn */)
4806
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
2285 {
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
2286 return do_cat (args, -1, "vertcat");
4806
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
2287 }
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
2288
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
2289 /*
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
2290 %!test
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2291 %! c = {"foo"; "bar"; "bazoloa"};
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
2292 %! assert (vertcat (c, "a", "bc", "def"),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
2293 %! {"foo"; "bar"; "bazoloa"; "a"; "bc"; "def"});
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
2294 */
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
2295
4758
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
2296 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
2297 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2298 @deftypefn {} {@var{A} =} cat (@var{dim}, @var{array1}, @var{array2}, @dots{}, @var{arrayN})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2299 Return the concatenation of N-D array objects, @var{array1}, @var{array2},
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2300 @dots{}, @var{arrayN} along dimension @var{dim}.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2301
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2302 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2303 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2304 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
2305 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
2306 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
2307 @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
2308 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
2309 @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
2310 @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
2311
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2312 Alternatively, we can concatenate @var{A} and @var{B} along the second
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2313 dimension in the following way:
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2314
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2315 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2316 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2317 [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
2318 @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
2319 @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
2320
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2321 @var{dim} can be larger than the dimensions of the N-D array objects and the
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2322 result will thus have @var{dim} dimensions as the following example shows:
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2323
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2324 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2325 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2326 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
2327 @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
2328
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2329 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
2330 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
2331
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2332 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
2333
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2334 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
2335 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
2336 @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
2337 @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
2338 @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
2339 @end deftypefn */)
4758
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
2340 {
20850
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
2341 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
2342 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
2343
20850
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
2344 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
2345
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
2346 if (dim < 0)
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
2347 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
2348
21127
df7891224709 maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents: 21121
diff changeset
2349 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
2350 }
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
2351
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
2352 /*
14085
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 14022
diff changeset
2353 %!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
2354 %! 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
2355 %!
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2356 %! 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
2357 %! 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
2358 %! assert (cat (1, cast ([1; 2], t1), cast (3, t2)), cast ([1; 2; 3], tr));
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
2359 %! assert (cat (1, cast ([1; 2], t1), cast ([3; 4], t2)),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
2360 %! cast ([1; 2; 3; 4], tr));
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2361 %! 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
2362 %! 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
2363 %! assert (cat (2, cast ([1, 2], t1), cast (3, t2)), cast ([1, 2, 3], tr));
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
2364 %! assert (cat (2, cast ([1, 2], t1), cast ([3, 4], t2)),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
2365 %! 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
2366 %!
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2367 %! 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
2368 %! 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
2369 %! 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
2370 %! 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
2371 %! 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
2372 %! 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
2373 %! 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
2374 %! 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
2375 %!
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2376 %! if (nargin == 3 || cmplx)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2377 %! 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
2378 %! 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
2379 %! assert (cat (1, cast ([1i; 2], t1), cast (3, t2)), cast ([1i; 2; 3], tr));
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
2380 %! assert (cat (1, cast ([1i; 2], t1), cast ([3; 4], t2)),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
2381 %! cast ([1i; 2; 3; 4], tr));
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2382 %! 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
2383 %! 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
2384 %! assert (cat (2, cast ([1i, 2], t1), cast (3, t2)), cast ([1i, 2, 3], tr));
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
2385 %! assert (cat (2, cast ([1i, 2], t1), cast ([3, 4], t2)),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
2386 %! cast ([1i, 2, 3, 4], tr));
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2387 %! 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
2388 %! 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
2389 %! 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
2390 %! 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
2391 %! 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
2392 %! 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
2393 %! 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
2394 %! 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
2395 %!
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2396 %! 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
2397 %! 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
2398 %! assert (cat (1, cast ([1; 2], t1), cast (3i, t2)), cast ([1; 2; 3i], tr));
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
2399 %! assert (cat (1, cast ([1; 2], t1), cast ([3i; 4], t2)),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
2400 %! cast ([1; 2; 3i; 4], tr));
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2401 %! 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
2402 %! 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
2403 %! assert (cat (2, cast ([1, 2], t1), cast (3i, t2)), cast ([1, 2, 3i], tr));
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
2404 %! assert (cat (2, cast ([1, 2], t1), cast ([3i, 4], t2)),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
2405 %! cast ([1, 2, 3i, 4], tr));
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2406 %! 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
2407 %! 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
2408 %! 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
2409 %! 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
2410 %! 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
2411 %! 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
2412 %! 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
2413 %! 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
2414 %!
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2415 %! assert (cat (1, cast (1i, t1), cast (2i, t2)), cast ([1i; 2i], tr));
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
2416 %! assert (cat (1, cast (1i, t1), cast ([2i; 3], t2)),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
2417 %! cast ([1i; 2i; 3], tr));
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
2418 %! assert (cat (1, cast ([1i; 2], t1), cast (3i, t2)),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
2419 %! cast ([1i; 2; 3i], tr));
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
2420 %! assert (cat (1, cast ([1i; 2], t1), cast ([3i; 4], t2)),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
2421 %! cast ([1i; 2; 3i; 4], tr));
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2422 %! assert (cat (2, cast (1i, t1), cast (2i, t2)), cast ([1i, 2i], tr));
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
2423 %! assert (cat (2, cast (1i, t1), cast ([2i, 3], t2)),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
2424 %! cast ([1i, 2i, 3], tr));
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
2425 %! assert (cat (2, cast ([1i, 2], t1), cast (3i, t2)),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
2426 %! cast ([1i, 2, 3i], tr));
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
2427 %! assert (cat (2, cast ([1i, 2], t1), cast ([3i, 4], t2)),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
2428 %! 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
2429 %!
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2430 %! 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
2431 %! 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
2432 %! assert ([cast([1i; 2], t1); cast(3i, t2)], cast ([1i; 2; 3i], tr));
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
2433 %! assert ([cast([1i; 2], t1); cast([3i; 4], t2)],
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
2434 %! cast ([1i; 2; 3i; 4], tr));
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2435 %! 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
2436 %! 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
2437 %! assert ([cast([1i, 2], t1), cast(3i, t2)], cast ([1i, 2, 3i], tr));
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
2438 %! assert ([cast([1i, 2], t1), cast([3i, 4], t2)],
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
2439 %! cast ([1i, 2, 3i, 4], tr));
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2440 %! endif
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2441 %! ret = true;
14085
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 14022
diff changeset
2442 %!endfunction
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 14022
diff changeset
2443
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2444 %!assert (__testcat ("double", "double", "double"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2445 %!assert (__testcat ("single", "double", "single"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2446 %!assert (__testcat ("double", "single", "single"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2447 %!assert (__testcat ("single", "single", "single"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2448
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2449 %!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
2450 %!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
2451 %!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
2452 %!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
2453 %!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
2454 %!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
2455 %!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
2456 %!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
2457 %!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
2458 %!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
2459 %!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
2460 %!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
2461 %!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
2462 %!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
2463 %!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
2464 %!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
2465 %!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
2466 %!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
2467 %!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
2468 %!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
2469
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2470 %!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
2471 %!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
2472 %!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
2473 %!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
2474 %!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
2475 %!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
2476 %!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
2477 %!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
2478 %!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
2479 %!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
2480 %!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
2481 %!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
2482 %!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
2483 %!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
2484 %!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
2485 %!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
2486 %!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
2487 %!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
2488 %!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
2489 %!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
2490
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 14022
diff changeset
2491 %!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
2492 %!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
2493 %!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
2494 %!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
2495
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 14022
diff changeset
2496 %!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
2497 %!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
2498 %!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
2499
18678
6113e0c6920b maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents: 18676
diff changeset
2500 %!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
2501 %!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
2502
23573
1b4f4ec53b4a use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents: 23572
diff changeset
2503 %!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
2504 %! A = [];
0ab9eecbb165 Concatenate empty matrices/cells in cat() the same as the parser (bug #49759).
Rik <rik@octave.org>
parents: 22853
diff changeset
2505 %! 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
2506 %! 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
2507 %! 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
2508
14085
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 14022
diff changeset
2509 %!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
2510 %!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
2511 */
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
2512
4593
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
2513 static octave_value
6959
47f4f4e88166 [project @ 2007-10-04 20:43:32 by jwe]
jwe
parents: 6953
diff changeset
2514 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
2515 {
20850
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
2516 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
2517 print_usage ();
4593
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
2518
20850
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
2519 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
2520
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
2521 // 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
2522 // and pass that to permute?
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
2523 int n = vec.numel ();
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
2524 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
2525 vec(i)--;
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
2526
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
2527 return octave_value (args(0).permute (vec, inv));
4593
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
2528 }
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
2529
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
2530 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
2531 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2532 @deftypefn {} {@var{B} =} permute (@var{A}, @var{perm})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2533 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
2534
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2535 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
2536 @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
2537 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
2538 @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
2539
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2540 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2541 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2542 @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
2543 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
2544 @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
2545
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2546 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
2547 @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
2548
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2549 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
2550 @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
2551
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2552 ## 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
2553 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
2554 @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
2555 @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
2556 @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
2557 @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
2558 @end deftypefn */)
4593
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
2559 {
6959
47f4f4e88166 [project @ 2007-10-04 20:43:32 by jwe]
jwe
parents: 6953
diff changeset
2560 return do_permute (args, false);
4593
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
2561 }
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
2562
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
2563 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
2564 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2565 @deftypefn {} {@var{A} =} ipermute (@var{B}, @var{iperm})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2566 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
2567
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2568 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
2569
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2570 @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 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
2572 @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
2573
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2574 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2575 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
2576 @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
2577 @end deftypefn */)
4593
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
2578 {
6959
47f4f4e88166 [project @ 2007-10-04 20:43:32 by jwe]
jwe
parents: 6953
diff changeset
2579 return do_permute (args, true);
4593
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
2580 }
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
2581
3195
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3186
diff changeset
2582 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
2583 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2584 @deftypefn {} {@var{n} =} length (@var{A})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2585 Return the length of the object @var{A}.
21966
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 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
2588 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
2589 of elements along the largest dimension
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2590 (equivalent to @w{@code{max (size (@var{A}))}}).
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2591 @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
2592 @end deftypefn */)
3195
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3186
diff changeset
2593 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2594 if (args.length () != 1)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
2595 print_usage ();
3195
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3186
diff changeset
2596
21127
df7891224709 maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents: 21121
diff changeset
2597 return ovl (args(0).length ());
3195
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3186
diff changeset
2598 }
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3186
diff changeset
2599
4554
78e34346f6fd [project @ 2003-10-27 22:01:49 by jwe]
jwe
parents: 4545
diff changeset
2600 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
2601 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2602 @deftypefn {} {@var{n} =} ndims (@var{A})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2603 Return the number of dimensions of @var{A}.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2604
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2605 For any array, the result will always be greater than or equal to 2.
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2606 Trailing singleton dimensions are not counted, i.e., trailing dimensions @var{d}
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2607 greater than 2 for which @code{size (@var{A}, @var{d}) = 1}.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2608
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2609 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2610 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2611 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
2612 @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
2613 @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
2614 @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
2615 @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
2616 @end deftypefn */)
4554
78e34346f6fd [project @ 2003-10-27 22:01:49 by jwe]
jwe
parents: 4545
diff changeset
2617 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2618 if (args.length () != 1)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
2619 print_usage ();
4554
78e34346f6fd [project @ 2003-10-27 22:01:49 by jwe]
jwe
parents: 4545
diff changeset
2620
25917
ba937c3dce82 Determine an object's shape by "size" (bug #51308, bug #44498, bug #43925).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25861
diff changeset
2621 // This function *must* use size() to determine the desired values to be
ba937c3dce82 Determine an object's shape by "size" (bug #51308, bug #44498, bug #43925).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25861
diff changeset
2622 // compatible with Matlab and to allow user-defined class overloading.
ba937c3dce82 Determine an object's shape by "size" (bug #51308, bug #44498, bug #43925).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25861
diff changeset
2623 Matrix sz = octave_value (args(0)).size ();
ba937c3dce82 Determine an object's shape by "size" (bug #51308, bug #44498, bug #43925).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25861
diff changeset
2624
ba937c3dce82 Determine an object's shape by "size" (bug #51308, bug #44498, bug #43925).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25861
diff changeset
2625 octave_idx_type ndims = sz.numel ();
ba937c3dce82 Determine an object's shape by "size" (bug #51308, bug #44498, bug #43925).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25861
diff changeset
2626
ba937c3dce82 Determine an object's shape by "size" (bug #51308, bug #44498, bug #43925).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25861
diff changeset
2627 // Don't count trailing ones. Trailing zeros are *not* singleton dimension.
ba937c3dce82 Determine an object's shape by "size" (bug #51308, bug #44498, bug #43925).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25861
diff changeset
2628 while ((ndims > 2) && (sz(ndims - 1) == 1))
ba937c3dce82 Determine an object's shape by "size" (bug #51308, bug #44498, bug #43925).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25861
diff changeset
2629 ndims--;
ba937c3dce82 Determine an object's shape by "size" (bug #51308, bug #44498, bug #43925).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25861
diff changeset
2630
ba937c3dce82 Determine an object's shape by "size" (bug #51308, bug #44498, bug #43925).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25861
diff changeset
2631 return ovl (ndims);
ba937c3dce82 Determine an object's shape by "size" (bug #51308, bug #44498, bug #43925).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25861
diff changeset
2632 }
ba937c3dce82 Determine an object's shape by "size" (bug #51308, bug #44498, bug #43925).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25861
diff changeset
2633
ba937c3dce82 Determine an object's shape by "size" (bug #51308, bug #44498, bug #43925).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25861
diff changeset
2634 /*
ba937c3dce82 Determine an object's shape by "size" (bug #51308, bug #44498, bug #43925).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25861
diff changeset
2635 %!assert (ndims (1:5), 2)
ba937c3dce82 Determine an object's shape by "size" (bug #51308, bug #44498, bug #43925).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25861
diff changeset
2636 %!assert (ndims (ones (4, 1, 2, 1)), 3)
ba937c3dce82 Determine an object's shape by "size" (bug #51308, bug #44498, bug #43925).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25861
diff changeset
2637 %!assert (ndims (ones (4, 1, 2, 0)), 4)
ba937c3dce82 Determine an object's shape by "size" (bug #51308, bug #44498, bug #43925).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25861
diff changeset
2638 */
4554
78e34346f6fd [project @ 2003-10-27 22:01:49 by jwe]
jwe
parents: 4545
diff changeset
2639
4559
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4556
diff changeset
2640 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
2641 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2642 @deftypefn {} {@var{n} =} numel (@var{A})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2643 @deftypefnx {} {@var{n} =} numel (@var{A}, @var{idx1}, @var{idx2}, @dots{})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2644 Return the number of elements in the object @var{A}.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2645
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2646 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
2647 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
2648
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2649 @example
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2650 @var{A}(@var{idx1}, @var{idx2}, @dots{})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2651 @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
2652
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2653 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
2654
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2655 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2656 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2657 @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
2658 @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
2659 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
2660 @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
2661 @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
2662
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2663 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2664 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
2665 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
2666 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
2667
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2668 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2669 @group
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2670 @var{A} = ones (5, 3);
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2671 numel (@var{A}, 2, ":")
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2672 @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
2673 @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
2674
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2675 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2676 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
2677
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2678 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
2679 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
2680 @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
2681 @end deftypefn */)
4559
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4556
diff changeset
2682 {
20850
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
2683 int nargin = args.length ();
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
2684
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
2685 if (nargin == 0)
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
2686 print_usage ();
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
2687
4559
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4556
diff changeset
2688 octave_value retval;
9329
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
2689
9705
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2690 if (nargin == 1)
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2691 retval = args(0).numel ();
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2692 else if (nargin > 1)
4559
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4556
diff changeset
2693 {
9705
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2694 // 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
2695 // an overloaded call, not to builtin!
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
2696 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
2697 }
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4556
diff changeset
2698
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4556
diff changeset
2699 return retval;
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4556
diff changeset
2700 }
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4556
diff changeset
2701
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1940
diff changeset
2702 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
2703 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2704 @deftypefn {} {@var{sz} =} size (@var{A})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2705 @deftypefnx {} {@var{dim_sz} =} size (@var{A}, @var{dim})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2706 @deftypefnx {} {@var{dim_sz} =} size (@var{A}, @var{d1}, @var{d2}, @dots{})
22699
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2707 @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
2708 Return a row vector with the size (number of elements) of each dimension for
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2709 the object @var{A}.
22699
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2710
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2711 When given a second argument, @var{dim}, return the size of the corresponding
30230
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2712 dimension. If @var{dim} is a vector, return each of the corresponding
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2713 dimensions. Multiple dimensions may also be specified as separate arguments.
22699
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2714
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2715 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
2716 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
2717 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
2718 first argument, the number of columns, dimension 2, is returned in the
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2719 second argument, etc. If there are more dimensions in @var{A} than there are
22699
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2720 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
2721 remaining dimensions in the final output argument.
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2722
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2723 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
2724
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2725 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2726 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2727 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
2728 @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
2729 @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
2730 @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
2731
22699
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2732 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
2733
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2734 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2735 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2736 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
2737 @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
2738 @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
2739 @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
2740
22699
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2741 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
2742
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2743 @example
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2744 @group
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2745 [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
2746 @result{} nr = 3
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2747 @result{} nc = 2
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2748 @end group
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2749 @end example
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2750
25574
0e09d5fd7dab doc: Clarify description of Example 4 for size() (bug #54283).
Rik <rik@octave.org>
parents: 25471
diff changeset
2751 Example 4: number of output arguments < number of dimensions
22699
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2752
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2753 @example
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2754 @group
22845
e23f7f47d8a3 doc: Small fixes to docstrings (bug #49733).
Rik <rik@octave.org>
parents: 22827
diff changeset
2755 [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
2756 @result{} nr = 2
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2757 @result{} remainder = 60
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2758 @end group
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2759 @end example
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2760
22429
00986ee43956 doc: Add more @seealso links to numel, size, size_equal.
Rik <rik@octave.org>
parents: 22407
diff changeset
2761 @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
2762 @end deftypefn */)
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
2763 {
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
2764 int nargin = args.length ();
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
2765
30230
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2766 if (nargin == 0)
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2767 print_usage ();
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2768
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2769 // For compatibility with Matlab, size returns dimensions as doubles.
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2770
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2771 Matrix m;
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2772
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2773 dim_vector dimensions = args(0).dims ();
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2774 int ndims = dimensions.ndims ();
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2775
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4512
diff changeset
2776 if (nargin == 1)
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
2777 {
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4512
diff changeset
2778 if (nargout > 1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
2779 {
30230
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2780 dimensions = dimensions.redim (nargout);
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2781 ndims = dimensions.ndims ();
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2782 }
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2783
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2784 m.resize (1, ndims);
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2785
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2786 for (octave_idx_type i = 0; i < ndims; i++)
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2787 m(i) = dimensions(i);
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2788 }
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2789 else
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2790 {
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2791 Array<octave_idx_type> query_dims;
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2792
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2793 if (nargin > 2)
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2794 {
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2795 query_dims.resize (dim_vector (1, nargin-1));
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2796
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2797 for (octave_idx_type i = 0; i < nargin-1; i++)
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2798 query_dims(i) = args(i+1).idx_type_value (true);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
2799 }
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4512
diff changeset
2800 else
30230
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2801 query_dims = args(1).octave_idx_type_vector_value (true);
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2802
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2803 if (nargout > 1 && nargout != query_dims.numel ())
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2804 error ("size: nargout > 1 but does not match number of requested dimensions");
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2805
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2806 octave_idx_type nidx = query_dims.numel ();
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2807
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2808 m.resize (1, nidx);
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2809
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2810 for (octave_idx_type i = 0; i < nidx; i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
2811 {
30230
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2812 octave_idx_type nd = query_dims.xelem (i);
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2813
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2814 if (nd < 1)
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2815 error ("size: requested dimension DIM (= %"
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2816 OCTAVE_IDX_TYPE_FORMAT ") out of range", nd);
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2817
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2818 m(i) = nd <= ndims ? dimensions (nd-1) : 1;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
2819 }
1031
59f5eb2d5eb3 [project @ 1995-01-15 21:11:11 by jwe]
jwe
parents: 1009
diff changeset
2820 }
30230
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2821
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2822 if (nargout > 1)
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2823 {
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2824 octave_value_list retval (nargout);
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2825
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2826 for (octave_idx_type i = 0; i < nargout; i++)
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2827 retval(i) = m(i);
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2828
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2829 return retval;
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2830 }
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2831
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2832 return ovl (m);
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2833 }
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2834
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2835 /*
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2836 ## Plain call
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2837
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2838 %!assert (size ([1, 2; 3, 4; 5, 6]), [3, 2])
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2839
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2840 %!test
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2841 %! [nr, nc] = size ([1, 2; 3, 4; 5, 6]);
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2842 %! assert (nr, 3)
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2843 %! assert (nc, 2)
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2844
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2845 %!test
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2846 %! [nr, remainder] = size (ones (2, 3, 4, 5));
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2847 %! assert (nr, 2)
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2848 %! assert (remainder, 60)
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2849
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2850 ## Call for single existing dimension
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2851
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2852 %!assert (size ([1, 2; 3, 4; 5, 6], 1), 3)
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2853 %!assert (size ([1, 2; 3, 4; 5, 6], 2), 2)
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2854
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2855 ## Call for single non-existing dimension
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2856
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2857 %!assert (size ([1, 2; 3, 4; 5, 6], 3), 1)
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2858 %!assert (size ([1, 2; 3, 4; 5, 6], 4), 1)
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2859
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2860 ## Call for more than existing dimensions
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2861
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2862 %!test
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2863 %! [nr, nc, e1, e2] = size ([1, 2; 3, 4; 5, 6]);
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2864 %! assert (nr, 3)
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2865 %! assert (nc, 2)
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2866 %! assert (e1, 1)
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2867 %! assert (e2, 1)
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2868
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2869 ## Call for two arbitrary dimensions
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2870
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2871 %!test
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2872 %! dim = [3, 2, 1, 1, 1];
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2873 %! for i = 1:5
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2874 %! for j = 1:5
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2875 %! assert (size ([1, 2; 3, 4; 5, 6], i, j), [dim(i), dim(j)])
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2876 %! assert (size ([1, 2; 3, 4; 5, 6], [i, j]), [dim(i), dim(j)])
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2877 %! [a, b] = size ([1, 2; 3, 4; 5, 6], i, j);
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2878 %! assert (a, dim(i));
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2879 %! assert (b, dim(j));
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2880 %! [a, b] = size ([1, 2; 3, 4; 5, 6], [i, j]);
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2881 %! assert (a, dim(i));
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2882 %! assert (b, dim(j));
31564
332a6ccac881 maint: cleanup code in BIST tests to use Octave coding conventions.
Rik <rik@octave.org>
parents: 31375
diff changeset
2883 %! endfor
332a6ccac881 maint: cleanup code in BIST tests to use Octave coding conventions.
Rik <rik@octave.org>
parents: 31375
diff changeset
2884 %! endfor
30230
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2885
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2886 ## Call for three arbitrary dimensions
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2887
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2888 %!test
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2889 %! dim = [3, 2, 1, 1, 1];
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2890 %! for i = 1:5
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2891 %! for j = 1:5
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2892 %! for k = 1:5
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2893 %! assert (size ([1, 2; 3, 4; 5, 6], i, j, k), [dim(i), dim(j), dim(k)])
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2894 %! assert (size ([1, 2; 3, 4; 5, 6], [i, j, k]), [dim(i), dim(j), dim(k)])
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2895 %! [a, b, c] = size ([1, 2; 3, 4; 5, 6], i, j, k);
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2896 %! assert (a, dim(i));
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2897 %! assert (b, dim(j));
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2898 %! assert (c, dim(k));
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2899 %! [a, b, c] = size ([1, 2; 3, 4; 5, 6], [i, j, k]);
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2900 %! assert (a, dim(i));
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2901 %! assert (b, dim(j));
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2902 %! assert (c, dim(k));
31564
332a6ccac881 maint: cleanup code in BIST tests to use Octave coding conventions.
Rik <rik@octave.org>
parents: 31375
diff changeset
2903 %! endfor
332a6ccac881 maint: cleanup code in BIST tests to use Octave coding conventions.
Rik <rik@octave.org>
parents: 31375
diff changeset
2904 %! endfor
332a6ccac881 maint: cleanup code in BIST tests to use Octave coding conventions.
Rik <rik@octave.org>
parents: 31375
diff changeset
2905 %! endfor
30230
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2906
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2907 %!error <does not match number of requested dimensions>
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2908 %! [a, b, c] = size ([1, 2; 3, 4; 5, 6], 1:4)
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2909 */
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
2910
6156
a46f14cdbecd [project @ 2006-11-13 19:20:23 by jwe]
jwe
parents: 6133
diff changeset
2911 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
2912 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2913 @deftypefn {} {@var{TF} =} size_equal (@var{A}, @var{B})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2914 @deftypefnx {} {@var{TF} =} size_equal (@var{A}, @var{B}, @dots{})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2915 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
2916
22429
00986ee43956 doc: Add more @seealso links to numel, size, size_equal.
Rik <rik@octave.org>
parents: 22407
diff changeset
2917 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
2918 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
2919 @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
2920 @end deftypefn */)
6156
a46f14cdbecd [project @ 2006-11-13 19:20:23 by jwe]
jwe
parents: 6133
diff changeset
2921 {
6561
dc83c15d7149 [project @ 2007-04-23 16:58:17 by jwe]
jwe
parents: 6556
diff changeset
2922 int nargin = args.length ();
dc83c15d7149 [project @ 2007-04-23 16:58:17 by jwe]
jwe
parents: 6556
diff changeset
2923
8947
1e4b3149365a allow size_equal called with 1 arg
Jaroslav Hajek <highegg@gmail.com>
parents: 8934
diff changeset
2924 if (nargin >= 1)
6156
a46f14cdbecd [project @ 2006-11-13 19:20:23 by jwe]
jwe
parents: 6133
diff changeset
2925 {
a46f14cdbecd [project @ 2006-11-13 19:20:23 by jwe]
jwe
parents: 6133
diff changeset
2926 dim_vector a_dims = args(0).dims ();
6561
dc83c15d7149 [project @ 2007-04-23 16:58:17 by jwe]
jwe
parents: 6556
diff changeset
2927
dc83c15d7149 [project @ 2007-04-23 16:58:17 by jwe]
jwe
parents: 6556
diff changeset
2928 for (int i = 1; i < nargin; ++i)
dc83c15d7149 [project @ 2007-04-23 16:58:17 by jwe]
jwe
parents: 6556
diff changeset
2929 {
dc83c15d7149 [project @ 2007-04-23 16:58:17 by jwe]
jwe
parents: 6556
diff changeset
2930 dim_vector b_dims = args(i).dims ();
dc83c15d7149 [project @ 2007-04-23 16:58:17 by jwe]
jwe
parents: 6556
diff changeset
2931
dc83c15d7149 [project @ 2007-04-23 16:58:17 by jwe]
jwe
parents: 6556
diff changeset
2932 if (a_dims != b_dims)
21078
49852ff04747 maint: Remove unnecessary declarations of retval.
Rik <rik@octave.org>
parents: 21062
diff changeset
2933 return ovl (false);
6561
dc83c15d7149 [project @ 2007-04-23 16:58:17 by jwe]
jwe
parents: 6556
diff changeset
2934 }
6156
a46f14cdbecd [project @ 2006-11-13 19:20:23 by jwe]
jwe
parents: 6133
diff changeset
2935 }
a46f14cdbecd [project @ 2006-11-13 19:20:23 by jwe]
jwe
parents: 6133
diff changeset
2936
21078
49852ff04747 maint: Remove unnecessary declarations of retval.
Rik <rik@octave.org>
parents: 21062
diff changeset
2937 return ovl (true);
6156
a46f14cdbecd [project @ 2006-11-13 19:20:23 by jwe]
jwe
parents: 6133
diff changeset
2938 }
a46f14cdbecd [project @ 2006-11-13 19:20:23 by jwe]
jwe
parents: 6133
diff changeset
2939
5602
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5533
diff changeset
2940 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
2941 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2942 @deftypefn {} {@var{n} =} nnz (@var{A})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2943 Return the number of nonzero elements in @var{A}.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2944 @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
2945 @end deftypefn */)
5602
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5533
diff changeset
2946 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2947 if (args.length () != 1)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
2948 print_usage ();
5602
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5533
diff changeset
2949
21127
df7891224709 maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents: 21121
diff changeset
2950 return ovl (args(0).nnz ());
5602
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5533
diff changeset
2951 }
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5533
diff changeset
2952
24859
00ecff875f8a Add nnz implementation for Range type (bug #53185).
maorshutman <maorus12@gmail.com>
parents: 24634
diff changeset
2953 /*
00ecff875f8a Add nnz implementation for Range type (bug #53185).
maorshutman <maorus12@gmail.com>
parents: 24634
diff changeset
2954 %!assert (nnz (1:5), 5)
00ecff875f8a Add nnz implementation for Range type (bug #53185).
maorshutman <maorus12@gmail.com>
parents: 24634
diff changeset
2955 %!assert (nnz (-5:-1), 5)
00ecff875f8a Add nnz implementation for Range type (bug #53185).
maorshutman <maorus12@gmail.com>
parents: 24634
diff changeset
2956 %!assert (nnz (0:5), 5)
00ecff875f8a Add nnz implementation for Range type (bug #53185).
maorshutman <maorus12@gmail.com>
parents: 24634
diff changeset
2957 %!assert (nnz (-5:0), 5)
00ecff875f8a Add nnz implementation for Range type (bug #53185).
maorshutman <maorus12@gmail.com>
parents: 24634
diff changeset
2958 %!assert (nnz (-5:5), 10)
00ecff875f8a Add nnz implementation for Range type (bug #53185).
maorshutman <maorus12@gmail.com>
parents: 24634
diff changeset
2959 %!assert (nnz (-2:1:2), 4)
28915
c40a367a84c0 maint: Use Octave convention of space after function name in libinterp/.
Rik <rik@octave.org>
parents: 28888
diff changeset
2960 %!assert (nnz (-2+eps (2):1:2), 5)
c40a367a84c0 maint: Use Octave convention of space after function name in libinterp/.
Rik <rik@octave.org>
parents: 28888
diff changeset
2961 %!assert (nnz (-2-eps (2):1:2), 5)
c40a367a84c0 maint: Use Octave convention of space after function name in libinterp/.
Rik <rik@octave.org>
parents: 28888
diff changeset
2962 %!assert (nnz (-2:1+eps (1):2), 5)
c40a367a84c0 maint: Use Octave convention of space after function name in libinterp/.
Rik <rik@octave.org>
parents: 28888
diff changeset
2963 %!assert (nnz (-2:1-eps (1):2), 5)
24859
00ecff875f8a Add nnz implementation for Range type (bug #53185).
maorshutman <maorus12@gmail.com>
parents: 24634
diff changeset
2964 %!assert (nnz ([1:5] * 0), 0)
00ecff875f8a Add nnz implementation for Range type (bug #53185).
maorshutman <maorus12@gmail.com>
parents: 24634
diff changeset
2965 %!assert (nnz ([-5:-1] * 0), 0)
00ecff875f8a Add nnz implementation for Range type (bug #53185).
maorshutman <maorus12@gmail.com>
parents: 24634
diff changeset
2966 %!assert (nnz ([-1:1] * 0), 0)
00ecff875f8a Add nnz implementation for Range type (bug #53185).
maorshutman <maorus12@gmail.com>
parents: 24634
diff changeset
2967 */
00ecff875f8a Add nnz implementation for Range type (bug #53185).
maorshutman <maorus12@gmail.com>
parents: 24634
diff changeset
2968
5604
2857357f9d3c [project @ 2006-01-31 18:22:59 by jwe]
jwe
parents: 5602
diff changeset
2969 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
2970 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
2971 @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
2972 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
2973
27081
c0d8ce61c1c9 Always reserve at least 1 element of storage for sparse matrices (bug #56232).
Rik <rik@octave.org>
parents: 27034
diff changeset
2974 Programming Note: Octave tends to crop unused memory at the first opportunity
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2975 for sparse objects. Thus, in general the value of @code{nzmax} will be the
27081
c0d8ce61c1c9 Always reserve at least 1 element of storage for sparse matrices (bug #56232).
Rik <rik@octave.org>
parents: 27034
diff changeset
2976 same as @code{nnz}, except for some cases of user-created sparse objects.
c0d8ce61c1c9 Always reserve at least 1 element of storage for sparse matrices (bug #56232).
Rik <rik@octave.org>
parents: 27034
diff changeset
2977
c0d8ce61c1c9 Always reserve at least 1 element of storage for sparse matrices (bug #56232).
Rik <rik@octave.org>
parents: 27034
diff changeset
2978 Also, note that Octave always reserves storage for at least one value. Thus,
c0d8ce61c1c9 Always reserve at least 1 element of storage for sparse matrices (bug #56232).
Rik <rik@octave.org>
parents: 27034
diff changeset
2979 for empty matrices @code{nnz} will report 0, but @code{nzmax} will report 1.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2980 @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
2981 @end deftypefn */)
5604
2857357f9d3c [project @ 2006-01-31 18:22:59 by jwe]
jwe
parents: 5602
diff changeset
2982 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2983 if (args.length () != 1)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
2984 print_usage ();
5604
2857357f9d3c [project @ 2006-01-31 18:22:59 by jwe]
jwe
parents: 5602
diff changeset
2985
21127
df7891224709 maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents: 21121
diff changeset
2986 return ovl (args(0).nzmax ());
5604
2857357f9d3c [project @ 2006-01-31 18:22:59 by jwe]
jwe
parents: 5602
diff changeset
2987 }
2857357f9d3c [project @ 2006-01-31 18:22:59 by jwe]
jwe
parents: 5602
diff changeset
2988
5677
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
2989 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
2990 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2991 @deftypefn {} {@var{nr} =} rows (@var{A})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2992 Return the number of rows of @var{A}.
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2993
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2994 This is equivalent to @code{size (@var{A}, 1)}.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2995 @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
2996 @end deftypefn */)
5677
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
2997 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2998 if (args.length () != 1)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
2999 print_usage ();
5677
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
3000
25917
ba937c3dce82 Determine an object's shape by "size" (bug #51308, bug #44498, bug #43925).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25861
diff changeset
3001 // This function *must* use size() to determine the desired values to
ba937c3dce82 Determine an object's shape by "size" (bug #51308, bug #44498, bug #43925).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25861
diff changeset
3002 // allow user-defined class overloading.
ba937c3dce82 Determine an object's shape by "size" (bug #51308, bug #44498, bug #43925).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25861
diff changeset
3003
ba937c3dce82 Determine an object's shape by "size" (bug #51308, bug #44498, bug #43925).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25861
diff changeset
3004 return ovl ((octave_value (args(0)).size ())(0));
5677
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
3005 }
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
3006
20810
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
3007 /*
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
3008 %!assert (rows (ones (2,5)), 2)
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
3009 %!assert (rows (ones (5,2)), 5)
20811
5979314bb15a Fix BIST tests for rows.
Rik <rik@octave.org>
parents: 20810
diff changeset
3010 %!assert (rows (ones (5,4,3,2)), 5)
20810
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
3011 %!assert (rows (ones (3,4,5,2)), 3)
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
3012
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
3013 %!assert (rows (cell (2,5)), 2)
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
3014 %!assert (rows (cell (5,2)), 5)
20811
5979314bb15a Fix BIST tests for rows.
Rik <rik@octave.org>
parents: 20810
diff changeset
3015 %!assert (rows (cell (5,4,3,2)), 5)
20810
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
3016 %!assert (rows (cell (3,4,5,2)), 3)
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
3017
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
3018 %!test
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
3019 %! x(2,5,3).a = 1;
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
3020 %! assert (rows (x), 2);
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
3021 %! y(5,4,3).b = 2;
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
3022 %! assert (rows (y), 5);
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
3023
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
3024 %!assert (rows ("Hello World"), 1)
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
3025
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
3026 %!assert (rows ([]), 0)
20815
6935b8f038cc Fix BIST tests for rows()
Rik <rik@octave.org>
parents: 20811
diff changeset
3027 %!assert (rows (zeros (2,0)), 2)
20810
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
3028
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
3029 ## Test input validation
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
3030 %!error rows ()
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
3031 %!error rows (1,2)
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
3032 */
5677
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
3033
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
3034 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
3035 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
3036 @deftypefn {} {@var{nc} =} columns (@var{A})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
3037 Return the number of columns of @var{A}.
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
3038
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
3039 This is equivalent to @code{size (@var{A}, 2)}.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3040 @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
3041 @end deftypefn */)
5677
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
3042 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3043 if (args.length () != 1)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
3044 print_usage ();
5677
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
3045
25917
ba937c3dce82 Determine an object's shape by "size" (bug #51308, bug #44498, bug #43925).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25861
diff changeset
3046 // This function *must* use size() to determine the desired values to
ba937c3dce82 Determine an object's shape by "size" (bug #51308, bug #44498, bug #43925).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25861
diff changeset
3047 // allow user-defined class overloading.
ba937c3dce82 Determine an object's shape by "size" (bug #51308, bug #44498, bug #43925).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25861
diff changeset
3048
ba937c3dce82 Determine an object's shape by "size" (bug #51308, bug #44498, bug #43925).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25861
diff changeset
3049 return ovl ((octave_value (args(0)).size ())(1));
5677
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
3050 }
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
3051
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1940
diff changeset
3052 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
3053 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
3054 @deftypefn {} {@var{y} =} sum (@var{x})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
3055 @deftypefnx {} {@var{y} =} sum (@var{x}, @var{dim})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
3056 @deftypefnx {} {@var{y} =} sum (@dots{}, "native")
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
3057 @deftypefnx {} {@var{y} =} sum (@dots{}, "double")
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
3058 @deftypefnx {} {@var{y} =} sum (@dots{}, "extra")
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3059 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
3060
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3061 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
3062
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3063 The optional @qcode{"type"} input determines the class of the variable
25286
44c0aca121cc doc: Clarify docstring for sum (bug #53698).
Rik <rik@octave.org>
parents: 25103
diff changeset
3064 used for calculations. By default, operations on floating point inputs (double
44c0aca121cc doc: Clarify docstring for sum (bug #53698).
Rik <rik@octave.org>
parents: 25103
diff changeset
3065 or single) are performed in their native data type, while operations on
44c0aca121cc doc: Clarify docstring for sum (bug #53698).
Rik <rik@octave.org>
parents: 25103
diff changeset
3066 integer, logical, and character data types are performed using doubles. If the
44c0aca121cc doc: Clarify docstring for sum (bug #53698).
Rik <rik@octave.org>
parents: 25103
diff changeset
3067 argument @qcode{"native"} is given, then the operation is performed in the same
44c0aca121cc doc: Clarify docstring for sum (bug #53698).
Rik <rik@octave.org>
parents: 25103
diff changeset
3068 type as the original argument.
21966
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 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
3071
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3072 @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 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3074 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
3075 @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
3076 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
3077 @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
3078 @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
3079 @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
3080
25286
44c0aca121cc doc: Clarify docstring for sum (bug #53698).
Rik <rik@octave.org>
parents: 25103
diff changeset
3081 If @qcode{"double"} is given the sum is performed in double precision even for
44c0aca121cc doc: Clarify docstring for sum (bug #53698).
Rik <rik@octave.org>
parents: 25103
diff changeset
3082 single precision inputs.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3083
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3084 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
3085 accurate algorithm than straightforward summation. For single precision
25286
44c0aca121cc doc: Clarify docstring for sum (bug #53698).
Rik <rik@octave.org>
parents: 25103
diff changeset
3086 inputs, @qcode{"extra"} is the same as @qcode{"double"}. For all other data
44c0aca121cc doc: Clarify docstring for sum (bug #53698).
Rik <rik@octave.org>
parents: 25103
diff changeset
3087 type @qcode{"extra"} has no effect.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3088 @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
3089 @end deftypefn */)
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
3090 {
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
3091 int nargin = args.length ();
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
3092
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
3093 bool isnative = false;
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
3094 bool isdouble = false;
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
3095 bool isextra = false;
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
3096
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
3097 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
3098 {
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
3099 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
3100
19743
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
3101 if (str == "native")
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
3102 isnative = true;
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
3103 else if (str == "double")
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
3104 isdouble = true;
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
3105 else if (str == "extra")
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
3106 isextra = true;
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
3107 else
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
3108 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
3109
21062
d9c1884d1aaa maint: Eliminate space between variable and decrement '--' operator.
Rik <rik@octave.org>
parents: 21055
diff changeset
3110 nargin--;
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
3111 }
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
3112
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3113 if (nargin < 1 || nargin > 2)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3114 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3115
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3116 int dim = -1;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3117 if (nargin == 2)
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
3118 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3119 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
3120 if (dim < 0)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3121 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
3122 }
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3123
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3124 octave_value retval;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3125 octave_value arg = args(0);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3126
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3127 switch (arg.builtin_type ())
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3128 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3129 case btyp_double:
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
3130 if (arg.issparse ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3131 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3132 if (isextra)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3133 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
3134 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
3135 }
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3136 else if (isextra)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3137 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
3138 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3139 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
3140 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3141
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3142 case btyp_complex:
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
3143 if (arg.issparse ())
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3144 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3145 if (isextra)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3146 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
3147 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
3148 }
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3149 else if (isextra)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3150 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
3151 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3152 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
3153 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3154
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3155 case btyp_float:
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3156 if (isdouble || isextra)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3157 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
3158 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3159 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
3160 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3161
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3162 case btyp_float_complex:
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3163 if (isdouble || isextra)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3164 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
3165 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3166 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
3167 break;
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
3168
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
3169 #define MAKE_INT_BRANCH(X) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
3170 case btyp_ ## X: \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
3171 if (isnative) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
3172 retval = arg.X ## _array_value ().sum (dim); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
3173 else \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
3174 retval = arg.X ## _array_value ().dsum (dim); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
3175 break;
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3176
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3177 MAKE_INT_BRANCH (int8);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3178 MAKE_INT_BRANCH (int16);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3179 MAKE_INT_BRANCH (int32);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3180 MAKE_INT_BRANCH (int64);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3181 MAKE_INT_BRANCH (uint8);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3182 MAKE_INT_BRANCH (uint16);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3183 MAKE_INT_BRANCH (uint32);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3184 MAKE_INT_BRANCH (uint64);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3185
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
3186 #undef MAKE_INT_BRANCH
19597
db92e7e28e1f strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 19596
diff changeset
3187
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
3188 // GAGME: Accursed Matlab compatibility...
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3189 case btyp_char:
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3190 if (isextra)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3191 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
3192 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3193 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
3194 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3195
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3196 case btyp_bool:
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
3197 if (arg.issparse ())
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3198 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3199 if (isnative)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3200 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
3201 else
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3202 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
3203 }
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3204 else if (isnative)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3205 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
3206 else
22773
7f70e420e342 deprecate boolNDArray::sum and boolNDArray::cumsum
John W. Eaton <jwe@octave.org>
parents: 22763
diff changeset
3207 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
3208 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3209
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3210 default:
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21078
diff changeset
3211 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
3212 }
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
3213
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
3214 return retval;
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
3215 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
3216
7112
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
3217 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3218 %!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
3219 %!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
3220 %!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
3221 %!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
3222
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3223 %!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
3224 %!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
3225 %!assert (sum (single ([i, 2+i, -3+2i, 4])), single (3+4i))
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
3226 %!assert (sum (single ([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i])),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
3227 %! single ([2+2i, 4+4i, 6+6i]))
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3228
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3229 %!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
3230 %!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
3231 %!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
3232 %!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
3233 %!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
3234 %!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
3235 %!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
3236 %!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
3237 %!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
3238 %!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
3239 %!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
3240 %!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
3241 %!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
3242 %!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
3243 %!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
3244 %!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
3245 %!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
3246 %!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
3247 %!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
3248
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3249 %!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
3250 %!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
3251 %!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
3252 %!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
3253 %!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
3254 %!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
3255 %!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
3256 %!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
3257 %!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
3258 %!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
3259 %!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
3260 %!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
3261 %!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
3262 %!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
3263 %!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
3264 %!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
3265 %!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
3266 %!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
3267 %!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
3268
18726
5baada25d5a2 Rewrite docstring of sum() to match prod().
Rik <rik@octave.org>
parents: 18725
diff changeset
3269 ## Test "native"
5baada25d5a2 Rewrite docstring of sum() to match prod().
Rik <rik@octave.org>
parents: 18725
diff changeset
3270 %!assert (sum ([true,true]), 2)
5baada25d5a2 Rewrite docstring of sum() to match prod().
Rik <rik@octave.org>
parents: 18725
diff changeset
3271 %!assert (sum ([true,true], "native"), true)
5baada25d5a2 Rewrite docstring of sum() to match prod().
Rik <rik@octave.org>
parents: 18725
diff changeset
3272 %!assert (sum (int8 ([127,10,-20])), 117)
5baada25d5a2 Rewrite docstring of sum() to match prod().
Rik <rik@octave.org>
parents: 18725
diff changeset
3273 %!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
3274
15623
d928ad126b66 maint: add a new test for Fsum corresponding to cset e9d842dcfc91
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 15621
diff changeset
3275 ;-)
d928ad126b66 maint: add a new test for Fsum corresponding to cset e9d842dcfc91
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 15621
diff changeset
3276 %!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
3277
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3278 %!error sum ()
18726
5baada25d5a2 Rewrite docstring of sum() to match prod().
Rik <rik@octave.org>
parents: 18725
diff changeset
3279 %!error sum (1,2,3)
5baada25d5a2 Rewrite docstring of sum() to match prod().
Rik <rik@octave.org>
parents: 18725
diff changeset
3280 %!error <unrecognized type argument 'foobar'> sum (1, "foobar")
7112
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
3281 */
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
3282
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1940
diff changeset
3283 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
3284 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
3285 @deftypefn {} {@var{y} =} sumsq (@var{x})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
3286 @deftypefnx {} {@var{y} =} sumsq (@var{x}, @var{dim})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3287 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
3288
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3289 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
3290
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3291 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
3292
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3293 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3294 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
3295 @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
3296
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3297 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3298 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
3299 @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
3300 @end deftypefn */)
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
3301 {
3723
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
3302 DATA_REDUCTION (sumsq);
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
3303 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
3304
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
3305 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3306 %!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
3307 %!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
3308 %!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
3309
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3310 %!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
3311 %!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
3312 %!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
3313
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3314 %!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
3315 %!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
3316
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3317 %!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
3318 %!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
3319
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3320 %!error sumsq ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3321 */
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
3322
6688
b26a8e0e42cd [project @ 2007-06-04 06:25:21 by jwe]
jwe
parents: 6671
diff changeset
3323 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
3324 doc: /* -*- texinfo -*-
30559
841a10208c38 doc: Use TF for output variable in documentation for isXXX functions in libinterp/ directory.
Rik <rik@octave.org>
parents: 30402
diff changeset
3325 @deftypefn {} {@var{tf} =} islogical (@var{x})
841a10208c38 doc: Use TF for output variable in documentation for isXXX functions in libinterp/ directory.
Rik <rik@octave.org>
parents: 30402
diff changeset
3326 @deftypefnx {} {@var{tf} =} isbool (@var{x})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3327 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
3328 @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
3329 @end deftypefn */)
3209
fbb332b96e4f [project @ 1998-11-03 20:48:54 by jwe]
jwe
parents: 3206
diff changeset
3330 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3331 if (args.length () != 1)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
3332 print_usage ();
3209
fbb332b96e4f [project @ 1998-11-03 20:48:54 by jwe]
jwe
parents: 3206
diff changeset
3333
23579
c20a0fa91c0c maint: Deprecate is_bool_type and replace with islogical.
Rik <rik@octave.org>
parents: 23577
diff changeset
3334 return ovl (args(0).islogical ());
3209
fbb332b96e4f [project @ 1998-11-03 20:48:54 by jwe]
jwe
parents: 3206
diff changeset
3335 }
fbb332b96e4f [project @ 1998-11-03 20:48:54 by jwe]
jwe
parents: 3206
diff changeset
3336
6688
b26a8e0e42cd [project @ 2007-06-04 06:25:21 by jwe]
jwe
parents: 6671
diff changeset
3337 DEFALIAS (isbool, islogical);
3209
fbb332b96e4f [project @ 1998-11-03 20:48:54 by jwe]
jwe
parents: 3206
diff changeset
3338
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
3339 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3340 %!assert (islogical (true), true)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3341 %!assert (islogical (false), true)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3342 %!assert (islogical ([true, false]), true)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3343 %!assert (islogical (1), false)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3344 %!assert (islogical (1i), false)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3345 %!assert (islogical ([1,1]), false)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3346 %!assert (islogical (single (1)), false)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3347 %!assert (islogical (single (1i)), false)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3348 %!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
3349 %!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
3350 %!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
3351 */
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
3352
6223
a6cc01dd09f9 [project @ 2007-01-03 20:59:28 by jwe]
jwe
parents: 6197
diff changeset
3353 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
3354 doc: /* -*- texinfo -*-
30559
841a10208c38 doc: Use TF for output variable in documentation for isXXX functions in libinterp/ directory.
Rik <rik@octave.org>
parents: 30402
diff changeset
3355 @deftypefn {} {@var{tf} =} isinteger (@var{x})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3356 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
3357
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3358 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
3359 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
3360 @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
3361 @end deftypefn */)
6223
a6cc01dd09f9 [project @ 2007-01-03 20:59:28 by jwe]
jwe
parents: 6197
diff changeset
3362 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3363 if (args.length () != 1)
6223
a6cc01dd09f9 [project @ 2007-01-03 20:59:28 by jwe]
jwe
parents: 6197
diff changeset
3364 print_usage ();
a6cc01dd09f9 [project @ 2007-01-03 20:59:28 by jwe]
jwe
parents: 6197
diff changeset
3365
23580
2230f9e10fb3 maint: Deprecate is_integer_type and replace with isinteger.
Rik <rik@octave.org>
parents: 23579
diff changeset
3366 return ovl (args(0).isinteger ());
6223
a6cc01dd09f9 [project @ 2007-01-03 20:59:28 by jwe]
jwe
parents: 6197
diff changeset
3367 }
a6cc01dd09f9 [project @ 2007-01-03 20:59:28 by jwe]
jwe
parents: 6197
diff changeset
3368
22749
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3369 /*
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3370 %!assert (isinteger (int8 (16)))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3371 %!assert (isinteger (int16 (16)))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3372 %!assert (isinteger (int32 (16)))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3373 %!assert (isinteger (int64 (16)))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3374
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3375 %!assert (isinteger (uint8 (16)))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3376 %!assert (isinteger (uint16 (16)))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3377 %!assert (isinteger (uint32 (16)))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3378 %!assert (isinteger (uint64 (16)))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3379
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3380 %!assert (isinteger (intmax ("int8")))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3381 %!assert (isinteger (intmax ("int16")))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3382 %!assert (isinteger (intmax ("int32")))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3383 %!assert (isinteger (intmax ("int64")))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3384
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3385 %!assert (isinteger (intmax ("uint8")))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3386 %!assert (isinteger (intmax ("uint16")))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3387 %!assert (isinteger (intmax ("uint32")))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3388 %!assert (isinteger (intmax ("uint64")))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3389
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3390 %!assert (isinteger (intmin ("int8")))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3391 %!assert (isinteger (intmin ("int16")))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3392 %!assert (isinteger (intmin ("int32")))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3393 %!assert (isinteger (intmin ("int64")))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3394
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3395 %!assert (isinteger (intmin ("uint8")))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3396 %!assert (isinteger (intmin ("uint16")))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3397 %!assert (isinteger (intmin ("uint32")))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3398 %!assert (isinteger (intmin ("uint64")))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3399
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3400 %!assert (isinteger (uint8 ([1:10])))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3401 %!assert (isinteger (uint8 ([1:10; 1:10])))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3402
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3403 %!assert (! isinteger (16))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3404 %!assert (! isinteger ("parrot"))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3405 %!assert (! isinteger ([1, 2, 3]))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3406
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3407 %!error isinteger ()
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3408 %!error isinteger ("multiple", "parameters")
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3409 */
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3410
4028
ef75c970c8f5 [project @ 2002-08-09 07:19:02 by jwe]
jwe
parents: 4025
diff changeset
3411 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
3412 doc: /* -*- texinfo -*-
30559
841a10208c38 doc: Use TF for output variable in documentation for isXXX functions in libinterp/ directory.
Rik <rik@octave.org>
parents: 30402
diff changeset
3413 @deftypefn {} {@var{tf} =} iscomplex (@var{x})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3414 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
3415 @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
3416 @end deftypefn */)
3186
edaa9a2d3d9c [project @ 1998-10-02 19:12:19 by jwe]
jwe
parents: 3174
diff changeset
3417 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3418 if (args.length () != 1)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
3419 print_usage ();
3186
edaa9a2d3d9c [project @ 1998-10-02 19:12:19 by jwe]
jwe
parents: 3174
diff changeset
3420
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
3421 return ovl (args(0).iscomplex ());
3186
edaa9a2d3d9c [project @ 1998-10-02 19:12:19 by jwe]
jwe
parents: 3174
diff changeset
3422 }
edaa9a2d3d9c [project @ 1998-10-02 19:12:19 by jwe]
jwe
parents: 3174
diff changeset
3423
26198
d57d30caffd6 Add BISTS tests for iscomplex().
Rik <rik@octave.org>
parents: 26164
diff changeset
3424 /*
d57d30caffd6 Add BISTS tests for iscomplex().
Rik <rik@octave.org>
parents: 26164
diff changeset
3425 %!assert (iscomplex (4), false)
d57d30caffd6 Add BISTS tests for iscomplex().
Rik <rik@octave.org>
parents: 26164
diff changeset
3426 %!assert (iscomplex (i), true)
d57d30caffd6 Add BISTS tests for iscomplex().
Rik <rik@octave.org>
parents: 26164
diff changeset
3427 %!assert (iscomplex (4+3i), true)
d57d30caffd6 Add BISTS tests for iscomplex().
Rik <rik@octave.org>
parents: 26164
diff changeset
3428 %!assert (iscomplex ([1, 2, 3]), false)
d57d30caffd6 Add BISTS tests for iscomplex().
Rik <rik@octave.org>
parents: 26164
diff changeset
3429 %!assert (iscomplex ([1, 2i, 3]), true)
d57d30caffd6 Add BISTS tests for iscomplex().
Rik <rik@octave.org>
parents: 26164
diff changeset
3430
d57d30caffd6 Add BISTS tests for iscomplex().
Rik <rik@octave.org>
parents: 26164
diff changeset
3431 %!assert (iscomplex (0j), false)
d57d30caffd6 Add BISTS tests for iscomplex().
Rik <rik@octave.org>
parents: 26164
diff changeset
3432 %!assert (iscomplex (complex (0,0)), true)
d57d30caffd6 Add BISTS tests for iscomplex().
Rik <rik@octave.org>
parents: 26164
diff changeset
3433 %!assert (iscomplex ("4"), false)
d57d30caffd6 Add BISTS tests for iscomplex().
Rik <rik@octave.org>
parents: 26164
diff changeset
3434 %!assert (iscomplex ({i}), false)
d57d30caffd6 Add BISTS tests for iscomplex().
Rik <rik@octave.org>
parents: 26164
diff changeset
3435
d57d30caffd6 Add BISTS tests for iscomplex().
Rik <rik@octave.org>
parents: 26164
diff changeset
3436 ## Test input validation
d57d30caffd6 Add BISTS tests for iscomplex().
Rik <rik@octave.org>
parents: 26164
diff changeset
3437 %!error iscomplex ()
d57d30caffd6 Add BISTS tests for iscomplex().
Rik <rik@octave.org>
parents: 26164
diff changeset
3438 %!error iscomplex (1, 2)
d57d30caffd6 Add BISTS tests for iscomplex().
Rik <rik@octave.org>
parents: 26164
diff changeset
3439 */
d57d30caffd6 Add BISTS tests for iscomplex().
Rik <rik@octave.org>
parents: 26164
diff changeset
3440
7576
7ebdc99a0bab new isfloat function
John W. Eaton <jwe@octave.org>
parents: 7515
diff changeset
3441 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
3442 doc: /* -*- texinfo -*-
30559
841a10208c38 doc: Use TF for output variable in documentation for isXXX functions in libinterp/ directory.
Rik <rik@octave.org>
parents: 30402
diff changeset
3443 @deftypefn {} {@var{tf} =} isfloat (@var{x})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3444 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
3445
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3446 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
3447 @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
3448 @end deftypefn */)
7576
7ebdc99a0bab new isfloat function
John W. Eaton <jwe@octave.org>
parents: 7515
diff changeset
3449 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3450 if (args.length () != 1)
7576
7ebdc99a0bab new isfloat function
John W. Eaton <jwe@octave.org>
parents: 7515
diff changeset
3451 print_usage ();
7ebdc99a0bab new isfloat function
John W. Eaton <jwe@octave.org>
parents: 7515
diff changeset
3452
23585
570170b6eb09 maint: Deprecate is_float_type and replace with isfloat.
Rik <rik@octave.org>
parents: 23584
diff changeset
3453 return ovl (args(0).isfloat ());
7576
7ebdc99a0bab new isfloat function
John W. Eaton <jwe@octave.org>
parents: 7515
diff changeset
3454 }
7ebdc99a0bab new isfloat function
John W. Eaton <jwe@octave.org>
parents: 7515
diff changeset
3455
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
3456 // FIXME: perhaps this should be implemented with an
5476
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3457 // octave_value member function?
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3458
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3459 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
3460 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
3461 @deftypefn {} {@var{z} =} complex (@var{x})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
3462 @deftypefnx {} {@var{z} =} complex (@var{re}, @var{im})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3463 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
3464
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3465 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
3466 @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
3467
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3468 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
3469 @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
3470 @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
3471 @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
3472 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
3473
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3474 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3475 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3476 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
3477 @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
3478 @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
3479 @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
3480 @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
3481 @end deftypefn */)
30673
1182fcd6cdaf Coding changes for performance in complex() (bug #61912)
Rik <rik@octave.org>
parents: 30594
diff changeset
3482 // Programming Note: Throughout this function the coding pattern
1182fcd6cdaf Coding changes for performance in complex() (bug #61912)
Rik <rik@octave.org>
parents: 30594
diff changeset
3483 // octave_value (new XXX)) is used. This is done specifically because the
1182fcd6cdaf Coding changes for performance in complex() (bug #61912)
Rik <rik@octave.org>
parents: 30594
diff changeset
3484 // default octave_value constructor would otherwise perform automatic narrowing
1182fcd6cdaf Coding changes for performance in complex() (bug #61912)
Rik <rik@octave.org>
parents: 30594
diff changeset
3485 // (i.e., complex values with 0 for the imaginary part would be converted
1182fcd6cdaf Coding changes for performance in complex() (bug #61912)
Rik <rik@octave.org>
parents: 30594
diff changeset
3486 // to real values). The complex() function *must* return a complex value
1182fcd6cdaf Coding changes for performance in complex() (bug #61912)
Rik <rik@octave.org>
parents: 30594
diff changeset
3487 // even when the imaginary part is 0.
5476
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3488 {
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3489 int nargin = args.length ();
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3490
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3491 if (nargin < 1 || nargin > 2)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3492 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3493
5476
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3494 octave_value retval;
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3495
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3496 if (nargin == 1)
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3497 {
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3498 octave_value arg = args(0);
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3499
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
3500 if (arg.iscomplex ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3501 retval = arg;
5476
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3502 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3503 {
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
3504 if (arg.issparse ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3505 {
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20700
diff changeset
3506 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
3507
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3508 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
3509 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3510 else if (arg.is_single_type ())
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3511 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3512 if (arg.numel () == 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3513 {
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20700
diff changeset
3514 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
3515
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3516 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
3517 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3518 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3519 {
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20700
diff changeset
3520 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
3521
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3522 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
3523 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3524 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3525 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3526 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3527 if (arg.numel () == 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3528 {
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20700
diff changeset
3529 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
3530
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3531 retval = octave_value (new octave_complex (val));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3532 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3533 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3534 {
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20700
diff changeset
3535 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
3536
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3537 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
3538 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3539 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3540 }
5476
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3541 }
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3542 else
5476
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3543 {
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3544 octave_value re = args(0);
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3545 octave_value im = args(1);
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3546
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
3547 if (re.issparse () && im.issparse ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3548 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3549 const SparseMatrix re_val = re.sparse_matrix_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3550 const SparseMatrix im_val = im.sparse_matrix_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3551
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3552 if (re.numel () == 1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3553 {
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3554 SparseComplexMatrix result;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3555 if (re_val.nnz () == 0)
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3556 result = Complex (0, 1) * SparseComplexMatrix (im_val);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3557 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3558 {
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3559 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
3560 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
3561 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
3562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3563 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
3564 {
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3565 octave_idx_type off = j * nr;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3566 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
3567 i < im_val.cidx (j + 1); i++)
27277
db687716fed6 style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents: 27081
diff changeset
3568 result.data (im_val.ridx (i) + off)
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
3569 += Complex (0, im_val.data (i));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3570 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3571 }
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3572 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
3573 }
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3574 else if (im.numel () == 1)
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3575 {
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3576 SparseComplexMatrix result;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3577 if (im_val.nnz () == 0)
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3578 result = SparseComplexMatrix (re_val);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3579 else
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3580 {
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3581 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
3582 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
3583 result = SparseComplexMatrix (nr, nc,
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3584 Complex (0, im_val(0)));
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3585
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3586 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
3587 {
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3588 octave_idx_type off = j * nr;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3589 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
3590 i < re_val.cidx (j + 1); i++)
27277
db687716fed6 style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents: 27081
diff changeset
3591 result.data (re_val.ridx (i) + off)
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
3592 += re_val.data (i);
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3593 }
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3594 }
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3595 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
3596 }
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3597 else
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3598 {
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3599 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
3600 error ("complex: dimension mismatch");
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3601
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3602 SparseComplexMatrix result;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3603 result = SparseComplexMatrix (re_val)
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
3604 + Complex (0, 1) * SparseComplexMatrix (im_val);
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3605 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
3606 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3607 }
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7743
diff changeset
3608 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
3609 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3610 if (re.numel () == 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3611 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3612 float re_val = re.float_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3613
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3614 if (im.numel () == 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3615 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3616 float im_val = im.double_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3617
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3618 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
3619 (FloatComplex (re_val, im_val)));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3620 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3621 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3622 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3623 const FloatNDArray im_val = im.float_array_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3624
30673
1182fcd6cdaf Coding changes for performance in complex() (bug #61912)
Rik <rik@octave.org>
parents: 30594
diff changeset
3625 FloatComplexNDArray result (im_val.dims ());
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3626
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3627 for (octave_idx_type i = 0; i < im_val.numel (); i++)
30673
1182fcd6cdaf Coding changes for performance in complex() (bug #61912)
Rik <rik@octave.org>
parents: 30594
diff changeset
3628 result.xelem (i) = FloatComplex (re_val, im_val.xelem (i));
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3629
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3630 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
3631 (result));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3632 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3633 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3634 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3635 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3636 const FloatNDArray re_val = re.float_array_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3637
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3638 if (im.numel () == 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3639 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3640 float im_val = im.float_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3641
30673
1182fcd6cdaf Coding changes for performance in complex() (bug #61912)
Rik <rik@octave.org>
parents: 30594
diff changeset
3642 FloatComplexNDArray result (re_val.dims ());
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3643
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3644 for (octave_idx_type i = 0; i < re_val.numel (); i++)
30673
1182fcd6cdaf Coding changes for performance in complex() (bug #61912)
Rik <rik@octave.org>
parents: 30594
diff changeset
3645 result.xelem (i) = FloatComplex (re_val.xelem (i), im_val);
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3646
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3647 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
3648 (result));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3649 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3650 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3651 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3652 const FloatNDArray im_val = im.float_array_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3653
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3654 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
3655 error ("complex: dimension mismatch");
20921
4d3daf7e43f3 eliminate trailing whitespace in source files
John W. Eaton <jwe@octave.org>
parents: 20918
diff changeset
3656
30673
1182fcd6cdaf Coding changes for performance in complex() (bug #61912)
Rik <rik@octave.org>
parents: 30594
diff changeset
3657 FloatComplexNDArray result (re_val.dims ());
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3658
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3659 for (octave_idx_type i = 0; i < re_val.numel (); i++)
30673
1182fcd6cdaf Coding changes for performance in complex() (bug #61912)
Rik <rik@octave.org>
parents: 30594
diff changeset
3660 result.xelem (i) = FloatComplex (re_val.xelem (i),
1182fcd6cdaf Coding changes for performance in complex() (bug #61912)
Rik <rik@octave.org>
parents: 30594
diff changeset
3661 im_val.xelem (i));
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3662
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3663 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
3664 (result));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3665 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3666 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3667 }
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7743
diff changeset
3668 else if (re.numel () == 1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3669 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3670 double re_val = re.double_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3671
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3672 if (im.numel () == 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3673 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3674 double im_val = im.double_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3675
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3676 retval = octave_value (new octave_complex
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3677 (Complex (re_val, im_val)));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3678 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3679 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3680 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3681 const NDArray im_val = im.array_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3682
30673
1182fcd6cdaf Coding changes for performance in complex() (bug #61912)
Rik <rik@octave.org>
parents: 30594
diff changeset
3683 ComplexNDArray result (im_val.dims ());
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3684
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3685 for (octave_idx_type i = 0; i < im_val.numel (); i++)
30673
1182fcd6cdaf Coding changes for performance in complex() (bug #61912)
Rik <rik@octave.org>
parents: 30594
diff changeset
3686 result.xelem (i) = Complex (re_val, im_val.xelem (i));
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3687
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3688 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
3689 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3690 }
5476
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3691 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3692 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3693 const NDArray re_val = re.array_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3694
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3695 if (im.numel () == 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3696 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3697 double im_val = im.double_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3698
30673
1182fcd6cdaf Coding changes for performance in complex() (bug #61912)
Rik <rik@octave.org>
parents: 30594
diff changeset
3699 ComplexNDArray result (re_val.dims ());
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3700
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3701 for (octave_idx_type i = 0; i < re_val.numel (); i++)
30673
1182fcd6cdaf Coding changes for performance in complex() (bug #61912)
Rik <rik@octave.org>
parents: 30594
diff changeset
3702 result.xelem (i) = Complex (re_val.xelem (i), im_val);
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3703
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3704 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
3705 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3706 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3707 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3708 const NDArray im_val = im.array_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3709
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3710 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
3711 error ("complex: dimension mismatch");
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3712
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3713 ComplexNDArray result (re_val.dims (), Complex ());
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3714
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3715 for (octave_idx_type i = 0; i < re_val.numel (); i++)
30673
1182fcd6cdaf Coding changes for performance in complex() (bug #61912)
Rik <rik@octave.org>
parents: 30594
diff changeset
3716 result.xelem (i) = Complex (re_val.xelem (i),
1182fcd6cdaf Coding changes for performance in complex() (bug #61912)
Rik <rik@octave.org>
parents: 30594
diff changeset
3717 im_val.xelem (i));
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3718
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3719 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
3720 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3721 }
5476
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3722 }
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3723
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3724 return retval;
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3725 }
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3726
22590
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3727 /*
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3728 %!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
3729 %!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
3730
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3731 %!test <31974>
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3732 %! 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
3733 %!
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3734 %! 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
3735 %! 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
3736 %!
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3737 %! ## 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
3738 %! 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
3739 %! 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
3740 %!
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3741 %! 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
3742 %!
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3743 %! 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
3744
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3745 %!test <31974>
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3746 %! x = Inf;
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3747 %! 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
3748 %! 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
3749 %! 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
3750
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3751 %!test <31974>
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3752 %! 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
3753 %! 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
3754 %! 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
3755 %! 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
3756 %! 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
3757
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3758 %!test <31974>
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3759 %! 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
3760 %! 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
3761 %! 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
3762
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3763 %!test <31974>
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3764 %! 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
3765 %! 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
3766 %! 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
3767 %! 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
3768 */
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3769
3258
4964d5391acc [project @ 1999-07-21 21:51:33 by jwe]
jwe
parents: 3238
diff changeset
3770 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
3771 doc: /* -*- texinfo -*-
30559
841a10208c38 doc: Use TF for output variable in documentation for isXXX functions in libinterp/ directory.
Rik <rik@octave.org>
parents: 30402
diff changeset
3772 @deftypefn {} {@var{tf} =} isreal (@var{x})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3773 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
3774
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3775 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
3776 matrices.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3777 @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
3778 @end deftypefn */)
3258
4964d5391acc [project @ 1999-07-21 21:51:33 by jwe]
jwe
parents: 3238
diff changeset
3779 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3780 if (args.length () != 1)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
3781 print_usage ();
3258
4964d5391acc [project @ 1999-07-21 21:51:33 by jwe]
jwe
parents: 3238
diff changeset
3782
23582
0cc2011d800e maint: Deprecate is_real_type and replace with isreal.
Rik <rik@octave.org>
parents: 23581
diff changeset
3783 return ovl (args(0).isreal ());
3258
4964d5391acc [project @ 1999-07-21 21:51:33 by jwe]
jwe
parents: 3238
diff changeset
3784 }
4964d5391acc [project @ 1999-07-21 21:51:33 by jwe]
jwe
parents: 3238
diff changeset
3785
3202
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3195
diff changeset
3786 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
3787 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
3788 @deftypefn {} {@var{tf} =} isempty (@var{A})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
3789 Return true if @var{A} is an empty matrix (any one of its dimensions is
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3790 zero).
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3791 @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
3792 @end deftypefn */)
3202
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3195
diff changeset
3793 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3794 if (args.length () != 1)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
3795 print_usage ();
3202
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3195
diff changeset
3796
23577
80c42f4cca13 maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents: 23576
diff changeset
3797 return ovl (args(0).isempty ());
3202
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3195
diff changeset
3798 }
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3195
diff changeset
3799
16779
8fce0ed4894a Specialize is_empty and numel methods for sparse matrices (debian bug #706376)
David Bateman <dbateman@free.fr>
parents: 16077
diff changeset
3800 /*
22737
7abc25e6206a maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22708
diff changeset
3801 ## Debian bug #706376
28915
c40a367a84c0 maint: Use Octave convention of space after function name in libinterp/.
Rik <rik@octave.org>
parents: 28888
diff changeset
3802 %!assert (isempty (speye (2^16)), false)
16779
8fce0ed4894a Specialize is_empty and numel methods for sparse matrices (debian bug #706376)
David Bateman <dbateman@free.fr>
parents: 16077
diff changeset
3803 */
8fce0ed4894a Specialize is_empty and numel methods for sparse matrices (debian bug #706376)
David Bateman <dbateman@free.fr>
parents: 16077
diff changeset
3804
3206
d0d2b69dc6c2 [project @ 1998-11-03 02:43:31 by jwe]
jwe
parents: 3204
diff changeset
3805 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
3806 doc: /* -*- texinfo -*-
30559
841a10208c38 doc: Use TF for output variable in documentation for isXXX functions in libinterp/ directory.
Rik <rik@octave.org>
parents: 30402
diff changeset
3807 @deftypefn {} {@var{tf} =} isnumeric (@var{x})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3808 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
3809 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
3810
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3811 Logical and character arrays are not considered to be numeric.
30329
81d26e8481a6 maint: Shorten @seealso lines to less than 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30230
diff changeset
3812 @seealso{isinteger, isfloat, isreal, iscomplex, ischar, islogical, isstring,
81d26e8481a6 maint: Shorten @seealso lines to less than 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30230
diff changeset
3813 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
3814 @end deftypefn */)
3206
d0d2b69dc6c2 [project @ 1998-11-03 02:43:31 by jwe]
jwe
parents: 3204
diff changeset
3815 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3816 if (args.length () != 1)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
3817 print_usage ();
3206
d0d2b69dc6c2 [project @ 1998-11-03 02:43:31 by jwe]
jwe
parents: 3204
diff changeset
3818
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23585
diff changeset
3819 return ovl (args(0).isnumeric ());
3206
d0d2b69dc6c2 [project @ 1998-11-03 02:43:31 by jwe]
jwe
parents: 3204
diff changeset
3820 }
d0d2b69dc6c2 [project @ 1998-11-03 02:43:31 by jwe]
jwe
parents: 3204
diff changeset
3821
11435
20f53b3a558f Add tests for sparse forms of logical matrices to islogical, isnumeric.
Rik <octave@nomad.inbox5.com>
parents: 11431
diff changeset
3822 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3823 %!assert (isnumeric (1), true)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3824 %!assert (isnumeric (1i), true)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3825 %!assert (isnumeric ([1,1]), true)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3826 %!assert (isnumeric (single (1)), true)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3827 %!assert (isnumeric (single (1i)), true)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3828 %!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
3829 %!assert (isnumeric (int8 (1)), true)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3830 %!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
3831 %!assert (isnumeric ("Hello World"), false)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3832 %!assert (isnumeric (true), false)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3833 %!assert (isnumeric (false), false)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3834 %!assert (isnumeric ([true, false]), false)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3835 %!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
3836 */
20f53b3a558f Add tests for sparse forms of logical matrices to islogical, isnumeric.
Rik <octave@nomad.inbox5.com>
parents: 11431
diff changeset
3837
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
3838 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
3839 doc: /* -*- texinfo -*-
30559
841a10208c38 doc: Use TF for output variable in documentation for isXXX functions in libinterp/ directory.
Rik <rik@octave.org>
parents: 30402
diff changeset
3840 @deftypefn {} {@var{tf} =} isscalar (@var{x})
28043
711cf9b1be49 doc: Reword isscalar, isvector, isrow, iscolumn, ismatrix, issquare docstrings.
Rik <rik@octave.org>
parents: 28012
diff changeset
3841 Return true if @var{x} is a scalar.
711cf9b1be49 doc: Reword isscalar, isvector, isrow, iscolumn, ismatrix, issquare docstrings.
Rik <rik@octave.org>
parents: 28012
diff changeset
3842
711cf9b1be49 doc: Reword isscalar, isvector, isrow, iscolumn, ismatrix, issquare docstrings.
Rik <rik@octave.org>
parents: 28012
diff changeset
3843 A scalar is an object with two dimensions for which @code{size (@var{x})}
711cf9b1be49 doc: Reword isscalar, isvector, isrow, iscolumn, ismatrix, issquare docstrings.
Rik <rik@octave.org>
parents: 28012
diff changeset
3844 returns @w{@code{[1, 1]}}.
711cf9b1be49 doc: Reword isscalar, isvector, isrow, iscolumn, ismatrix, issquare docstrings.
Rik <rik@octave.org>
parents: 28012
diff changeset
3845 @seealso{isvector, ismatrix, 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
3846 @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
3847 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3848 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
3849 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
3850
25917
ba937c3dce82 Determine an object's shape by "size" (bug #51308, bug #44498, bug #43925).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25861
diff changeset
3851 // This function *must* use size() to determine the desired values to be
ba937c3dce82 Determine an object's shape by "size" (bug #51308, bug #44498, bug #43925).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25861
diff changeset
3852 // compatible with Matlab and to allow user-defined class overloading.
ba937c3dce82 Determine an object's shape by "size" (bug #51308, bug #44498, bug #43925).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25861
diff changeset
3853 Matrix sz = octave_value (args(0)).size ();
ba937c3dce82 Determine an object's shape by "size" (bug #51308, bug #44498, bug #43925).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25861
diff changeset
3854
ba937c3dce82 Determine an object's shape by "size" (bug #51308, bug #44498, bug #43925).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25861
diff changeset
3855 return ovl (sz.numel () == 2 && sz(0) == 1 && sz(1) == 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
3856 }
bc52657a7d29 Convert isscalar from an m-file to a built-in function (bug #42422).
Jason Alan Palmer <jalanpalmer@gmail.com>
parents: 18812
diff changeset
3857
bc52657a7d29 Convert isscalar from an m-file to a built-in function (bug #42422).
Jason Alan Palmer <jalanpalmer@gmail.com>
parents: 18812
diff changeset
3858 /*
bc52657a7d29 Convert isscalar from an m-file to a built-in function (bug #42422).
Jason Alan Palmer <jalanpalmer@gmail.com>
parents: 18812
diff changeset
3859 %!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
3860 %!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
3861 %!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
3862 %!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
3863
bc52657a7d29 Convert isscalar from an m-file to a built-in function (bug #42422).
Jason Alan Palmer <jalanpalmer@gmail.com>
parents: 18812
diff changeset
3864 %!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
3865 %!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
3866 %!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
3867
bc52657a7d29 Convert isscalar from an m-file to a built-in function (bug #42422).
Jason Alan Palmer <jalanpalmer@gmail.com>
parents: 18812
diff changeset
3868 %!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
3869 %! 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
3870 %! 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
3871
22737
7abc25e6206a maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22708
diff changeset
3872 ## 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
3873 %!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
3874 %!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
3875 */
bc52657a7d29 Convert isscalar from an m-file to a built-in function (bug #42422).
Jason Alan Palmer <jalanpalmer@gmail.com>
parents: 18812
diff changeset
3876
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3877 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
3878 doc: /* -*- texinfo -*-
30559
841a10208c38 doc: Use TF for output variable in documentation for isXXX functions in libinterp/ directory.
Rik <rik@octave.org>
parents: 30402
diff changeset
3879 @deftypefn {} {@var{tf} =} isvector (@var{x})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3880 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
3881
28714
d8dcb36bb904 maint: spellcheck documentation ahead of 6.1 release.
Rik <rik@octave.org>
parents: 28043
diff changeset
3882 A vector is a 2-D array where one of the dimensions is equal to 1 (either
d8dcb36bb904 maint: spellcheck documentation ahead of 6.1 release.
Rik <rik@octave.org>
parents: 28043
diff changeset
3883 @nospell{1xN} or @nospell{Nx1}). As a consequence of this definition, a 1x1
d8dcb36bb904 maint: spellcheck documentation ahead of 6.1 release.
Rik <rik@octave.org>
parents: 28043
diff changeset
3884 array (a scalar) is also a vector.
28043
711cf9b1be49 doc: Reword isscalar, isvector, isrow, iscolumn, ismatrix, issquare docstrings.
Rik <rik@octave.org>
parents: 28012
diff changeset
3885 @seealso{isscalar, ismatrix, iscolumn, isrow, 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
3886 @end deftypefn */)
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3887 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3888 if (args.length () != 1)
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3889 print_usage ();
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3890
25917
ba937c3dce82 Determine an object's shape by "size" (bug #51308, bug #44498, bug #43925).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25861
diff changeset
3891 // This function *must* use size() to determine the desired values to be
ba937c3dce82 Determine an object's shape by "size" (bug #51308, bug #44498, bug #43925).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25861
diff changeset
3892 // compatible with Matlab and to allow user-defined class overloading.
ba937c3dce82 Determine an object's shape by "size" (bug #51308, bug #44498, bug #43925).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25861
diff changeset
3893 Matrix sz = octave_value (args(0)).size ();
ba937c3dce82 Determine an object's shape by "size" (bug #51308, bug #44498, bug #43925).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25861
diff changeset
3894
ba937c3dce82 Determine an object's shape by "size" (bug #51308, bug #44498, bug #43925).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25861
diff changeset
3895 return ovl (sz.numel () == 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
3896 }
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3897
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3898 /*
19700
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3899 %!assert (isvector (1), true)
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3900 %!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
3901 %!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
3902 %!assert (isvector ([]), false)
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3903 %!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
3904
19700
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3905 %!assert (isvector ("t"), true)
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3906 %!assert (isvector ("test"), true)
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3907 %!assert (isvector (["test"; "ing"]), false)
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3908
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3909 %!test
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3910 %! s.a = 1;
19700
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3911 %! assert (isvector (s), true);
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3912
22737
7abc25e6206a maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22708
diff changeset
3913 ## Test input validation
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3914 %!error isvector ()
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3915 %!error isvector ([1, 2], 2)
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3916 */
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3917
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3918 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
3919 doc: /* -*- texinfo -*-
30559
841a10208c38 doc: Use TF for output variable in documentation for isXXX functions in libinterp/ directory.
Rik <rik@octave.org>
parents: 30402
diff changeset
3920 @deftypefn {} {@var{tf} =} isrow (@var{x})
28043
711cf9b1be49 doc: Reword isscalar, isvector, isrow, iscolumn, ismatrix, issquare docstrings.
Rik <rik@octave.org>
parents: 28012
diff changeset
3921 Return true if @var{x} is a row vector.
711cf9b1be49 doc: Reword isscalar, isvector, isrow, iscolumn, ismatrix, issquare docstrings.
Rik <rik@octave.org>
parents: 28012
diff changeset
3922
711cf9b1be49 doc: Reword isscalar, isvector, isrow, iscolumn, ismatrix, issquare docstrings.
Rik <rik@octave.org>
parents: 28012
diff changeset
3923 A row vector is a 2-D array for which @code{size (@var{x})} returns
711cf9b1be49 doc: Reword isscalar, isvector, isrow, iscolumn, ismatrix, issquare docstrings.
Rik <rik@octave.org>
parents: 28012
diff changeset
3924 @w{@code{[1, N]}} with non-negative N.
711cf9b1be49 doc: Reword isscalar, isvector, isrow, iscolumn, ismatrix, issquare docstrings.
Rik <rik@octave.org>
parents: 28012
diff changeset
3925 @seealso{iscolumn, isscalar, isvector, ismatrix, 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
3926 @end deftypefn */)
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3927 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3928 if (args.length () != 1)
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3929 print_usage ();
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3930
25917
ba937c3dce82 Determine an object's shape by "size" (bug #51308, bug #44498, bug #43925).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25861
diff changeset
3931 // This function *must* use size() to determine the desired values to be
ba937c3dce82 Determine an object's shape by "size" (bug #51308, bug #44498, bug #43925).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25861
diff changeset
3932 // compatible with Matlab and to allow user-defined class overloading.
ba937c3dce82 Determine an object's shape by "size" (bug #51308, bug #44498, bug #43925).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25861
diff changeset
3933 Matrix sz = octave_value (args(0)).size ();
ba937c3dce82 Determine an object's shape by "size" (bug #51308, bug #44498, bug #43925).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25861
diff changeset
3934
ba937c3dce82 Determine an object's shape by "size" (bug #51308, bug #44498, bug #43925).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25861
diff changeset
3935 return ovl (sz.numel () == 2 && sz(0) == 1);
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3936 }
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3937
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3938 /*
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3939 %!assert (isrow ([1, 2, 3]))
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3940 %!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
3941 %!assert (isrow (1))
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3942 %!assert (isrow ([]), false)
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3943 %!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
3944
19700
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3945 %!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
3946 %!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
3947 %!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
3948 %!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
3949 %!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
3950
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3951 %!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
3952 %!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
3953
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3954 %!assert (isrow ("t"), true)
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3955 %!assert (isrow ("test"), true)
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3956 %!assert (isrow (["test"; "ing"]), false)
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3957
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3958 %!test
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3959 %! s.a = 1;
19700
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3960 %! assert (isrow (s), true);
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3961
22737
7abc25e6206a maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22708
diff changeset
3962 ## Test input validation
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3963 %!error isrow ()
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3964 %!error isrow ([1, 2], 2)
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3965 */
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3966
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3967 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
3968 doc: /* -*- texinfo -*-
30559
841a10208c38 doc: Use TF for output variable in documentation for isXXX functions in libinterp/ directory.
Rik <rik@octave.org>
parents: 30402
diff changeset
3969 @deftypefn {} {@var{tf} =} iscolumn (@var{x})
28043
711cf9b1be49 doc: Reword isscalar, isvector, isrow, iscolumn, ismatrix, issquare docstrings.
Rik <rik@octave.org>
parents: 28012
diff changeset
3970 Return true if @var{x} is a column vector.
711cf9b1be49 doc: Reword isscalar, isvector, isrow, iscolumn, ismatrix, issquare docstrings.
Rik <rik@octave.org>
parents: 28012
diff changeset
3971
711cf9b1be49 doc: Reword isscalar, isvector, isrow, iscolumn, ismatrix, issquare docstrings.
Rik <rik@octave.org>
parents: 28012
diff changeset
3972 A column vector is a 2-D array for which @code{size (@var{x})} returns
711cf9b1be49 doc: Reword isscalar, isvector, isrow, iscolumn, ismatrix, issquare docstrings.
Rik <rik@octave.org>
parents: 28012
diff changeset
3973 @w{@code{[N, 1]}} with non-negative N.
711cf9b1be49 doc: Reword isscalar, isvector, isrow, iscolumn, ismatrix, issquare docstrings.
Rik <rik@octave.org>
parents: 28012
diff changeset
3974 @seealso{isrow, isscalar, isvector, ismatrix, 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
3975 @end deftypefn */)
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3976 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3977 if (args.length () != 1)
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3978 print_usage ();
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3979
25917
ba937c3dce82 Determine an object's shape by "size" (bug #51308, bug #44498, bug #43925).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25861
diff changeset
3980 // This function *must* use size() to determine the desired values to be
ba937c3dce82 Determine an object's shape by "size" (bug #51308, bug #44498, bug #43925).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25861
diff changeset
3981 // compatible with Matlab and to allow user-defined class overloading.
ba937c3dce82 Determine an object's shape by "size" (bug #51308, bug #44498, bug #43925).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25861
diff changeset
3982 Matrix sz = octave_value (args(0)).size ();
ba937c3dce82 Determine an object's shape by "size" (bug #51308, bug #44498, bug #43925).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25861
diff changeset
3983
ba937c3dce82 Determine an object's shape by "size" (bug #51308, bug #44498, bug #43925).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25861
diff changeset
3984 return ovl (sz.numel () == 2 && sz(1) == 1);
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3985 }
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3986
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3987 /*
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3988 %!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
3989 %!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
3990 %!assert (iscolumn (1), true)
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3991 %!assert (iscolumn ([]), false)
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3992 %!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
3993
19700
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3994 %!assert (iscolumn ("t"), true)
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3995 %!assert (iscolumn ("test"), false)
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3996 %!assert (iscolumn (["test"; "ing"]), false)
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3997
19700
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3998 %!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
3999 %!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
4000 %!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
4001 %!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
4002 %!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
4003
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
4004 %!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
4005 %!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
4006
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
4007 %!test
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
4008 %! s.a = 1;
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
4009 %! assert (iscolumn (s));
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
4010
22737
7abc25e6206a maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22708
diff changeset
4011 ## Test input validation
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
4012 %!error iscolumn ()
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
4013 %!error iscolumn ([1, 2], 2)
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
4014 */
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
4015
4028
ef75c970c8f5 [project @ 2002-08-09 07:19:02 by jwe]
jwe
parents: 4025
diff changeset
4016 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
4017 doc: /* -*- texinfo -*-
30559
841a10208c38 doc: Use TF for output variable in documentation for isXXX functions in libinterp/ directory.
Rik <rik@octave.org>
parents: 30402
diff changeset
4018 @deftypefn {} {@var{tf} =} ismatrix (@var{x})
28043
711cf9b1be49 doc: Reword isscalar, isvector, isrow, iscolumn, ismatrix, issquare docstrings.
Rik <rik@octave.org>
parents: 28012
diff changeset
4019 Return true if @var{x} is a 2-D array.
711cf9b1be49 doc: Reword isscalar, isvector, isrow, iscolumn, ismatrix, issquare docstrings.
Rik <rik@octave.org>
parents: 28012
diff changeset
4020
711cf9b1be49 doc: Reword isscalar, isvector, isrow, iscolumn, ismatrix, issquare docstrings.
Rik <rik@octave.org>
parents: 28012
diff changeset
4021 A matrix is an object with two dimensions (@code{ndims (@var{x}) == 2}) for
711cf9b1be49 doc: Reword isscalar, isvector, isrow, iscolumn, ismatrix, issquare docstrings.
Rik <rik@octave.org>
parents: 28012
diff changeset
4022 which @code{size (@var{x})} returns @w{@code{[M, N]}} with non-negative M and
711cf9b1be49 doc: Reword isscalar, isvector, isrow, iscolumn, ismatrix, issquare docstrings.
Rik <rik@octave.org>
parents: 28012
diff changeset
4023 N.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4024 @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
4025 @end deftypefn */)
3202
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3195
diff changeset
4026 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
4027 if (args.length () != 1)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
4028 print_usage ();
3202
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3195
diff changeset
4029
25917
ba937c3dce82 Determine an object's shape by "size" (bug #51308, bug #44498, bug #43925).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25861
diff changeset
4030 // This function *must* use size() to determine the desired values to be
ba937c3dce82 Determine an object's shape by "size" (bug #51308, bug #44498, bug #43925).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25861
diff changeset
4031 // compatible with Matlab and to allow user-defined class overloading.
ba937c3dce82 Determine an object's shape by "size" (bug #51308, bug #44498, bug #43925).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25861
diff changeset
4032 Matrix sz = octave_value (args(0)).size ();
ba937c3dce82 Determine an object's shape by "size" (bug #51308, bug #44498, bug #43925).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25861
diff changeset
4033
ba937c3dce82 Determine an object's shape by "size" (bug #51308, bug #44498, bug #43925).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25861
diff changeset
4034 return ovl (sz.numel () == 2 && sz(0) >= 0 && sz(1) >= 0);
3202
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3195
diff changeset
4035 }
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3195
diff changeset
4036
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
4037 /*
19700
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
4038 %!assert (ismatrix ([]), true)
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
4039 %!assert (ismatrix (1), true)
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
4040 %!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
4041 %!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
4042
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
4043 %!assert (ismatrix (zeros (0)), true)
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
4044 %!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
4045 %!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
4046 %!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
4047
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
4048 %!assert (ismatrix (single ([])), true)
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
4049 %!assert (ismatrix (single (1)), true)
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
4050 %!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
4051 %!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
4052
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
4053 %!assert (ismatrix ("t"), true)
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
4054 %!assert (ismatrix ("test"), true)
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
4055 %!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
4056
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
4057 %!test
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
4058 %! s.a = 1;
19700
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
4059 %! assert (ismatrix (s), true);
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4060
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4061 %!error ismatrix ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4062 %!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
4063 */
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
4064
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
4065 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
4066 doc: /* -*- texinfo -*-
30559
841a10208c38 doc: Use TF for output variable in documentation for isXXX functions in libinterp/ directory.
Rik <rik@octave.org>
parents: 30402
diff changeset
4067 @deftypefn {} {@var{tf} =} issquare (@var{x})
28043
711cf9b1be49 doc: Reword isscalar, isvector, isrow, iscolumn, ismatrix, issquare docstrings.
Rik <rik@octave.org>
parents: 28012
diff changeset
4068 Return true if @var{x} is a 2-D square array.
711cf9b1be49 doc: Reword isscalar, isvector, isrow, iscolumn, ismatrix, issquare docstrings.
Rik <rik@octave.org>
parents: 28012
diff changeset
4069
711cf9b1be49 doc: Reword isscalar, isvector, isrow, iscolumn, ismatrix, issquare docstrings.
Rik <rik@octave.org>
parents: 28012
diff changeset
4070 A square array is a 2-D object for which @code{size (@var{x})} returns
711cf9b1be49 doc: Reword isscalar, isvector, isrow, iscolumn, ismatrix, issquare docstrings.
Rik <rik@octave.org>
parents: 28012
diff changeset
4071 @w{@code{[N, N]}} where N is a non-negative integer.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4072 @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
4073 @end deftypefn */)
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
4074 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
4075 if (args.length () != 1)
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
4076 print_usage ();
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
4077
25917
ba937c3dce82 Determine an object's shape by "size" (bug #51308, bug #44498, bug #43925).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25861
diff changeset
4078 // This function *must* use size() to determine the desired values to
ba937c3dce82 Determine an object's shape by "size" (bug #51308, bug #44498, bug #43925).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25861
diff changeset
4079 // allow user-defined class overloading.
ba937c3dce82 Determine an object's shape by "size" (bug #51308, bug #44498, bug #43925).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25861
diff changeset
4080 Matrix sz = octave_value (args(0)).size ();
ba937c3dce82 Determine an object's shape by "size" (bug #51308, bug #44498, bug #43925).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25861
diff changeset
4081
ba937c3dce82 Determine an object's shape by "size" (bug #51308, bug #44498, bug #43925).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25861
diff changeset
4082 return ovl (sz.numel () == 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
4083 }
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
4084
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
4085 /*
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
4086 %!assert (issquare ([]))
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
4087 %!assert (issquare (1))
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
4088 %!assert (! issquare ([1, 2]))
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
4089 %!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
4090 %!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
4091 %!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
4092 %!assert (issquare ("t"))
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
4093 %!assert (! issquare ("test"))
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
4094 %!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
4095 %!test
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
4096 %! s.a = 1;
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
4097 %! assert (issquare (s));
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
4098 %!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
4099 %!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
4100
22737
7abc25e6206a maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22708
diff changeset
4101 ## Test input validation
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
4102 %!error issquare ()
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
4103 %!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
4104 */
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
4105
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3333
diff changeset
4106 static octave_value
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4107 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
4108 {
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3333
diff changeset
4109 octave_value retval;
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
4110
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
4111 int nargin = args.length ();
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
4112
4946
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
4113 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
4114
4946
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
4115 dim_vector dims (1, 1);
29086
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4116 bool issparse = false;
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4117 bool iscomplex = false;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
4118
4481
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4479
diff changeset
4119 if (nargin > 0 && args(nargin-1).is_string ())
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4479
diff changeset
4120 {
4946
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
4121 std::string nm = args(nargin-1).string_value ();
4481
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4479
diff changeset
4122 nargin--;
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4479
diff changeset
4123
4946
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
4124 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
4125 }
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4479
diff changeset
4126
29086
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4127 if (nargin > 1 && args(nargin-2).is_string ()
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4128 && args(nargin-2).string_value () == "like")
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4129 {
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4130 std::string nm = args(nargin-1).class_name ();
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4131 issparse = args(nargin-1).issparse ();
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4132 iscomplex = args(nargin-1).iscomplex ();
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4133 nargin -= 2;
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4134 dt = oct_data_conv::string_to_data_type (nm);
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4135 }
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4136
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
4137 switch (nargin)
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
4138 {
712
36ba0576bd1b [project @ 1994-09-19 14:18:15 by jwe]
jwe
parents: 649
diff changeset
4139 case 0:
36ba0576bd1b [project @ 1994-09-19 14:18:15 by jwe]
jwe
parents: 649
diff changeset
4140 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 767
diff changeset
4141
610
14b2a186a5c0 [project @ 1994-08-14 00:55:49 by jwe]
jwe
parents: 597
diff changeset
4142 case 1:
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
4143 get_dimensions (args(0), fcn, dims);
610
14b2a186a5c0 [project @ 1994-08-14 00:55:49 by jwe]
jwe
parents: 597
diff changeset
4144 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 767
diff changeset
4145
4563
742993a501b9 [project @ 2003-10-29 06:25:12 by jwe]
jwe
parents: 4559
diff changeset
4146 default:
742993a501b9 [project @ 2003-10-29 06:25:12 by jwe]
jwe
parents: 4559
diff changeset
4147 {
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4148 dims.resize (nargin);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4149
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4150 for (int i = 0; i < nargin; i++)
30934
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4151 {
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4152 if (args(i).numel () > 1)
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4153 error ("%s: dimensions must be scalars.", fcn);
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4154
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4155 dims(i) = (args(i).isempty () ? 0 : args(i).idx_type_value (true));
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4156 }
4563
742993a501b9 [project @ 2003-10-29 06:25:12 by jwe]
jwe
parents: 4559
diff changeset
4157 }
742993a501b9 [project @ 2003-10-29 06:25:12 by jwe]
jwe
parents: 4559
diff changeset
4158 break;
4481
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4479
diff changeset
4159 }
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4479
diff changeset
4160
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4161 dims.chop_trailing_singletons ();
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4162
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
4163 check_dimensions (dims, fcn);
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4164
25926
373fe1608f7c Emit an error when utility matrices (zeros, ones, rand, etc.) are given a fractional dimension (bug #54781).
Rik <rik@octave.org>
parents: 25917
diff changeset
4165 // FIXME: Perhaps this should be made extensible by using the class name
373fe1608f7c Emit an error when utility matrices (zeros, ones, rand, etc.) are given a fractional dimension (bug #54781).
Rik <rik@octave.org>
parents: 25917
diff changeset
4166 // to lookup a function to call to create the new value.
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4167
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4168 // 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
4169 // NDArray to scalar.
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4170
29086
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4171 if (issparse)
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4172 {
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4173 if (dims.ndims () > 2)
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4174 error ("%s: sparse ND arrays not supported.", fcn);
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4175
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4176 switch (dt)
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4177 {
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4178 case oct_data_conv::dt_double:
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4179 if (iscomplex)
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4180 retval = SparseComplexMatrix (dims(0), dims(1), Complex (val, 0));
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4181 else
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4182 retval = SparseMatrix (dims(0), dims(1), static_cast<double> (val));
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4183 break;
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4184
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4185 case oct_data_conv::dt_logical:
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4186 retval = SparseBoolMatrix (dims(0), dims(1), static_cast<bool> (val));
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4187 break;
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4188
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4189 default:
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4190 // FIXME: It shouldn't be possible to ever reach this.
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4191 error ("%s: invalid class name for sparse", fcn);
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4192 }
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4193
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4194 return retval;
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4195 }
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4196
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4197 switch (dt)
4481
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4479
diff changeset
4198 {
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4199 case oct_data_conv::dt_int8:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4200 retval = int8NDArray (dims, val);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4201 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4202
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4203 case oct_data_conv::dt_uint8:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4204 retval = uint8NDArray (dims, val);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4205 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4206
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4207 case oct_data_conv::dt_int16:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4208 retval = int16NDArray (dims, val);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4209 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4210
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4211 case oct_data_conv::dt_uint16:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4212 retval = uint16NDArray (dims, val);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4213 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4214
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4215 case oct_data_conv::dt_int32:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4216 retval = int32NDArray (dims, val);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4217 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4218
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4219 case oct_data_conv::dt_uint32:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4220 retval = uint32NDArray (dims, val);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4221 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4222
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4223 case oct_data_conv::dt_int64:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4224 retval = int64NDArray (dims, val);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4225 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4226
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4227 case oct_data_conv::dt_uint64:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4228 retval = uint64NDArray (dims, val);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4229 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4230
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4231 case oct_data_conv::dt_single:
29086
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4232 if (iscomplex)
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4233 retval = FloatComplexNDArray (dims, val);
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4234 else
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4235 retval = FloatNDArray (dims, val);
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4236 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4237
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4238 case oct_data_conv::dt_double:
29086
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4239 if (iscomplex)
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4240 retval = ComplexNDArray (dims, Complex (val, 0));
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4241 else
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4242 retval = NDArray (dims, val);
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4243 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4244
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4245 case oct_data_conv::dt_logical:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4246 retval = boolNDArray (dims, val);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4247 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4248
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4249 default:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4250 error ("%s: invalid class name", fcn);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4251 break;
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
4252 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
4253
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
4254 return retval;
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
4255 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
4256
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4257 static octave_value
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
4258 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
4259 const char *fcn)
7795
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4260 {
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4261 octave_value retval;
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4262
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4263 int nargin = args.length ();
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4264
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4265 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
4266
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4267 dim_vector dims (1, 1);
29086
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4268 bool issparse = false;
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4269 bool iscomplex = false;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
4270
7795
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4271 if (nargin > 0 && args(nargin-1).is_string ())
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4272 {
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4273 std::string nm = args(nargin-1).string_value ();
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4274 nargin--;
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4275
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4276 dt = oct_data_conv::string_to_data_type (nm);
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4277 }
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4278
29086
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4279 if (nargin > 1 && args(nargin-2).is_string ()
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4280 && args(nargin-2).string_value () == "like"
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4281 && (std::string(fcn) == "Inf"
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4282 || std::string(fcn) == "NaN" || std::string(fcn) == "NA"))
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4283 {
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4284 if (! args(nargin-1).isfloat ())
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4285 error ("%s: input followed by 'like' must be floating point", fcn);
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4286 std::string nm = args(nargin-1).class_name ();
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4287 issparse = args(nargin-1).issparse ();
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4288 iscomplex = args(nargin-1).iscomplex ();
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4289 nargin -= 2;
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4290 dt = oct_data_conv::string_to_data_type (nm);
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4291 }
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4292
7795
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4293 switch (nargin)
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4294 {
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4295 case 0:
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4296 break;
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4297
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4298 case 1:
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
4299 get_dimensions (args(0), fcn, dims);
7795
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4300 break;
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4301
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4302 default:
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4303 {
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4304 dims.resize (nargin);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4305
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4306 for (int i = 0; i < nargin; i++)
30934
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4307 {
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4308 if (args(i).numel () > 1)
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4309 error ("%s: dimensions must be scalars.", fcn);
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4310
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4311 dims(i) = (args(i).isempty () ? 0 : args(i).idx_type_value (true));
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4312 }
7795
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4313 }
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4314 break;
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4315 }
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4316
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4317 dims.chop_trailing_singletons ();
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4318
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
4319 check_dimensions (dims, fcn);
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4320
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4321 // 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
4322 // NDArray to scalar.
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4323
29086
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4324 if (issparse)
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4325 {
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4326 if (dims.ndims () > 2)
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4327 error ("%s: sparse ND arrays not supported", fcn);
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4328
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4329 if (iscomplex)
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4330 retval = SparseComplexMatrix (dims(0), dims(1), Complex (val, 0));
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4331 else
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4332 retval = SparseMatrix (dims(0), dims(1), static_cast<double> (val));
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4333
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4334 return retval;
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4335 }
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4336
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4337 switch (dt)
7795
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4338 {
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4339 case oct_data_conv::dt_single:
29086
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4340 if (iscomplex)
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4341 retval = FloatComplexNDArray (dims, fval);
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4342 else
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4343 retval = FloatNDArray (dims, fval);
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4344 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4345
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4346 case oct_data_conv::dt_double:
29086
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4347 if (iscomplex)
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4348 retval = ComplexNDArray (dims, Complex (val, 0));
27568
e78b6e7f743c Store constant row vectors for ones(), zeros(), pi(), e() as Ranges for compactness.
Rik <rik@octave.org>
parents: 27435
diff changeset
4349 else
e78b6e7f743c Store constant row vectors for ones(), zeros(), pi(), e() as Ranges for compactness.
Rik <rik@octave.org>
parents: 27435
diff changeset
4350 retval = NDArray (dims, val);
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4351 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4352
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4353 default:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4354 error ("%s: invalid class name", fcn);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4355 break;
7795
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4356 }
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4357
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4358 return retval;
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4359 }
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4360
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4361 static octave_value
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4362 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
4363 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4364 octave_value retval;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4365
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4366 int nargin = args.length ();
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4367
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4368 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
4369
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4370 dim_vector dims (1, 1);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
4371
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4372 if (nargin > 0 && args(nargin-1).is_string ())
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4373 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4374 std::string nm = args(nargin-1).string_value ();
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4375 nargin--;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4376
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4377 dt = oct_data_conv::string_to_data_type (nm);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4378 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4379
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4380 switch (nargin)
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4381 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4382 case 0:
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4383 break;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4384
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4385 case 1:
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
4386 get_dimensions (args(0), fcn, dims);
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4387 break;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4388
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4389 default:
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4390 {
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4391 dims.resize (nargin);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4392
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4393 for (int i = 0; i < nargin; i++)
30934
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4394 {
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4395 if (args(i).numel () > 1)
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4396 error ("%s: dimensions must be scalars.", fcn);
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4397
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4398 dims(i) = (args(i).isempty () ? 0 : args(i).idx_type_value (true));
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4399 }
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4400 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4401 break;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4402 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4403
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4404 dims.chop_trailing_singletons ();
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4405
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
4406 check_dimensions (dims, fcn);
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4407
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4408 // 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
4409 // NDArray to scalar.
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4410
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4411 switch (dt)
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4412 {
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4413 case oct_data_conv::dt_single:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4414 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
4415 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4416
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4417 case oct_data_conv::dt_double:
30853
fc3bd70cd1be eliminate range<T>::make_constant function
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
4418 retval = NDArray (dims, val);
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4419 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4420
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4421 default:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4422 error ("%s: invalid class name", fcn);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4423 break;
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4424 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4425
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4426 return retval;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4427 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4428
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4429 static octave_value
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4430 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
4431 const char *fcn)
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4432 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4433 octave_value retval;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4434
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4435 int nargin = args.length ();
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4436
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4437 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
4438
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4439 dim_vector dims (1, 1);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
4440
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4441 if (nargin > 0 && args(nargin-1).is_string ())
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4442 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4443 std::string nm = args(nargin-1).string_value ();
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4444 nargin--;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4445
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4446 dt = oct_data_conv::string_to_data_type (nm);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4447 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4448
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4449 switch (nargin)
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 case 0:
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4452 break;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4453
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4454 case 1:
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
4455 get_dimensions (args(0), fcn, dims);
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4456 break;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4457
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4458 default:
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4459 {
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4460 dims.resize (nargin);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4461
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4462 for (int i = 0; i < nargin; i++)
30934
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4463 {
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4464 if (args(i).numel () > 1)
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4465 error ("%s: dimensions must be scalars.", fcn);
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4466
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4467 dims(i) = (args(i).isempty () ? 0 : args(i).idx_type_value (true));
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4468 }
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4469 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4470 break;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4471 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4472
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4473 dims.chop_trailing_singletons ();
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4474
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
4475 check_dimensions (dims, fcn);
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4476
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4477 // 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
4478 // NDArray to scalar.
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4479
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4480 switch (dt)
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4481 {
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4482 case oct_data_conv::dt_single:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4483 retval = FloatComplexNDArray (dims,
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4484 static_cast<FloatComplex> (val));
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4485 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4486
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4487 case oct_data_conv::dt_double:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4488 retval = ComplexNDArray (dims, val);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4489 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4490
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4491 default:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4492 error ("%s: invalid class name", fcn);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4493 break;
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4494 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4495
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4496 return retval;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4497 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4498
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4499 static octave_value
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4500 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
4501 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4502 octave_value retval;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4503
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4504 int nargin = args.length ();
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4505
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4506 dim_vector dims (1, 1);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
4507
28115
de2c73ae450f allow data type argument for true and false functions
John W. Eaton <jwe@octave.org>
parents: 28043
diff changeset
4508 // The TYPE argument is required to be "logical" if present. This
de2c73ae450f allow data type argument for true and false functions
John W. Eaton <jwe@octave.org>
parents: 28043
diff changeset
4509 // feature appears to be undocumented in Matlab.
de2c73ae450f allow data type argument for true and false functions
John W. Eaton <jwe@octave.org>
parents: 28043
diff changeset
4510
de2c73ae450f allow data type argument for true and false functions
John W. Eaton <jwe@octave.org>
parents: 28043
diff changeset
4511 if (nargin > 0 && args(nargin-1).is_string ())
de2c73ae450f allow data type argument for true and false functions
John W. Eaton <jwe@octave.org>
parents: 28043
diff changeset
4512 {
de2c73ae450f allow data type argument for true and false functions
John W. Eaton <jwe@octave.org>
parents: 28043
diff changeset
4513 std::string nm = args(nargin-1).string_value ();
de2c73ae450f allow data type argument for true and false functions
John W. Eaton <jwe@octave.org>
parents: 28043
diff changeset
4514 nargin--;
de2c73ae450f allow data type argument for true and false functions
John W. Eaton <jwe@octave.org>
parents: 28043
diff changeset
4515
de2c73ae450f allow data type argument for true and false functions
John W. Eaton <jwe@octave.org>
parents: 28043
diff changeset
4516 if (oct_data_conv::string_to_data_type (nm) != oct_data_conv::dt_logical)
de2c73ae450f allow data type argument for true and false functions
John W. Eaton <jwe@octave.org>
parents: 28043
diff changeset
4517 error ("%s: invalid data type '%s'", fcn, nm.c_str ());
de2c73ae450f allow data type argument for true and false functions
John W. Eaton <jwe@octave.org>
parents: 28043
diff changeset
4518 }
de2c73ae450f allow data type argument for true and false functions
John W. Eaton <jwe@octave.org>
parents: 28043
diff changeset
4519
29086
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4520 bool issparse = false;
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4521
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4522 if (nargin > 1 && args(nargin-2).is_string ()
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4523 && args(nargin-2).string_value () == "like")
30390
a61e1a0f6024 maint: style check C++ files in libinterp/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 30377
diff changeset
4524 {
a61e1a0f6024 maint: style check C++ files in libinterp/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 30377
diff changeset
4525 if (! args(nargin-1).islogical ())
a61e1a0f6024 maint: style check C++ files in libinterp/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 30377
diff changeset
4526 error (R"(%s: input followed by "like" must be logical)", fcn);
a61e1a0f6024 maint: style check C++ files in libinterp/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 30377
diff changeset
4527
a61e1a0f6024 maint: style check C++ files in libinterp/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 30377
diff changeset
4528 issparse = args(nargin-1).issparse ();
a61e1a0f6024 maint: style check C++ files in libinterp/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 30377
diff changeset
4529 nargin -= 2;
a61e1a0f6024 maint: style check C++ files in libinterp/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 30377
diff changeset
4530 }
29086
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4531
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4532 switch (nargin)
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4533 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4534 case 0:
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4535 break;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4536
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4537 case 1:
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
4538 get_dimensions (args(0), fcn, dims);
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4539 break;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4540
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4541 default:
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4542 {
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4543 dims.resize (nargin);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4544
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4545 for (int i = 0; i < nargin; i++)
30934
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4546 {
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4547 if (args(i).numel () > 1)
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4548 error ("%s: dimensions must be scalars.", fcn);
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4549
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4550 dims(i) = (args(i).isempty () ? 0 : args(i).idx_type_value (true));
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4551 }
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4552 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4553 break;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4554 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4555
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4556 dims.chop_trailing_singletons ();
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4557
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
4558 check_dimensions (dims, fcn);
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4559
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4560 // 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
4561 // NDArray to scalar.
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4562
29086
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4563 if (issparse)
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4564 {
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4565 if (dims.ndims () > 2)
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4566 error ("%s: sparse ND arrays not supported", fcn);
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4567
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4568 retval = SparseBoolMatrix (dims(0), dims(1), val);
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4569 }
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4570 else
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4571 retval = boolNDArray (dims, val);
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4572
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4573 return retval;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4574 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4575
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3333
diff changeset
4576 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
4577 doc: /* -*- texinfo -*-
29218
8469b3aad7ac ones, zeros, NaN, NA, false, true: Document syntax with "like" (bug #50854).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29163
diff changeset
4578 @deftypefn {} {@var{val} =} ones (@var{n})
8469b3aad7ac ones, zeros, NaN, NA, false, true: Document syntax with "like" (bug #50854).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29163
diff changeset
4579 @deftypefnx {} {@var{val} =} ones (@var{m}, @var{n})
8469b3aad7ac ones, zeros, NaN, NA, false, true: Document syntax with "like" (bug #50854).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29163
diff changeset
4580 @deftypefnx {} {@var{val} =} ones (@var{m}, @var{n}, @var{k}, @dots{})
8469b3aad7ac ones, zeros, NaN, NA, false, true: Document syntax with "like" (bug #50854).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29163
diff changeset
4581 @deftypefnx {} {@var{val} =} ones ([@var{m} @var{n} @dots{}])
31611
535492e34f8f doc: Don't use TexInfo @var{} macro "like" for zeros, ones, etc.
Rik <rik@octave.org>
parents: 31607
diff changeset
4582 @deftypefnx {} {@var{val} =} ones (@dots{}, "like", @var{var})
29218
8469b3aad7ac ones, zeros, NaN, NA, false, true: Document syntax with "like" (bug #50854).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29163
diff changeset
4583 @deftypefnx {} {@var{val} =} ones (@dots{}, @var{class})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4584 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
4585
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4586 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
4587 @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
4588
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4589 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
4590 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
4591
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4592 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
4593 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
4594
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4595 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4596 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
4597 @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
4598
29218
8469b3aad7ac ones, zeros, NaN, NA, false, true: Document syntax with "like" (bug #50854).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29163
diff changeset
4599 If a variable @var{var} is specified after @qcode{"like"}, the output @var{val}
8469b3aad7ac ones, zeros, NaN, NA, false, true: Document syntax with "like" (bug #50854).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29163
diff changeset
4600 will have the same data type, complexity, and sparsity as @var{var}.
8469b3aad7ac ones, zeros, NaN, NA, false, true: Document syntax with "like" (bug #50854).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29163
diff changeset
4601
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4602 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
4603 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
4604
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4605 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4606 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
4607 @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
4608 @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
4609 @end deftypefn */)
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
4610 {
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4611 return fill_matrix (args, 1, "ones");
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
4612 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
4613
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
4614 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4615 %!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
4616 %!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
4617 %!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
4618 %!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
4619
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4620 %!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
4621 %!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
4622 %!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
4623 %!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
4624
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4625 %!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
4626 %!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
4627 %!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
4628 %!assert (size (ones (3, 4, 5, "int8")), [3, 4, 5])
25926
373fe1608f7c Emit an error when utility matrices (zeros, ones, rand, etc.) are given a fractional dimension (bug #54781).
Rik <rik@octave.org>
parents: 25917
diff changeset
4629
29086
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4630 %!assert (ones (2, 2, "like", double (1)), double ([1, 1; 1, 1]))
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4631 %!assert (ones (2, 2, "like", complex (ones (2, 2))), [1, 1; 1, 1])
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4632 %!assert (ones (1, 2, "like", single (1)), single ([1, 1]))
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4633 %!assert (ones (1, "like", single (1i)), single (1))
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4634 %!assert (ones (2, 2, "like", uint8 (8)), uint8 ([1, 1; 1, 1]))
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4635 %!assert (ones (2, "like", speye (2)), sparse ([1, 1; 1, 1]))
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4636 %!assert (ones (2, "like", sparse (1i)), sparse (complex ([1, 1; 1, 1])))
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4637
25926
373fe1608f7c Emit an error when utility matrices (zeros, ones, rand, etc.) are given a fractional dimension (bug #54781).
Rik <rik@octave.org>
parents: 25917
diff changeset
4638 %!assert (size (ones (1, -2, 2)), [1, 0, 2])
25928
a533a7c4d2cc Emit an error when utility matrices (zeros, ones, rand, etc.) are given a fractional dimension in a dimension vector (bug #54781).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25927
diff changeset
4639
a533a7c4d2cc Emit an error when utility matrices (zeros, ones, rand, etc.) are given a fractional dimension in a dimension vector (bug #54781).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25927
diff changeset
4640 ## Test input validation
a533a7c4d2cc Emit an error when utility matrices (zeros, ones, rand, etc.) are given a fractional dimension in a dimension vector (bug #54781).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25927
diff changeset
4641 %!error <conversion of 1.1 .*failed> ones (1.1)
a533a7c4d2cc Emit an error when utility matrices (zeros, ones, rand, etc.) are given a fractional dimension in a dimension vector (bug #54781).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25927
diff changeset
4642 %!error <conversion of 1.1 .*failed> ones (1, 1.1)
a533a7c4d2cc Emit an error when utility matrices (zeros, ones, rand, etc.) are given a fractional dimension in a dimension vector (bug #54781).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25927
diff changeset
4643 %!error <conversion of 1.1 .*failed> ones ([1, 1.1])
29086
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4644 %!error <sparse ND .* not supported> ones (3, 3, 3, "like", speye (1))
30934
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4645 %!error <must be scalar> ones (1:3, 1)
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4646 %!error <must be scalar> ones (1, 1:3)
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4647 %!error <must be scalar> ones (1, 2, 1:3)
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4648 %!error <must be scalar> ones (1:3, 1, "like", single (1))
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4649 */
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
4650
21405
120bb822c6f4 Handle empty vectors for size of ones(), zeros(), inf(), etc... (bug #47298)
Carnë Draug <carandraug@octave.org>
parents: 21317
diff changeset
4651 /*
120bb822c6f4 Handle empty vectors for size of ones(), zeros(), inf(), etc... (bug #47298)
Carnë Draug <carandraug@octave.org>
parents: 21317
diff changeset
4652 ## 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
4653 ## 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
4654 ## n to be a 1x0 vector (returns 0x0) but not a 0x1 vector. Octave supports
31278
076c8f94d7f4 Allow empty input for dimension vector (bug #63181).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31141
diff changeset
4655 ## row and column vectors and therefore must support 0x1, 1x0, and 0x1x1.
076c8f94d7f4 Allow empty input for dimension vector (bug #63181).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31141
diff changeset
4656 ## Also any empty input results in a 0x0 output.
23573
1b4f4ec53b4a use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents: 23572
diff changeset
4657 %!test <*47298>
30896
c9788d7f6e65 maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents: 30892
diff changeset
4658 %! fcns = {@zeros, @ones, @inf, @nan, @NA, @i, @pi, @e};
c9788d7f6e65 maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents: 30892
diff changeset
4659 %! for idx = 1:numel (fcns)
c9788d7f6e65 maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents: 30892
diff changeset
4660 %! fcn = fcns{idx};
c9788d7f6e65 maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents: 30892
diff changeset
4661 %! assert (fcn (zeros (1, 0)), zeros (0, 0));
c9788d7f6e65 maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents: 30892
diff changeset
4662 %! assert (fcn (zeros (0, 1)), zeros (0, 0));
c9788d7f6e65 maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents: 30892
diff changeset
4663 %! assert (fcn (zeros (0, 1, 1)), zeros (0, 0));
31278
076c8f94d7f4 Allow empty input for dimension vector (bug #63181).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31141
diff changeset
4664 %! assert (fcn (zeros ([])), zeros (0, 0));
076c8f94d7f4 Allow empty input for dimension vector (bug #63181).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31141
diff changeset
4665 %! assert (fcn (zeros (0, 0, 1)), zeros (0, 0));
21405
120bb822c6f4 Handle empty vectors for size of ones(), zeros(), inf(), etc... (bug #47298)
Carnë Draug <carandraug@octave.org>
parents: 21317
diff changeset
4666 %! endfor
120bb822c6f4 Handle empty vectors for size of ones(), zeros(), inf(), etc... (bug #47298)
Carnë Draug <carandraug@octave.org>
parents: 21317
diff changeset
4667 */
120bb822c6f4 Handle empty vectors for size of ones(), zeros(), inf(), etc... (bug #47298)
Carnë Draug <carandraug@octave.org>
parents: 21317
diff changeset
4668
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3333
diff changeset
4669 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
4670 doc: /* -*- texinfo -*-
29218
8469b3aad7ac ones, zeros, NaN, NA, false, true: Document syntax with "like" (bug #50854).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29163
diff changeset
4671 @deftypefn {} {@var{val} =} zeros (@var{n})
8469b3aad7ac ones, zeros, NaN, NA, false, true: Document syntax with "like" (bug #50854).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29163
diff changeset
4672 @deftypefnx {} {@var{val} =} zeros (@var{m}, @var{n})
8469b3aad7ac ones, zeros, NaN, NA, false, true: Document syntax with "like" (bug #50854).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29163
diff changeset
4673 @deftypefnx {} {@var{val} =} zeros (@var{m}, @var{n}, @var{k}, @dots{})
8469b3aad7ac ones, zeros, NaN, NA, false, true: Document syntax with "like" (bug #50854).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29163
diff changeset
4674 @deftypefnx {} {@var{val} =} zeros ([@var{m} @var{n} @dots{}])
31611
535492e34f8f doc: Don't use TexInfo @var{} macro "like" for zeros, ones, etc.
Rik <rik@octave.org>
parents: 31607
diff changeset
4675 @deftypefnx {} {@var{val} =} zeros (@dots{}, "like", @var{var})
29218
8469b3aad7ac ones, zeros, NaN, NA, false, true: Document syntax with "like" (bug #50854).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29163
diff changeset
4676 @deftypefnx {} {@var{val} =} zeros (@dots{}, @var{class})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4677 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
4678
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4679 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
4680 @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
4681
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4682 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
4683 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
4684
29218
8469b3aad7ac ones, zeros, NaN, NA, false, true: Document syntax with "like" (bug #50854).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29163
diff changeset
4685 If a variable @var{var} is specified after @qcode{"like"}, the output @var{val}
8469b3aad7ac ones, zeros, NaN, NA, false, true: Document syntax with "like" (bug #50854).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29163
diff changeset
4686 will have the same data type, complexity, and sparsity as @var{var}.
8469b3aad7ac ones, zeros, NaN, NA, false, true: Document syntax with "like" (bug #50854).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29163
diff changeset
4687
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4688 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
4689 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
4690
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4691 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4692 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
4693 @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
4694 @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
4695 @end deftypefn */)
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
4696 {
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4697 return fill_matrix (args, 0, "zeros");
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4698 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4699
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
4700 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4701 %!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
4702 %!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
4703 %!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
4704 %!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
4705
29086
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4706 %!assert (zeros (2, 2, "like", double (1)), double ([0, 0; 0, 0]))
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4707 %!assert (zeros (2, 2, "like", complex (ones (2, 2))), [0, 0; 0, 0])
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4708 %!assert (zeros (1, 2, "like", single (1)), single ([0, 0]))
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4709 %!assert (zeros (1, 2, "like", single (1i)), single ([0, 0]))
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4710 %!assert (zeros (2, 2, "like", uint8 (8)), uint8 ([0, 0; 0, 0]))
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4711 %!assert (zeros (2, "like", speye (2)), sparse ([0, 0; 0, 0]))
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4712
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4713 %!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
4714 %!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
4715 %!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
4716 %!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
4717
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4718 %!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
4719 %!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
4720 %!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
4721 %!assert (size (zeros (3, 4, 5, "int8")), [3, 4, 5])
25928
a533a7c4d2cc Emit an error when utility matrices (zeros, ones, rand, etc.) are given a fractional dimension in a dimension vector (bug #54781).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25927
diff changeset
4722
a533a7c4d2cc Emit an error when utility matrices (zeros, ones, rand, etc.) are given a fractional dimension in a dimension vector (bug #54781).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25927
diff changeset
4723 ## Test input validation
a533a7c4d2cc Emit an error when utility matrices (zeros, ones, rand, etc.) are given a fractional dimension in a dimension vector (bug #54781).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25927
diff changeset
4724 %!error <invalid data type specified> zeros (1, 1, "foobar")
a533a7c4d2cc Emit an error when utility matrices (zeros, ones, rand, etc.) are given a fractional dimension in a dimension vector (bug #54781).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25927
diff changeset
4725 %!error <conversion of 1.1 .*failed> zeros (1.1)
a533a7c4d2cc Emit an error when utility matrices (zeros, ones, rand, etc.) are given a fractional dimension in a dimension vector (bug #54781).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25927
diff changeset
4726 %!error <conversion of 1.1 .*failed> zeros (1, 1.1)
a533a7c4d2cc Emit an error when utility matrices (zeros, ones, rand, etc.) are given a fractional dimension in a dimension vector (bug #54781).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25927
diff changeset
4727 %!error <conversion of 1.1 .*failed> zeros ([1, 1.1])
a533a7c4d2cc Emit an error when utility matrices (zeros, ones, rand, etc.) are given a fractional dimension in a dimension vector (bug #54781).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25927
diff changeset
4728 %!error <conversion of 1.1 .*failed> zeros (1, 1.1, 2)
a533a7c4d2cc Emit an error when utility matrices (zeros, ones, rand, etc.) are given a fractional dimension in a dimension vector (bug #54781).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25927
diff changeset
4729 %!error <conversion of 1.1 .*failed> zeros ([1, 1.1, 2])
29086
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4730 %!error <sparse ND .* not supported> zeros (3, 3, 3, "like", speye (1))
30934
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4731 %!error <must be scalar> zeros (1:3, 1)
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4732 %!error <must be scalar> zeros (1, 1:3)
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4733 %!error <must be scalar> zeros (1, 2, 1:3)
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4734 %!error <must be scalar> zeros (1:3, 1, "like", single (1))
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4735 */
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
4736
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4737 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
4738 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
4739 @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
4740 @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
4741
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
4742 @deftypefn {} {@var{A} =} Inf
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
4743 @deftypefnx {} {@var{A} =} Inf (@var{n})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
4744 @deftypefnx {} {@var{A} =} Inf (@var{n}, @var{m})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
4745 @deftypefnx {} {@var{A} =} Inf (@var{n}, @var{m}, @var{k}, @dots{})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
4746 @deftypefnx {} {@var{A} =} Inf (@dots{}, @var{class})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4747 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
4748 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
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 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
4751 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
4752 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
4753
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4754 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4755 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4756 [ 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
4757 @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
4758 @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
4759 @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
4760
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4761 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
4762
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4763 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
4764 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
4765
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4766 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
4767 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
4768 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
4769
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4770 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
4771 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
4772 @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
4773 @end deftypefn */)
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4774 {
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
4775 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
4776 lo_ieee_float_inf_value (), "Inf");
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4777 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4778
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4779 DEFALIAS (inf, Inf);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4780
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
4781 /*
29086
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4782 %!assert (Inf (3), [Inf, Inf, Inf; Inf, Inf, Inf; Inf, Inf, Inf])
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4783 %!assert (Inf (2, 3), [Inf, Inf, Inf; Inf, Inf, Inf])
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4784 %!assert (Inf (3, 2), [Inf, Inf; Inf, Inf; Inf, Inf])
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4785 %!assert (size (Inf (3, 4, 5)), [3, 4, 5])
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4786
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
4787 %!assert (Inf (3, "single"),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
4788 %! single ([Inf, Inf, Inf; Inf, Inf, Inf; Inf, Inf, Inf]))
29086
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4789 %!assert (Inf (2, 3, "single"), single ([Inf, Inf, Inf; Inf, Inf, Inf]))
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4790 %!assert (Inf (3, 2, "single"), single ([Inf, Inf; Inf, Inf; Inf, Inf]))
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4791 %!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
4792
29086
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4793 %!assert (Inf (2, 2, "like", speye (2)), sparse ([Inf, Inf; Inf, Inf]))
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4794 %!assert (Inf (2, 2, "like", complex (ones (2, 2))), [Inf, Inf; Inf, Inf])
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4795 %!assert (Inf (2, 2, "like", double (1)), double ([Inf, Inf; Inf, Inf]))
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
4796 %!assert (Inf (3, 3, "like", single (1)),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
4797 %! single ([Inf, Inf, Inf; Inf, Inf, Inf; Inf, Inf, Inf]))
29086
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4798 %!assert (Inf (2, "like", single (1i)), single ([Inf, Inf; Inf, Inf]))
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4799
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4800 %!error Inf (3, "like", int8 (1))
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4801
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4802 %!error Inf (3, "int8")
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4803 %!error Inf (2, 3, "int8")
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4804 %!error Inf (3, 2, "int8")
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4805 %!error Inf (3, 4, 5, "int8")
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4806 %!error <input .* floating> Inf (3, 3, "like", true)
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4807 %!error <input .* floating> Inf (2, "like", uint8 (1))
30934
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4808 %!error <must be scalar> Inf (1:3, 1)
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4809 %!error <must be scalar> Inf (1, 1:3)
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4810 %!error <must be scalar> Inf (1, 2, 1:3)
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4811 %!error <must be scalar> Inf (1:3, 1, "like", single (1))
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4812 */
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
4813
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4814 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
4815 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
4816 @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
4817 @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
4818
29218
8469b3aad7ac ones, zeros, NaN, NA, false, true: Document syntax with "like" (bug #50854).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29163
diff changeset
4819 @deftypefn {} {@var{val} =} NaN
8469b3aad7ac ones, zeros, NaN, NA, false, true: Document syntax with "like" (bug #50854).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29163
diff changeset
4820 @deftypefnx {} {@var{val} =} NaN (@var{n})
8469b3aad7ac ones, zeros, NaN, NA, false, true: Document syntax with "like" (bug #50854).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29163
diff changeset
4821 @deftypefnx {} {@var{val} =} NaN (@var{n}, @var{m})
8469b3aad7ac ones, zeros, NaN, NA, false, true: Document syntax with "like" (bug #50854).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29163
diff changeset
4822 @deftypefnx {} {@var{val} =} NaN (@var{n}, @var{m}, @var{k}, @dots{})
31611
535492e34f8f doc: Don't use TexInfo @var{} macro "like" for zeros, ones, etc.
Rik <rik@octave.org>
parents: 31607
diff changeset
4823 @deftypefnx {} {@var{val} =} NaN (@dots{}, "like", @var{var})
29218
8469b3aad7ac ones, zeros, NaN, NA, false, true: Document syntax with "like" (bug #50854).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29163
diff changeset
4824 @deftypefnx {} {@var{val} =} NaN (@dots{}, @var{class})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4825 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
4826 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
4827
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4828 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
4829 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
4830 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
4831 @tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4832 ($\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
4833 @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
4834 @ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4835 (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
4836 @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
4837 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
4838
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4839 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
4840 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
4841 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
4842
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4843 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
4844
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4845 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
4846 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
4847
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4848 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
4849 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
4850 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
4851
29218
8469b3aad7ac ones, zeros, NaN, NA, false, true: Document syntax with "like" (bug #50854).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29163
diff changeset
4852 If a variable @var{var} is specified after @qcode{"like"}, the output @var{val}
8469b3aad7ac ones, zeros, NaN, NA, false, true: Document syntax with "like" (bug #50854).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29163
diff changeset
4853 will have the same data type, complexity, and sparsity as @var{var}.
8469b3aad7ac ones, zeros, NaN, NA, false, true: Document syntax with "like" (bug #50854).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29163
diff changeset
4854
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4855 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
4856 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
4857 @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
4858 @end deftypefn */)
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4859 {
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
4860 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
4861 lo_ieee_float_nan_value (), "NaN");
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4862 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4863
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4864 DEFALIAS (nan, NaN);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4865
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
4866 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4867 %!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
4868 %!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
4869 %!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
4870 %!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
4871
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
4872 %!assert (NaN (3, "single"),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
4873 %! single ([NaN, NaN, NaN; NaN, NaN, NaN; NaN, NaN, NaN]))
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4874 %!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
4875 %!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
4876 %!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
4877
29086
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4878 %!assert (NaN (2, 2, "like", double (1)), double ([NaN, NaN; NaN, NaN]))
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4879 %!assert (NaN (2, 2, "like", complex (ones(2, 2))), [NaN, NaN; NaN, NaN])
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
4880 %!assert (NaN (3, 3, "like", single (1)),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
4881 %! single ([NaN, NaN, NaN; NaN, NaN, NaN; NaN, NaN, NaN]))
29086
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4882 %!assert (NaN (2, "like", single (1i)), single ([NaN, NaN; NaN, NaN]))
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4883 %!assert (NaN (2, 2, "like", speye (2)), sparse ([NaN, NaN; NaN, NaN]))
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4884
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4885 %!error NaN (3, 'like', int8 (1))
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4886
28930
2883b3d08b7e maint: Remove unnecessary parentheses bracketing %!error BIST tests.
Rik <rik@octave.org>
parents: 28919
diff changeset
4887 %!error NaN (3, "int8")
2883b3d08b7e maint: Remove unnecessary parentheses bracketing %!error BIST tests.
Rik <rik@octave.org>
parents: 28919
diff changeset
4888 %!error NaN (2, 3, "int8")
2883b3d08b7e maint: Remove unnecessary parentheses bracketing %!error BIST tests.
Rik <rik@octave.org>
parents: 28919
diff changeset
4889 %!error NaN (3, 2, "int8")
2883b3d08b7e maint: Remove unnecessary parentheses bracketing %!error BIST tests.
Rik <rik@octave.org>
parents: 28919
diff changeset
4890 %!error NaN (3, 4, 5, "int8")
29086
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4891 %!error <input .* floating> NaN (3, 3, "like", true)
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4892 %!error <input .* floating> NaN (2, "like", uint8 (1))
30934
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4893 %!error <must be scalar> NaN (1:3, 1)
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4894 %!error <must be scalar> NaN (1, 1:3)
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4895 %!error <must be scalar> NaN (1, 2, 1:3)
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4896 %!error <must be scalar> NaN (1:3, 1, "like", single (1))
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4897 */
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
4898
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4899 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
4900 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
4901 @deftypefn {} {@var{A} =} e
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
4902 @deftypefnx {} {@var{A} =} e (@var{n})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
4903 @deftypefnx {} {@var{A} =} e (@var{n}, @var{m})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
4904 @deftypefnx {} {@var{A} =} e (@var{n}, @var{m}, @var{k}, @dots{})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
4905 @deftypefnx {} {@var{A} =} e (@dots{}, @var{class})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4906 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
4907 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
4908
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4909 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
4910 @tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4911 $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
4912 @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
4913 @ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4914 @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
4915 @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
4916
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4917 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
4918
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
4919 When called with a single argument, return a square matrix with the dimension
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
4920 specified.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4921
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4922 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
4923 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
4924 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
4925
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
4926 The optional argument @var{class} specifies the return type and may be either
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
4927 @qcode{"double"} or @qcode{"single"}.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4928 @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
4929 @end deftypefn */)
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4930 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4931 #if defined (M_E)
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4932 double e_val = M_E;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4933 #else
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4934 double e_val = exp (1.0);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4935 #endif
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4936
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4937 return fill_matrix (args, e_val, "e");
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4938 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4939
24295
48e7efceb427 libinterp/corefcn/data.cc: template eps() to reduce code duplication
Carnë Draug <carandraug@octave.org>
parents: 24219
diff changeset
4940 template <typename T>
48e7efceb427 libinterp/corefcn/data.cc: template eps() to reduce code duplication
Carnë Draug <carandraug@octave.org>
parents: 24219
diff changeset
4941 T
48e7efceb427 libinterp/corefcn/data.cc: template eps() to reduce code duplication
Carnë Draug <carandraug@octave.org>
parents: 24219
diff changeset
4942 eps (const T& x)
48e7efceb427 libinterp/corefcn/data.cc: template eps() to reduce code duplication
Carnë Draug <carandraug@octave.org>
parents: 24219
diff changeset
4943 {
48e7efceb427 libinterp/corefcn/data.cc: template eps() to reduce code duplication
Carnë Draug <carandraug@octave.org>
parents: 24219
diff changeset
4944 T epsval = x.abs ();
48e7efceb427 libinterp/corefcn/data.cc: template eps() to reduce code duplication
Carnë Draug <carandraug@octave.org>
parents: 24219
diff changeset
4945 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
4946 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
4947 {
48e7efceb427 libinterp/corefcn/data.cc: template eps() to reduce code duplication
Carnë Draug <carandraug@octave.org>
parents: 24219
diff changeset
4948 P val = epsval.xelem (i);
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
4949 if (math::isnan (val) || math::isinf (val))
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
4950 epsval(i) = numeric_limits<P>::NaN ();
24295
48e7efceb427 libinterp/corefcn/data.cc: template eps() to reduce code duplication
Carnë Draug <carandraug@octave.org>
parents: 24219
diff changeset
4951 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
4952 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
4953 else
48e7efceb427 libinterp/corefcn/data.cc: template eps() to reduce code duplication
Carnë Draug <carandraug@octave.org>
parents: 24219
diff changeset
4954 {
48e7efceb427 libinterp/corefcn/data.cc: template eps() to reduce code duplication
Carnë Draug <carandraug@octave.org>
parents: 24219
diff changeset
4955 int exponent;
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
4956 math::frexp (val, &exponent);
24295
48e7efceb427 libinterp/corefcn/data.cc: template eps() to reduce code duplication
Carnë Draug <carandraug@octave.org>
parents: 24219
diff changeset
4957 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
4958 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
4959 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
4960 }
48e7efceb427 libinterp/corefcn/data.cc: template eps() to reduce code duplication
Carnë Draug <carandraug@octave.org>
parents: 24219
diff changeset
4961 }
48e7efceb427 libinterp/corefcn/data.cc: template eps() to reduce code duplication
Carnë Draug <carandraug@octave.org>
parents: 24219
diff changeset
4962 return epsval;
48e7efceb427 libinterp/corefcn/data.cc: template eps() to reduce code duplication
Carnë Draug <carandraug@octave.org>
parents: 24219
diff changeset
4963 }
48e7efceb427 libinterp/corefcn/data.cc: template eps() to reduce code duplication
Carnë Draug <carandraug@octave.org>
parents: 24219
diff changeset
4964
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4965 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
4966 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
4967 @deftypefn {} {@var{d} =} eps
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
4968 @deftypefnx {} {@var{d} =} eps (@var{x})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
4969 @deftypefnx {} {@var{d} =} eps (@var{n}, @var{m})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
4970 @deftypefnx {} {@var{d} =} eps (@var{n}, @var{m}, @var{k}, @dots{})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
4971 @deftypefnx {} {@var{d} =} eps (@dots{}, @var{class})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4972 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
4973 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
4974
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4975 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
4976 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
4977 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
4978 @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
4979 @tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4980 $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
4981 @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
4982 @ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4983 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
4984 @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
4985 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
4986
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4987 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
4988 @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
4989
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4990 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
4991 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
4992
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4993 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
4994 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
4995 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
4996 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
4997 @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
4998 @end deftypefn */)
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4999 {
7795
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
5000 octave_value retval;
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
5001
20819
f428cbe7576f eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents: 20816
diff changeset
5002 if (args.length () == 1 && ! args(0).is_string ())
7795
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
5003 {
24295
48e7efceb427 libinterp/corefcn/data.cc: template eps() to reduce code duplication
Carnë Draug <carandraug@octave.org>
parents: 24219
diff changeset
5004 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
5005 if (arg0.is_single_type ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5006 {
24295
48e7efceb427 libinterp/corefcn/data.cc: template eps() to reduce code duplication
Carnë Draug <carandraug@octave.org>
parents: 24219
diff changeset
5007 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
5008 retval = epsval;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5009 }
24296
3981e3a11150 eps: error if input is not of floating point type
Carnë Draug <carandraug@octave.org>
parents: 24295
diff changeset
5010 else if (arg0.is_double_type ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5011 {
24295
48e7efceb427 libinterp/corefcn/data.cc: template eps() to reduce code duplication
Carnë Draug <carandraug@octave.org>
parents: 24219
diff changeset
5012 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
5013 retval = epsval;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5014 }
7795
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
5015 else
24296
3981e3a11150 eps: error if input is not of floating point type
Carnë Draug <carandraug@octave.org>
parents: 24295
diff changeset
5016 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
5017 }
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
5018 else
15213
336f42406671 use numeric_limits functions instead of DBL_MIN, DBL_MAX, etc.
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
5019 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
5020 std::numeric_limits<float>::epsilon (), "eps");
7795
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
5021
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
5022 return retval;
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5023 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5024
7795
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
5025 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5026 %!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
5027 %!assert (eps (1), 2^(-52))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5028 %!assert (eps (2), 2^(-51))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5029 %!assert (eps (realmax), 2^971)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5030 %!assert (eps (0), 2^(-1074))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5031 %!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
5032 %!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
5033 %!assert (eps (Inf), NaN)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5034 %!assert (eps (NaN), NaN)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
5035 %!assert (eps ([1/2 1 2 realmax 0 realmin/2 realmin/16 Inf NaN]),
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
5036 %! [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
5037 %!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
5038 %!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
5039 %!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
5040 %!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
5041 %!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
5042 %!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
5043 %!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
5044 %!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
5045 %!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
5046 %!assert (eps (single ([1/2 1 2 realmax("single") 0 realmin("single")/2 realmin("single")/16 Inf NaN])),
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
5047 %! 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
5048 %!error <X must be of a floating point type> eps (uint8 ([0 1 2]))
30934
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
5049 %!error <must be scalar> eps (1:3, 1)
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
5050 %!error <must be scalar> eps (1, 1:3)
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
5051 %!error <must be scalar> eps (1, 2, 1:3)
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
5052 %!error <must be scalar> eps (1:3, 1, "single")
7795
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
5053 */
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
5054
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5055 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
5056 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5057 @deftypefn {} {@var{p} =} pi
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5058 @deftypefnx {} {@var{p} =} pi (@var{n})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5059 @deftypefnx {} {@var{p} =} pi (@var{n}, @var{m})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5060 @deftypefnx {} {@var{p} =} pi (@var{n}, @var{m}, @var{k}, @dots{})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5061 @deftypefnx {} {@var{p} =} pi (@dots{}, @var{class})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5062 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
5063 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
5064 @tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5065 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
5066 @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
5067 @ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5068 diameter.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5069 @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
5070
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5071 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
5072 @tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5073 $\pi$.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5074 @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
5075 @ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5076 pi.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5077 @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
5078
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5079 When called with a single argument, return a square matrix with the dimension
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5080 specified.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5081
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5082 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
5083 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
5084 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
5085
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5086 The optional argument @var{class} specifies the return type and may be either
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5087 @qcode{"double"} or @qcode{"single"}.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5088 @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
5089 @end deftypefn */)
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5090 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5091 #if defined (M_PI)
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5092 double pi_val = M_PI;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5093 #else
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5094 double pi_val = 4.0 * atan (1.0);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5095 #endif
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5096
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5097 return fill_matrix (args, pi_val, "pi");
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5098 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5099
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5100 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
5101 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5102 @deftypefn {} {@var{Rmax} =} realmax
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5103 @deftypefnx {} {@var{Rmax} =} realmax (@var{n})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5104 @deftypefnx {} {@var{Rmax} =} realmax (@var{n}, @var{m})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5105 @deftypefnx {} {@var{Rmax} =} realmax (@var{n}, @var{m}, @var{k}, @dots{})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5106 @deftypefnx {} {@var{Rmax} =} realmax (@dots{}, @var{class})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5107 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
5108 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
5109
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5110 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
5111 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
5112 @tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5113 $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
5114 @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
5115 @ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5116 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
5117 @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
5118 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
5119
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5120 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
5121 @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
5122
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5123 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
5124 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
5125
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5126 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
5127 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
5128 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
5129
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5130 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
5131 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
5132 @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
5133 @end deftypefn */)
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5134 {
15213
336f42406671 use numeric_limits functions instead of DBL_MIN, DBL_MAX, etc.
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
5135 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
5136 std::numeric_limits<float>::max (), "realmax");
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5137 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5138
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5139 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
5140 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5141 @deftypefn {} {@var{Rmin} =} realmin
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5142 @deftypefnx {} {@var{Rmin} =} realmin (@var{n})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5143 @deftypefnx {} {@var{Rmin} =} realmin (@var{n}, @var{m})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5144 @deftypefnx {} {@var{Rmin} =} realmin (@var{n}, @var{m}, @var{k}, @dots{})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5145 @deftypefnx {} {@var{Rmin} =} realmin (@dots{}, @var{class})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5146 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
5147 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
5148
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5149 The actual value is system dependent. On machines that support IEEE floating
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5150 point arithmetic, @code{realmin} is approximately
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5151 @tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5152 $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
5153 @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
5154 @ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5155 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
5156 @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
5157 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
5158
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5159 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
5160 @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
5161
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5162 When called with a single argument, return a square matrix with the dimension
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5163 specified.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5164
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5165 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
5166 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
5167 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
5168
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5169 The optional argument @var{class} specifies the return type and may be either
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5170 @qcode{"double"} or @qcode{"single"}.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5171 @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
5172 @end deftypefn */)
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5173 {
15213
336f42406671 use numeric_limits functions instead of DBL_MIN, DBL_MAX, etc.
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
5174 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
5175 std::numeric_limits<float>::min (), "realmin");
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5176 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5177
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5178 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
5179 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
5180 @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
5181 @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
5182 @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
5183 @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
5184
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5185 @deftypefn {} {@var{A} =} I
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5186 @deftypefnx {} {@var{A} =} I (@var{n})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5187 @deftypefnx {} {@var{A} =} I (@var{n}, @var{m})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5188 @deftypefnx {} {@var{A} =} I (@var{n}, @var{m}, @var{k}, @dots{})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5189 @deftypefnx {} {@var{A} =} I (@dots{}, @var{class})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5190 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
5191 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
5192 @tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5193 $\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
5194 @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
5195 @ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5196 @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
5197 @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
5198
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5199 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
5200 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
5201
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5202 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
5203
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5204 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
5205 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
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 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
5208 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
5209 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
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 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
5212 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
5213 @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
5214 @end deftypefn */)
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5215 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5216 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
5217 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5218
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5219 DEFALIAS (i, I);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5220 DEFALIAS (J, I);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5221 DEFALIAS (j, I);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5222
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5223 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
5224 doc: /* -*- texinfo -*-
29218
8469b3aad7ac ones, zeros, NaN, NA, false, true: Document syntax with "like" (bug #50854).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29163
diff changeset
5225 @deftypefn {} {@var{val} =} NA
8469b3aad7ac ones, zeros, NaN, NA, false, true: Document syntax with "like" (bug #50854).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29163
diff changeset
5226 @deftypefnx {} {@var{val} =} NA (@var{n})
8469b3aad7ac ones, zeros, NaN, NA, false, true: Document syntax with "like" (bug #50854).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29163
diff changeset
5227 @deftypefnx {} {@var{val} =} NA (@var{n}, @var{m})
8469b3aad7ac ones, zeros, NaN, NA, false, true: Document syntax with "like" (bug #50854).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29163
diff changeset
5228 @deftypefnx {} {@var{val} =} NA (@var{n}, @var{m}, @var{k}, @dots{})
31611
535492e34f8f doc: Don't use TexInfo @var{} macro "like" for zeros, ones, etc.
Rik <rik@octave.org>
parents: 31607
diff changeset
5229 @deftypefnx {} {@var{val} =} NA (@dots{}, "like", @var{var})
29218
8469b3aad7ac ones, zeros, NaN, NA, false, true: Document syntax with "like" (bug #50854).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29163
diff changeset
5230 @deftypefnx {} {@var{val} =} NA (@dots{}, @var{class})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5231 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
5232 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
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 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
5235 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
5236
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5237 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
5238
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5239 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
5240 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
5241
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5242 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
5243 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
5244 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
5245
29218
8469b3aad7ac ones, zeros, NaN, NA, false, true: Document syntax with "like" (bug #50854).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29163
diff changeset
5246 If a variable @var{var} is specified after @qcode{"like"}, the output @var{val}
8469b3aad7ac ones, zeros, NaN, NA, false, true: Document syntax with "like" (bug #50854).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29163
diff changeset
5247 will have the same data type, complexity, and sparsity as @var{var}.
8469b3aad7ac ones, zeros, NaN, NA, false, true: Document syntax with "like" (bug #50854).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29163
diff changeset
5248
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5249 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
5250 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
5251 @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
5252 @end deftypefn */)
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5253 {
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
5254 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
5255 lo_ieee_float_na_value (), "NA");
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5256 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5257
7991
139f47cf17ab Change NA value to support single to double precision conversion
David Bateman <dbateman@free.fr>
parents: 7919
diff changeset
5258 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5259 %!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
5260 %!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
5261 */
7991
139f47cf17ab Change NA value to support single to double precision conversion
David Bateman <dbateman@free.fr>
parents: 7919
diff changeset
5262
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5263 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
5264 doc: /* -*- texinfo -*-
29218
8469b3aad7ac ones, zeros, NaN, NA, false, true: Document syntax with "like" (bug #50854).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29163
diff changeset
5265 @deftypefn {} {@var{val} =} false (@var{x})
8469b3aad7ac ones, zeros, NaN, NA, false, true: Document syntax with "like" (bug #50854).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29163
diff changeset
5266 @deftypefnx {} {@var{val} =} false (@var{n}, @var{m})
8469b3aad7ac ones, zeros, NaN, NA, false, true: Document syntax with "like" (bug #50854).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29163
diff changeset
5267 @deftypefnx {} {@var{val} =} false (@var{n}, @var{m}, @var{k}, @dots{})
31611
535492e34f8f doc: Don't use TexInfo @var{} macro "like" for zeros, ones, etc.
Rik <rik@octave.org>
parents: 31607
diff changeset
5268 @deftypefnx {} {@var{val} =} false (@dots{}, "like", @var{var})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5269 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
5270
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5271 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
5272 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
5273
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5274 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
5275 values, return an array with given dimensions.
29218
8469b3aad7ac ones, zeros, NaN, NA, false, true: Document syntax with "like" (bug #50854).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29163
diff changeset
5276
8469b3aad7ac ones, zeros, NaN, NA, false, true: Document syntax with "like" (bug #50854).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29163
diff changeset
5277 If a logical variable @var{var} is specified after @qcode{"like"}, the output
8469b3aad7ac ones, zeros, NaN, NA, false, true: Document syntax with "like" (bug #50854).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29163
diff changeset
5278 @var{val} will have the same sparsity as @var{var}.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5279 @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
5280 @end deftypefn */)
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5281 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5282 return fill_matrix (args, false, "false");
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5283 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5284
28115
de2c73ae450f allow data type argument for true and false functions
John W. Eaton <jwe@octave.org>
parents: 28043
diff changeset
5285 /*
de2c73ae450f allow data type argument for true and false functions
John W. Eaton <jwe@octave.org>
parents: 28043
diff changeset
5286 %!assert (false (2, 3), logical (zeros (2, 3)))
de2c73ae450f allow data type argument for true and false functions
John W. Eaton <jwe@octave.org>
parents: 28043
diff changeset
5287 %!assert (false (2, 3, "logical"), logical (zeros (2, 3)))
29086
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
5288 %!assert (false (2, 1, "like", true), [false; false])
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
5289 %!assert (false (2, 1, "like", sparse (true)), sparse ([false; false]))
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
5290
28115
de2c73ae450f allow data type argument for true and false functions
John W. Eaton <jwe@octave.org>
parents: 28043
diff changeset
5291 %!error false (2, 3, "double")
29086
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
5292 %!error <input .* logical> false (2, 1, "like", sparse (1))
30934
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
5293 %!error <must be scalar> false (1:3, 1)
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
5294 %!error <must be scalar> false (1, 1:3)
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
5295 %!error <must be scalar> false (1, 2, 1:3)
28115
de2c73ae450f allow data type argument for true and false functions
John W. Eaton <jwe@octave.org>
parents: 28043
diff changeset
5296 */
de2c73ae450f allow data type argument for true and false functions
John W. Eaton <jwe@octave.org>
parents: 28043
diff changeset
5297
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5298 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
5299 doc: /* -*- texinfo -*-
29218
8469b3aad7ac ones, zeros, NaN, NA, false, true: Document syntax with "like" (bug #50854).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29163
diff changeset
5300 @deftypefn {} {@var{val} =} true (@var{x})
8469b3aad7ac ones, zeros, NaN, NA, false, true: Document syntax with "like" (bug #50854).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29163
diff changeset
5301 @deftypefnx {} {@var{val} =} true (@var{n}, @var{m})
8469b3aad7ac ones, zeros, NaN, NA, false, true: Document syntax with "like" (bug #50854).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29163
diff changeset
5302 @deftypefnx {} {@var{val} =} true (@var{n}, @var{m}, @var{k}, @dots{})
31611
535492e34f8f doc: Don't use TexInfo @var{} macro "like" for zeros, ones, etc.
Rik <rik@octave.org>
parents: 31607
diff changeset
5303 @deftypefnx {} {@var{val} =} true (@dots{}, "like", @var{var})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5304 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
5305
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5306 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
5307 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
5308
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5309 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
5310 values, return an array with given dimensions.
29218
8469b3aad7ac ones, zeros, NaN, NA, false, true: Document syntax with "like" (bug #50854).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29163
diff changeset
5311
8469b3aad7ac ones, zeros, NaN, NA, false, true: Document syntax with "like" (bug #50854).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29163
diff changeset
5312 If a logical variable @var{var} is specified after @qcode{"like"}, the output
8469b3aad7ac ones, zeros, NaN, NA, false, true: Document syntax with "like" (bug #50854).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29163
diff changeset
5313 @var{val} will have the same sparsity as @var{var}.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5314 @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
5315 @end deftypefn */)
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5316 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5317 return fill_matrix (args, true, "true");
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3333
diff changeset
5318 }
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
5319
28115
de2c73ae450f allow data type argument for true and false functions
John W. Eaton <jwe@octave.org>
parents: 28043
diff changeset
5320 /*
de2c73ae450f allow data type argument for true and false functions
John W. Eaton <jwe@octave.org>
parents: 28043
diff changeset
5321 %!assert (true (2, 3), logical (ones (2, 3)))
de2c73ae450f allow data type argument for true and false functions
John W. Eaton <jwe@octave.org>
parents: 28043
diff changeset
5322 %!assert (true (2, 3, "logical"), logical (ones (2, 3)))
29086
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
5323 %!assert (true (2, 1, "like", false), [true; true])
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
5324 %!assert (true (2, 1, "like", sparse (true)), sparse ([true; true]))
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
5325
28115
de2c73ae450f allow data type argument for true and false functions
John W. Eaton <jwe@octave.org>
parents: 28043
diff changeset
5326 %!error true (2, 3, "double")
29086
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
5327 %!error <input .* logical> true (2, 1, "like", double (1))
30934
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
5328 %!error <must be scalar> true (1:3, 1)
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
5329 %!error <must be scalar> true (1, 1:3)
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
5330 %!error <must be scalar> true (1, 2, 1:3)
28115
de2c73ae450f allow data type argument for true and false functions
John W. Eaton <jwe@octave.org>
parents: 28043
diff changeset
5331 */
de2c73ae450f allow data type argument for true and false functions
John W. Eaton <jwe@octave.org>
parents: 28043
diff changeset
5332
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
5333 template <typename MT>
4946
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5334 octave_value
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5335 identity_matrix (int nr, int nc)
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5336 {
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5337 octave_value retval;
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5338
9685
e793865ede63 implement builtin_type
Jaroslav Hajek <highegg@gmail.com>
parents: 9658
diff changeset
5339 typename MT::element_type one (1);
4946
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5340
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5341 if (nr == 1 && nc == 1)
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5342 retval = one;
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5343 else
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5344 {
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5345 dim_vector dims (nr, nc);
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5346
9685
e793865ede63 implement builtin_type
Jaroslav Hajek <highegg@gmail.com>
parents: 9658
diff changeset
5347 typename MT::element_type zero (0);
4946
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5348
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5349 MT m (dims, zero);
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5350
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5351 if (nr > 0 && nc > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5352 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5353 int n = std::min (nr, nc);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5354
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5355 for (int i = 0; i < n; i++)
30390
a61e1a0f6024 maint: style check C++ files in libinterp/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 30377
diff changeset
5356 m(i, i) = one;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5357 }
4946
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5358
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5359 retval = m;
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5360 }
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5361
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5362 return retval;
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5363 }
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5364
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
5365 #define INSTANTIATE_EYE(T) \
5058
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
5366 template octave_value identity_matrix<T> (int, int)
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
5367
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
5368 INSTANTIATE_EYE (int8NDArray);
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
5369 INSTANTIATE_EYE (uint8NDArray);
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
5370 INSTANTIATE_EYE (int16NDArray);
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
5371 INSTANTIATE_EYE (uint16NDArray);
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
5372 INSTANTIATE_EYE (int32NDArray);
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
5373 INSTANTIATE_EYE (uint32NDArray);
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
5374 INSTANTIATE_EYE (int64NDArray);
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
5375 INSTANTIATE_EYE (uint64NDArray);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7743
diff changeset
5376 INSTANTIATE_EYE (FloatNDArray);
5058
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
5377 INSTANTIATE_EYE (NDArray);
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
5378 INSTANTIATE_EYE (boolNDArray);
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
5379
4945
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
5380 static octave_value
4948
7124436476cb [project @ 2004-08-31 17:57:21 by jwe]
jwe
parents: 4947
diff changeset
5381 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
5382 {
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
5383 octave_value retval;
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
5384
25926
373fe1608f7c Emit an error when utility matrices (zeros, ones, rand, etc.) are given a fractional dimension (bug #54781).
Rik <rik@octave.org>
parents: 25917
diff changeset
5385 // FIXME: Perhaps this should be made extensible by using the class name
373fe1608f7c Emit an error when utility matrices (zeros, ones, rand, etc.) are given a fractional dimension (bug #54781).
Rik <rik@octave.org>
parents: 25917
diff changeset
5386 // to lookup a function to call to create the new value.
4946
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5387
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5388 switch (dt)
4946
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5389 {
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5390 case oct_data_conv::dt_int8:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5391 retval = identity_matrix<int8NDArray> (nr, nc);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5392 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5393
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5394 case oct_data_conv::dt_uint8:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5395 retval = identity_matrix<uint8NDArray> (nr, nc);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5396 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5397
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5398 case oct_data_conv::dt_int16:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5399 retval = identity_matrix<int16NDArray> (nr, nc);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5400 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5401
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5402 case oct_data_conv::dt_uint16:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5403 retval = identity_matrix<uint16NDArray> (nr, nc);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5404 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5405
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5406 case oct_data_conv::dt_int32:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5407 retval = identity_matrix<int32NDArray> (nr, nc);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5408 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5409
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5410 case oct_data_conv::dt_uint32:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5411 retval = identity_matrix<uint32NDArray> (nr, nc);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5412 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5413
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5414 case oct_data_conv::dt_int64:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5415 retval = identity_matrix<int64NDArray> (nr, nc);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5416 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5417
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5418 case oct_data_conv::dt_uint64:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5419 retval = identity_matrix<uint64NDArray> (nr, nc);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5420 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5421
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5422 case oct_data_conv::dt_single:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5423 retval = FloatDiagMatrix (nr, nc, 1.0f);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5424 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5425
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5426 case oct_data_conv::dt_double:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5427 retval = DiagMatrix (nr, nc, 1.0);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5428 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5429
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5430 case oct_data_conv::dt_logical:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5431 retval = identity_matrix<boolNDArray> (nr, nc);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5432 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5433
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5434 default:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5435 error ("eye: invalid class name");
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5436 break;
4945
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
5437 }
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
5438
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
5439 return retval;
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
5440 }
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
5441
4946
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5442 #undef INT_EYE_MATRIX
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5443
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1940
diff changeset
5444 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
5445 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5446 @deftypefn {} {@var{I} =} eye (@var{n})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5447 @deftypefnx {} {@var{I} =} eye (@var{m}, @var{n})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5448 @deftypefnx {} {@var{I} =} eye ([@var{m} @var{n}])
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5449 @deftypefnx {} {@var{I} =} eye (@dots{}, @var{class})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5450 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
5451
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5452 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
5453 @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
5454
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5455 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
5456 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
5457 @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
5458 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
5459
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5460 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5461 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5462 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
5463 @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
5464 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
5465 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
5466 @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
5467 @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
5468
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5469 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
5470
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5471 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5472 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5473 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
5474 @equiv{}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5475 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
5476 @equiv{}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5477 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
5478 @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
5479 @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
5480
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5481 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
5482 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
5483
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5484 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5485 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
5486 @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
5487
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5488 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
5489 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
5490 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
5491 @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
5492 @end deftypefn */)
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
5493 {
4948
7124436476cb [project @ 2004-08-31 17:57:21 by jwe]
jwe
parents: 4947
diff changeset
5494 int nargin = args.length ();
4945
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
5495
4948
7124436476cb [project @ 2004-08-31 17:57:21 by jwe]
jwe
parents: 4947
diff changeset
5496 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
5497
4945
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
5498 // Check for type information.
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
5499
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
5500 if (nargin > 0 && args(nargin-1).is_string ())
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
5501 {
4948
7124436476cb [project @ 2004-08-31 17:57:21 by jwe]
jwe
parents: 4947
diff changeset
5502 std::string nm = args(nargin-1).string_value ();
4945
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
5503 nargin--;
4948
7124436476cb [project @ 2004-08-31 17:57:21 by jwe]
jwe
parents: 4947
diff changeset
5504
7124436476cb [project @ 2004-08-31 17:57:21 by jwe]
jwe
parents: 4947
diff changeset
5505 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
5506 }
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
5507
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5508 if (nargin > 2)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5509 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5510
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5511 octave_value retval;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5512
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5513 if (nargin == 0)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5514 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
5515 else if (nargin == 1)
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
5516 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5517 octave_idx_type nr, nc;
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
5518 get_dimensions (args(0), "eye", nr, nc);
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5519
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5520 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
5521 }
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5522 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5523 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5524 octave_idx_type nr, nc;
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
5525 get_dimensions (args(0), args(1), "eye", nr, nc);
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5526
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5527 retval = identity_matrix (nr, nc, dt);
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
5528 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
5529
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
5530 return retval;
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
5531 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
5532
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5533 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5534 %!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
5535 %!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
5536
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5537 %!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
5538 %!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
5539
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5540 %!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
5541 %!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
5542
25928
a533a7c4d2cc Emit an error when utility matrices (zeros, ones, rand, etc.) are given a fractional dimension in a dimension vector (bug #54781).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25927
diff changeset
5543 ## Test input validation
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5544 %!error eye (1, 2, 3)
25928
a533a7c4d2cc Emit an error when utility matrices (zeros, ones, rand, etc.) are given a fractional dimension in a dimension vector (bug #54781).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25927
diff changeset
5545 %!error <conversion of 1.1 .*failed> eye (1.1)
a533a7c4d2cc Emit an error when utility matrices (zeros, ones, rand, etc.) are given a fractional dimension in a dimension vector (bug #54781).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25927
diff changeset
5546 %!error <conversion of 1.1 .*failed> eye (1, 1.1)
a533a7c4d2cc Emit an error when utility matrices (zeros, ones, rand, etc.) are given a fractional dimension in a dimension vector (bug #54781).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25927
diff changeset
5547 %!error <conversion of 1.1 .*failed> eye ([1, 1.1])
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5548 */
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5549
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
5550 template <typename MT>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
5551 static octave_value
9658
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5552 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
5553 octave_idx_type n)
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5554 {
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5555 typedef typename MT::column_vector_type CVT;
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5556 typedef typename MT::element_type T;
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5557
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5558 octave_value retval;
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5559
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5560 if (base.is_scalar_type ())
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5561 {
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5562 T bs = octave_value_extract<T> (base);
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5563 if (limit.is_scalar_type ())
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5564 {
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5565 T ls = octave_value_extract<T> (limit);
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5566 retval = linspace (bs, ls, n);
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5567 }
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5568 else
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5569 {
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5570 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
5571 CVT bv (lv.numel (), bs);
9658
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5572 retval = linspace (bv, lv, n);
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5573 }
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5574 }
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5575 else
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5576 {
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5577 CVT bv = octave_value_extract<CVT> (base);
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5578 if (limit.is_scalar_type ())
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5579 {
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5580 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
5581 CVT lv (bv.numel (), ls);
9658
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5582 retval = linspace (bv, lv, n);
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5583 }
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5584 else
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5585 {
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5586 CVT lv = octave_value_extract<CVT> (limit);
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5587 retval = linspace (bv, lv, n);
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5588 }
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5589 }
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5590
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5591 return retval;
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5592 }
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5593
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1940
diff changeset
5594 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
5595 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5596 @deftypefn {} {@var{y} =} linspace (@var{start}, @var{end})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5597 @deftypefnx {} {@var{y} =} linspace (@var{start}, @var{end}, @var{n})
24504
5188d936c79a doc: Documentation fixes for linspace, logspace, lookup (bug #52785).
Rik <rik@octave.org>
parents: 24440
diff changeset
5598 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
5599 and @var{end}.
5188d936c79a doc: Documentation fixes for linspace, logspace, lookup (bug #52785).
Rik <rik@octave.org>
parents: 24440
diff changeset
5600
31923
073cc98750c6 doc: Improve documentation for linspace and logspace functions.
Rik <rik@octave.org>
parents: 31706
diff changeset
5601 If the number of elements @var{n} is greater than one, then the endpoints
073cc98750c6 doc: Improve documentation for linspace and logspace functions.
Rik <rik@octave.org>
parents: 31706
diff changeset
5602 @var{start} and @var{end} are always included in the range. If @var{start} is
073cc98750c6 doc: Improve documentation for linspace and logspace functions.
Rik <rik@octave.org>
parents: 31706
diff changeset
5603 greater than @var{end}, the elements are stored in decreasing order. If the
073cc98750c6 doc: Improve documentation for linspace and logspace functions.
Rik <rik@octave.org>
parents: 31706
diff changeset
5604 number of points @var{n} is not specified, a value of 100 is used.
24504
5188d936c79a doc: Documentation fixes for linspace, logspace, lookup (bug #52785).
Rik <rik@octave.org>
parents: 24440
diff changeset
5605
5188d936c79a doc: Documentation fixes for linspace, logspace, lookup (bug #52785).
Rik <rik@octave.org>
parents: 24440
diff changeset
5606 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
5607 @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
5608 @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
5609 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
5610 @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
5611
31923
073cc98750c6 doc: Improve documentation for linspace and logspace functions.
Rik <rik@octave.org>
parents: 31706
diff changeset
5612 Programming Notes: For compatibility with @sc{matlab}, return the second
073cc98750c6 doc: Improve documentation for linspace and logspace functions.
Rik <rik@octave.org>
parents: 31706
diff changeset
5613 argument (@var{end}) when a single value (@var{n} = 1) is requested. If
073cc98750c6 doc: Improve documentation for linspace and logspace functions.
Rik <rik@octave.org>
parents: 31706
diff changeset
5614 @var{n} is not an integer then @code{floor (@var{n})} is used to round the
073cc98750c6 doc: Improve documentation for linspace and logspace functions.
Rik <rik@octave.org>
parents: 31706
diff changeset
5615 number of elements. If @var{n} is zero or negative then an empty 1x0 matrix
073cc98750c6 doc: Improve documentation for linspace and logspace functions.
Rik <rik@octave.org>
parents: 31706
diff changeset
5616 is returned.
24504
5188d936c79a doc: Documentation fixes for linspace, logspace, lookup (bug #52785).
Rik <rik@octave.org>
parents: 24440
diff changeset
5617 @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
5618 @end deftypefn */)
1100
3b6f6c5217e7 [project @ 1995-02-14 01:45:09 by jwe]
jwe
parents: 1032
diff changeset
5619 {
3b6f6c5217e7 [project @ 1995-02-14 01:45:09 by jwe]
jwe
parents: 1032
diff changeset
5620 int nargin = args.length ();
3b6f6c5217e7 [project @ 1995-02-14 01:45:09 by jwe]
jwe
parents: 1032
diff changeset
5621
1940
1b193e313c56 [project @ 1996-02-13 16:28:47 by jwe]
jwe
parents: 1884
diff changeset
5622 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
5623 print_usage ();
1940
1b193e313c56 [project @ 1996-02-13 16:28:47 by jwe]
jwe
parents: 1884
diff changeset
5624
6133
e0065af38cf4 [project @ 2006-11-02 03:33:50 by jwe]
jwe
parents: 5991
diff changeset
5625 octave_idx_type npoints = 100;
1100
3b6f6c5217e7 [project @ 1995-02-14 01:45:09 by jwe]
jwe
parents: 1032
diff changeset
5626 if (nargin == 3)
16077
39129305b914 provide some undocumented matlab behavior for linspace (bug #38151)
John W. Eaton <jwe@octave.org>
parents: 15623
diff changeset
5627 {
39129305b914 provide some undocumented matlab behavior for linspace (bug #38151)
John W. Eaton <jwe@octave.org>
parents: 15623
diff changeset
5628 // 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
5629 // 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
5630 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
5631
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23585
diff changeset
5632 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
5633 npoints = 1;
20466
16b9ec39ff46 Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents: 20405
diff changeset
5634 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
5635 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
5636 else
20573
32a0bf9906c1 linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents: 20562
diff changeset
5637 // 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
5638 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
5639 }
1100
3b6f6c5217e7 [project @ 1995-02-14 01:45:09 by jwe]
jwe
parents: 1032
diff changeset
5640
20573
32a0bf9906c1 linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents: 20562
diff changeset
5641 octave_value arg_1 = args(0);
32a0bf9906c1 linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents: 20562
diff changeset
5642 octave_value arg_2 = args(1);
32a0bf9906c1 linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents: 20562
diff changeset
5643
32a0bf9906c1 linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents: 20562
diff changeset
5644 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
5645 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
5646 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
5647 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
5648
32a0bf9906c1 linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents: 20562
diff changeset
5649 if (! isvector1 || ! isvector2)
24535
22a2bc91cc7f Add more BIST tests for linspace.
Rik <rik@octave.org>
parents: 24534
diff changeset
5650 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
5651
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5652 octave_value retval;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5653
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5654 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
5655 {
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
5656 if (arg_1.iscomplex () || arg_2.iscomplex ())
20573
32a0bf9906c1 linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents: 20562
diff changeset
5657 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
5658 else
20573
32a0bf9906c1 linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents: 20562
diff changeset
5659 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
5660 }
4732
b484cdca27be [project @ 2004-02-04 04:32:48 by jwe]
jwe
parents: 4685
diff changeset
5661 else
20573
32a0bf9906c1 linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents: 20562
diff changeset
5662 {
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
5663 if (arg_1.iscomplex () || arg_2.iscomplex ())
20573
32a0bf9906c1 linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents: 20562
diff changeset
5664 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
5665 else
32a0bf9906c1 linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents: 20562
diff changeset
5666 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
5667 }
1100
3b6f6c5217e7 [project @ 1995-02-14 01:45:09 by jwe]
jwe
parents: 1032
diff changeset
5668
3b6f6c5217e7 [project @ 1995-02-14 01:45:09 by jwe]
jwe
parents: 1032
diff changeset
5669 return retval;
3b6f6c5217e7 [project @ 1995-02-14 01:45:09 by jwe]
jwe
parents: 1032
diff changeset
5670 }
3b6f6c5217e7 [project @ 1995-02-14 01:45:09 by jwe]
jwe
parents: 1032
diff changeset
5671
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5672 /*
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5673 %!test
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5674 %! 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
5675 %! 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
5676 %! 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
5677 %! 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
5678 %! 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
5679 %! 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
5680 %! 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
5681 %! 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
5682 %! 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
5683
20466
16b9ec39ff46 Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents: 20405
diff changeset
5684 ## Test complex values
16b9ec39ff46 Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents: 20405
diff changeset
5685 %!test
16b9ec39ff46 Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents: 20405
diff changeset
5686 %! 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
5687 %! 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
5688 %! assert (obs, exp);
16b9ec39ff46 Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents: 20405
diff changeset
5689
24535
22a2bc91cc7f Add more BIST tests for linspace.
Rik <rik@octave.org>
parents: 24534
diff changeset
5690 ## 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
5691 %!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
5692 %! [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
5693 %!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
5694 %! [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
5695 %!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
5696 %! [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
5697 %!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
5698 %! [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
5699 %!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
5700 %! [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
5701 %!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
5702 %! [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
5703
20466
16b9ec39ff46 Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents: 20405
diff changeset
5704 ## Test class of output
16b9ec39ff46 Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents: 20405
diff changeset
5705 %!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
5706 %!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
5707 %!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
5708
27435
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5709 ## Test symmetry
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5710 %!test <*56659>
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5711 %! x = linspace (-1, 1, 10);
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5712 %! assert (all (x == -fliplr (x)));
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5713 %! x = linspace (-1, 1, 11);
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5714 %! assert (all (x == -fliplr (x)));
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5715
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5716 %!test <*56659>
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5717 %! x = linspace (-1-1i, 1+1i, 10);
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5718 %! assert (all (x == -fliplr (x)));
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5719 %! x = linspace (-1-1i, 1+1i, 11);
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5720 %! assert (all (x == -fliplr (x)));
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5721
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5722 %!test <*56659>
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5723 %! x = linspace (single (-1), 1, 10);
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5724 %! assert (all (x == -fliplr (x)));
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5725 %! x = linspace (single (-1), 1, 11);
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5726 %! assert (all (x == -fliplr (x)));
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5727
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5728 %!test <*56659>
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5729 %! x = linspace (single (-1-1i), 1+1i, 10);
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5730 %! assert (all (x == -fliplr (x)));
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5731 %! x = linspace (single (-1-1i), 1+1i, 11);
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5732 %! assert (all (x == -fliplr (x)));
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5733
20466
16b9ec39ff46 Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents: 20405
diff changeset
5734 ## 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
5735 %!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
5736 %!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
5737 %!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
5738 %!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
5739 %!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
5740 %!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
5741 %!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
5742 %!assert (linspace (10, 20, 2.1), [10 20])
32a0bf9906c1 linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents: 20562
diff changeset
5743 %!assert (linspace (10, 20, 2.9), [10 20])
24634
ab2321d4ba03 maint: strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 24619
diff changeset
5744 %!assert (1 ./ linspace (-0, 0, 4), [-Inf, Inf, Inf, Inf])
25237
ca022a8c4015 linspace: handle ranges with equal Inf endpoints (bug #53489)
Maor Shutman <maorus12@gmail.com>
parents: 25103
diff changeset
5745 %!assert (linspace (Inf, Inf, 3), [Inf, Inf, Inf])
ca022a8c4015 linspace: handle ranges with equal Inf endpoints (bug #53489)
Maor Shutman <maorus12@gmail.com>
parents: 25103
diff changeset
5746 %!assert (linspace (-Inf, -Inf, 3), [-Inf, -Inf, -Inf])
27435
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5747 %!assert (linspace (-Inf, Inf, 3), [-Inf, 0, Inf])
25237
ca022a8c4015 linspace: handle ranges with equal Inf endpoints (bug #53489)
Maor Shutman <maorus12@gmail.com>
parents: 25103
diff changeset
5748 %!assert (linspace (Inf + 1i, Inf + 1i, 3), [Inf + 1i, Inf + 1i, Inf + 1i])
ca022a8c4015 linspace: handle ranges with equal Inf endpoints (bug #53489)
Maor Shutman <maorus12@gmail.com>
parents: 25103
diff changeset
5749 %!assert (linspace (-Inf + 1i, Inf + 1i, 3), [-Inf + 1i, NaN + 1i, Inf + 1i])
27435
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5750
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5751 ## FIXME: Octave is not fully Matlab-compatible for some combinations of
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5752 ## Inf/-Inf endpoints. See bug #56933. This was dubbed "Won't Fix"
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5753 ## so these tests have been removed from the test suite by commenting
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5754 ## them out. If the behavior in the future is made compatible these
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5755 ## tests can be re-instated.
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5756 ##%!assert <56933> (linspace (-Inf, Inf, 4), [-Inf, -Inf, Inf, Inf])
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5757 ##%!assert <56933> (linspace (-Inf, Inf, 5), [-Inf, -Inf, 0, Inf, Inf])
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5758 ##%!assert <56933> (linspace (0, Inf, 4), [0, Inf, Inf, Inf])
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5759 ##%!assert <56933> (linspace (0, -Inf, 4), [0, -Inf, -Inf, -Inf])
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5760 ##%!assert <56933> (linspace (-Inf, 0, 4), [-Inf, NaN, NaN, 0])
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5761 ##%!assert <56933> (linspace (Inf, 0, 4), [Inf, NaN, NaN, 0])
16077
39129305b914 provide some undocumented matlab behavior for linspace (bug #38151)
John W. Eaton <jwe@octave.org>
parents: 15623
diff changeset
5762
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5763 %!error linspace ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5764 %!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
5765 %!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
5766 %!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
5767 %!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
5768 %!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
5769 */
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5770
20726
25d676f9619c Preface error() messages with name of function when possible.
Rik <rik@octave.org>
parents: 20720
diff changeset
5771 // 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
5772 // 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
5773
5731
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
5774 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
5775 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5776 @deftypefn {} {@var{B} =} resize (@var{A}, @var{m})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5777 @deftypefnx {} {@var{B} =} resize (@var{A}, @var{m}, @var{n}, @dots{})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5778 @deftypefnx {} {@var{B} =} resize (@var{A}, [@var{m} @var{n} @dots{}])
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5779 Resize @var{A} cutting off elements as necessary.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5780
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5781 In the result, element with certain indices is equal to the corresponding
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5782 element of @var{A} if the indices are within the bounds of @var{A}; otherwise,
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5783 the element is set to zero.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5784
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5785 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
5786
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5787 @example
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5788 B = resize (A, dv)
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5789 @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
5790
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5791 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5792 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
5793
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5794 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5795 @group
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5796 B = zeros (dv, class (A));
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5797 sz = min (dv, size (A));
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5798 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
5799 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
5800 endfor
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5801 B(idx@{:@}) = A(idx@{:@});
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5802 @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
5803 @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
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 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5806 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
5807
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5808 If only @var{m} is supplied, and it is a scalar, the dimension of the result is
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5809 @var{m}-by-@var{m}. If @var{m}, @var{n}, @dots{} are all scalars, then the
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5810 dimensions of the result are @var{m}-by-@var{n}-by-@dots{}. If given a vector
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5811 as input, then the dimensions of the result are given by the elements of that
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5812 vector.
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5813
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5814 An object can be resized to more dimensions than it has; in such case the
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5815 missing dimensions are assumed to be 1. Resizing an object to fewer dimensions
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5816 is not possible.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5817 @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
5818 @end deftypefn */)
5731
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
5819 {
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
5820 int nargin = args.length ();
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
5821
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5822 if (nargin < 2)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5823 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5824
5731
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
5825 octave_value retval;
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
5826
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
5827 if (nargin == 2)
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
5828 {
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
5829 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
5830 int ndim = vec.numel ();
5731
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
5831 if (ndim == 1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5832 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5833 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
5834 retval = args(0);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5835 retval = retval.resize (dim_vector (m, m), true);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5836 }
5731
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
5837 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5838 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5839 dim_vector dv;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5840 dv.resize (ndim);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5841 for (int i = 0; i < ndim; i++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5842 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
5843 retval = args(0);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5844 retval = retval.resize (dv, true);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5845 }
5731
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
5846 }
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5847 else
5731
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
5848 {
8799
f6dc6eb57045 improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 8780
diff changeset
5849 dim_vector dv;
f6dc6eb57045 improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 8780
diff changeset
5850 dv.resize (nargin - 1);
f6dc6eb57045 improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 8780
diff changeset
5851 for (octave_idx_type i = 1; i < nargin; i++)
f6dc6eb57045 improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 8780
diff changeset
5852 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
5853
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5854 retval = args(0);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5855 retval = retval.resize (dv, true);
5731
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
5856 }
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5857
5731
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
5858 return retval;
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
5859 }
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
5860
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
5861 // FIXME: should use octave_idx_type for dimensions.
5734
a7d2c47371d2 [project @ 2006-04-04 18:29:13 by jwe]
jwe
parents: 5731
diff changeset
5862
4567
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
5863 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
5864 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5865 @deftypefn {} {@var{B} =} reshape (@var{A}, @var{m}, @var{n}, @dots{})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5866 @deftypefnx {} {@var{B} =} reshape (@var{A}, [@var{m} @var{n} @dots{}])
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5867 @deftypefnx {} {@var{B} =} reshape (@var{A}, @dots{}, [], @dots{})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5868 @deftypefnx {} {@var{B} =} reshape (@var{A}, @var{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
5869 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
5870 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
5871
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5872 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
5873 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
5874
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5875 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
5876 matrix.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5877
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5878 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5879 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5880 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
5881 @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
5882 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
5883 @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
5884 @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
5885
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5886 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5887 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
5888 (@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
5889 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
5890
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5891 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
5892 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
5893 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
5894 @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
5895 @end deftypefn */)
4567
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
5896 {
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
5897 int nargin = args.length ();
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
5898
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5899 if (nargin < 2)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5900 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5901
4567
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
5902 octave_value retval;
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
5903
10693
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
5904 dim_vector new_dims;
4567
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
5905
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
5906 if (nargin == 2)
10693
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
5907 {
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
5908 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
5909
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20218
diff changeset
5910 if (new_size.numel () < 2)
20893
384ff5aa9437 2015 Code Sprint: Eliminate useless return statements after error ().
Rik <rik@octave.org>
parents: 20884
diff changeset
5911 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
5912
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20218
diff changeset
5913 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
5914
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20218
diff changeset
5915 for (octave_idx_type i = 0; i < new_size.numel (); i++)
10693
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
5916 {
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
5917 if (new_size(i) < 0)
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5918 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
5919
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
5920 new_dims(i) = new_size(i);
10693
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
5921 }
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
5922 }
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5923 else
4567
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
5924 {
10693
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
5925 new_dims = dim_vector::alloc (nargin-1);
5013
1eb9ce5c0152 [project @ 2004-09-21 22:18:07 by jwe]
jwe
parents: 4986
diff changeset
5926 int empty_dim = -1;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
5927
4567
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
5928 for (int i = 1; i < nargin; i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5929 {
23577
80c42f4cca13 maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents: 23576
diff changeset
5930 if (args(i).isempty ())
10693
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
5931 {
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
5932 if (empty_dim > 0)
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5933 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
5934
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
5935 empty_dim = i;
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
5936 new_dims(i-1) = 1;
10693
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
5937 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5938 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5939 {
10693
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
5940 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
5941
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5942 if (new_dims(i-1) < 0)
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5943 error ("reshape: SIZE must be non-negative");
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5944 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5945 }
5013
1eb9ce5c0152 [project @ 2004-09-21 22:18:07 by jwe]
jwe
parents: 4986
diff changeset
5946
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5947 if (empty_dim > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5948 {
10693
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
5949 octave_idx_type nel = new_dims.numel ();
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5950
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5951 if (nel == 0)
10693
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
5952 new_dims(empty_dim-1) = 0;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5953 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5954 {
10693
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
5955 octave_idx_type a_nel = args(0).numel ();
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
5956 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
5957
10693
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
5958 if (a_nel != size_empty_dim * nel)
26164
7f6a50f73625 Silence compiler warnings about format identifier for octave_idx_type (bug #55046).
Markus Mützel <markus.muetzel@gmx.de>
parents: 26107
diff changeset
5959 error ("reshape: SIZE is not divisible by the product of "
7f6a50f73625 Silence compiler warnings about format identifier for octave_idx_type (bug #55046).
Markus Mützel <markus.muetzel@gmx.de>
parents: 26107
diff changeset
5960 "known dimensions (= %" OCTAVE_IDX_TYPE_FORMAT ")",
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
5961 nel);
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
5962
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
5963 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
5964 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5965 }
4567
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
5966 }
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
5967
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5968 retval = args(0).reshape (new_dims);
4567
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
5969
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
5970 return retval;
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
5971 }
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
5972
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5973 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5974 %!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
5975 %!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
5976 %!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
5977 %!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
5978
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5979 %!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
5980 %!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
5981 %!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
5982 %!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
5983
32045
f18da620ab4d Fix floating point exception when Sparse array reshaped to 0x0 (bug #64080)
Rik <rik@octave.org>
parents: 31923
diff changeset
5984 %!assert <*64080> (size (reshape (sparse (0, 1), 0, 0)), [0, 0])
f18da620ab4d Fix floating point exception when Sparse array reshaped to 0x0 (bug #64080)
Rik <rik@octave.org>
parents: 31923
diff changeset
5985
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5986 %!test
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5987 %! s.a = 1;
17915
56d2b6838405 Issue an error if reshape called with just a single dimension.
Rik <rik@octave.org>
parents: 17843
diff changeset
5988 %! 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
5989
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5990 %!error reshape ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5991 %!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
5992 %!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
5993 %!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
5994 %!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
5995 %!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
5996 %!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
5997 */
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5998
10694
d97165928d05 implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents: 10693
diff changeset
5999 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
6000 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
6001 @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
6002 @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
6003 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
6004 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
6005
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6006 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
6007
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6008 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
6009 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
6010 @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
6011 @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
6012 @end deftypefn */)
10694
d97165928d05 implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents: 10693
diff changeset
6013 {
11402
a9a3ee461b83 Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents: 11357
diff changeset
6014 int nargin = args.length ();
a9a3ee461b83 Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents: 11357
diff changeset
6015
a9a3ee461b83 Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents: 11357
diff changeset
6016 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
6017 print_usage ();
11402
a9a3ee461b83 Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents: 11357
diff changeset
6018
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6019 int dim = 1;
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
6020 if (nargin == 2)
11402
a9a3ee461b83 Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents: 11357
diff changeset
6021 {
a9a3ee461b83 Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents: 11357
diff changeset
6022 dim = args(1).idx_type_value ();
a9a3ee461b83 Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents: 11357
diff changeset
6023
a9a3ee461b83 Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents: 11357
diff changeset
6024 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
6025 error ("vec: DIM must be greater than zero");
11402
a9a3ee461b83 Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents: 11357
diff changeset
6026 }
a9a3ee461b83 Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents: 11357
diff changeset
6027
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
6028 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
6029 octave_value arg = args(0);
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6030
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6031 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
6032
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
6033 if (dim > 1)
10694
d97165928d05 implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents: 10693
diff changeset
6034 {
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
6035 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
6036
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
6037 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
6038 new_dims(i) = 1;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
6039
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
6040 new_dims(dim-1) = retval.numel ();
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
6041
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
6042 retval = retval.reshape (new_dims);
10694
d97165928d05 implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents: 10693
diff changeset
6043 }
d97165928d05 implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents: 10693
diff changeset
6044
d97165928d05 implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents: 10693
diff changeset
6045 return retval;
d97165928d05 implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents: 10693
diff changeset
6046 }
d97165928d05 implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents: 10693
diff changeset
6047
d97165928d05 implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents: 10693
diff changeset
6048 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6049 %!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
6050 %!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
6051 %!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
6052 %!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
6053 %!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
6054 %!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
6055 %!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
6056 %!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
6057
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6058 %!error vec ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6059 %!error vec (1, 2, 3)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6060 %!error vec ([1, 2; 3, 4], 0)
10694
d97165928d05 implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents: 10693
diff changeset
6061 */
d97165928d05 implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents: 10693
diff changeset
6062
4532
01ee68d18069 [project @ 2003-10-10 00:49:54 by jwe]
jwe
parents: 4516
diff changeset
6063 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
6064 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6065 @deftypefn {} {@var{B} =} squeeze (@var{A})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6066 Remove singleton dimensions from @var{A} and return the result.
21966
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 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
6069 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
6070 @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
6071 @end deftypefn */)
4532
01ee68d18069 [project @ 2003-10-10 00:49:54 by jwe]
jwe
parents: 4516
diff changeset
6072 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6073 if (args.length () != 1)
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
6074 print_usage ();
4532
01ee68d18069 [project @ 2003-10-10 00:49:54 by jwe]
jwe
parents: 4516
diff changeset
6075
21127
df7891224709 maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents: 21121
diff changeset
6076 return ovl (args(0).squeeze ());
4532
01ee68d18069 [project @ 2003-10-10 00:49:54 by jwe]
jwe
parents: 4516
diff changeset
6077 }
01ee68d18069 [project @ 2003-10-10 00:49:54 by jwe]
jwe
parents: 4516
diff changeset
6078
8458
d254a21e0120 reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents: 8433
diff changeset
6079 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
6080 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
6081 @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
6082 Return a full storage matrix from a sparse, diagonal, or permutation matrix,
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6083 or from a range.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6084 @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
6085 @end deftypefn */)
8458
d254a21e0120 reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents: 8433
diff changeset
6086 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6087 if (args.length () != 1)
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
6088 print_usage ();
8458
d254a21e0120 reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents: 8433
diff changeset
6089
21127
df7891224709 maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents: 21121
diff changeset
6090 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
6091 }
d254a21e0120 reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents: 8433
diff changeset
6092
6945
6bbf56a9718a [project @ 2007-10-02 20:47:22 by jwe]
jwe
parents: 6887
diff changeset
6093 // Compute various norms of the vector X.
6bbf56a9718a [project @ 2007-10-02 20:47:22 by jwe]
jwe
parents: 6887
diff changeset
6094
6953
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
6095 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
6096 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6097 @deftypefn {} {@var{n} =} norm (@var{A})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6098 @deftypefnx {} {@var{n} =} norm (@var{A}, @var{p})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6099 @deftypefnx {} {@var{n} =} norm (@var{A}, @var{p}, @var{opt})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6100 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
6101
22827
c3d3a81ad986 doc: Update documentation for norm, normest, normest1, condest.
Rik <rik@octave.org>
parents: 22791
diff changeset
6102 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
6103
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6104 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
6105
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6106 @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
6107 @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
6108 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
6109
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6110 @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
6111 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
6112
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6113 @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
6114 @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
6115 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
6116
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6117 @item @var{p} = @qcode{"fro"}
25003
2365c2661b3c doc: Spellcheck documentation ahead of 4.4 release.
Rik <rik@octave.org>
parents: 24859
diff changeset
6118 @cindex @nospell{Frobenius} norm
2365c2661b3c doc: Spellcheck documentation ahead of 4.4 release.
Rik <rik@octave.org>
parents: 24859
diff changeset
6119 @nospell{Frobenius} norm of @var{A},
2365c2661b3c doc: Spellcheck documentation ahead of 4.4 release.
Rik <rik@octave.org>
parents: 24859
diff changeset
6120 @code{sqrt (sum (diag (@var{A}' * @var{A})))}.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6121
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6122 @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
6123 @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
6124 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
6125 @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
6126
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6127 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
6128
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6129 @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
6130 @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
6131 @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
6132
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6133 @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
6134 @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
6135
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6136 @item @var{p} = @qcode{"fro"}
25003
2365c2661b3c doc: Spellcheck documentation ahead of 4.4 release.
Rik <rik@octave.org>
parents: 24859
diff changeset
6137 @nospell{Frobenius} norm of @var{A}, @code{sqrt (sumsq (abs (A)))}.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6138
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6139 @item @var{p} = 0
22827
c3d3a81ad986 doc: Update documentation for norm, normest, normest1, condest.
Rik <rik@octave.org>
parents: 22791
diff changeset
6140 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
6141
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6142 @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
6143 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
6144
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6145 @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
6146 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
6147 @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
6148
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6149 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
6150 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
6151 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
6152 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
6153 @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
6154 @end deftypefn */)
6508
184ab67c3bc1 [project @ 2007-04-07 00:43:09 by jwe]
jwe
parents: 6401
diff changeset
6155 {
184ab67c3bc1 [project @ 2007-04-07 00:43:09 by jwe]
jwe
parents: 6401
diff changeset
6156 int nargin = args.length ();
184ab67c3bc1 [project @ 2007-04-07 00:43:09 by jwe]
jwe
parents: 6401
diff changeset
6157
22789
bedfedcd878e norm: fix error in input argument validation leading to segfault (bug #49634)
Mike Miller <mtmiller@octave.org>
parents: 22749
diff changeset
6158 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
6159 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6160
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6161 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
6162
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6163 if (x_arg.ndims () != 2)
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6164 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
6165
23147
eb5a162c1342 Accept case-insensitive string value for p-value input to norm (bug #50195);
Rik <rik@octave.org>
parents: 23141
diff changeset
6166 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
6167 if (nargin > 1 && args(nargin-1).is_string ())
6508
184ab67c3bc1 [project @ 2007-04-07 00:43:09 by jwe]
jwe
parents: 6401
diff changeset
6168 {
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6169 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
6170 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
6171 if (str == "cols" || str == "columns")
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6172 strflag = sfcols;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6173 else if (str == "rows")
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6174 strflag = sfrows;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6175 else if (str == "fro")
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6176 strflag = sffrob;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6177 else if (str == "inf")
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6178 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
6179 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
6180 strflag = sfneginf;
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6181 else
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6182 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
6183
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6184 // 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
6185 nargin--;
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6186 }
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6187
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6188 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
6189
23577
80c42f4cca13 maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents: 23576
diff changeset
6190 if (p_arg.isempty ())
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6191 p_arg = octave_value (2);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6192 else if (p_arg.is_string ())
6508
184ab67c3bc1 [project @ 2007-04-07 00:43:09 by jwe]
jwe
parents: 6401
diff changeset
6193 {
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6194 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
6195 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
6196 if (strflag != sfcols && strflag != sfrows)
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
6197 error ("norm: invalid combination of options");
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
6198
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
6199 if (str == "cols" || str == "columns" || str == "rows")
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
6200 error ("norm: invalid combination of options");
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
6201
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
6202 if (str == "fro")
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
6203 p_arg = octave_value (2);
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
6204 else if (str == "inf")
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
6205 p_arg = 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
6206 else if (str == "-inf")
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
6207 p_arg = -numeric_limits<double>::Inf ();
6508
184ab67c3bc1 [project @ 2007-04-07 00:43:09 by jwe]
jwe
parents: 6401
diff changeset
6208 else
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
6209 error ("norm: unrecognized option: %s", str.c_str ());
6508
184ab67c3bc1 [project @ 2007-04-07 00:43:09 by jwe]
jwe
parents: 6401
diff changeset
6210 }
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6211 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
6212 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
6213
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6214 octave_value retval;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6215
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6216 switch (strflag)
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6217 {
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6218 case sfmatrix:
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6219 retval = xnorm (x_arg, p_arg);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6220 break;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6221
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6222 case sfcols:
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6223 retval = xcolnorms (x_arg, p_arg);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6224 break;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6225
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6226 case sfrows:
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6227 retval = xrownorms (x_arg, p_arg);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6228 break;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6229
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6230 case sffrob:
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6231 retval = xfrobnorm (x_arg);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6232 break;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6233
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6234 case sfinf:
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
6235 retval = xnorm (x_arg, numeric_limits<double>::Inf ());
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6236 break;
23147
eb5a162c1342 Accept case-insensitive string value for p-value input to norm (bug #50195);
Rik <rik@octave.org>
parents: 23141
diff changeset
6237
eb5a162c1342 Accept case-insensitive string value for p-value input to norm (bug #50195);
Rik <rik@octave.org>
parents: 23141
diff changeset
6238 case sfneginf:
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
6239 retval = xnorm (x_arg, -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
6240 break;
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6241 }
6508
184ab67c3bc1 [project @ 2007-04-07 00:43:09 by jwe]
jwe
parents: 6401
diff changeset
6242
184ab67c3bc1 [project @ 2007-04-07 00:43:09 by jwe]
jwe
parents: 6401
diff changeset
6243 return retval;
184ab67c3bc1 [project @ 2007-04-07 00:43:09 by jwe]
jwe
parents: 6401
diff changeset
6244 }
184ab67c3bc1 [project @ 2007-04-07 00:43:09 by jwe]
jwe
parents: 6401
diff changeset
6245
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
6246 /*
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
6247 %!shared x
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
6248 %! 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
6249 %!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
6250 %!assert (norm (x,1), 20)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6251 %!assert (norm (x,2), 10)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6252 %!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
6253 %!assert (norm (x,Inf), 7)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6254 %!assert (norm (x,-Inf), 1)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6255 %!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
6256 %!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
6257 %!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
6258 %!assert (norm (x), 10)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6259 %!assert (norm ([1e200, 1]), 1e200)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6260 %!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
6261 %!shared m
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
6262 %! m = magic (4);
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6263 %!assert (norm (m,1), 34)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6264 %!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
6265 %!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
6266 %!assert (norm (m,Inf), 34)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6267 %!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
6268 %!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
6269 %! 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
6270 %! 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
6271 %! fhi = 1e+300;
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6272 %!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
6273 %!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
6274
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
6275 %!shared x
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6276 %! 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
6277 %!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
6278 %!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
6279 %!assert (norm (x,2), single (10))
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
6280 %!assert (norm (x,3), single (8.24257059961711), -4* eps ("single"))
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6281 %!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
6282 %!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
6283 %!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
6284 %!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
6285 %!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
6286 %!assert (norm (x), single (10))
18676
5bd1ca29c5f0 Clean up questionable code bits identified by clang sanitize.
Rik <rik@octave.org>
parents: 18212
diff changeset
6287 %!assert (norm (single ([1e38, 1])), single (1e38))
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
6288 %!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
6289 %!shared m
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6290 %! m = single (magic (4));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6291 %!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
6292 %!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
6293 %!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
6294 %!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
6295 %!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
6296 %!shared m2, flo, fhi
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6297 %! 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
6298 %! flo = single (1e-300);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6299 %! fhi = single (1e+300);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6300 %!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
6301 %!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
6302
23141
bfa4ad642fa0 Disallow p-norm of -Inf for matrices (bug #50194).
Rik <rik@octave.org>
parents: 23127
diff changeset
6303 ## Hamming norm (p == 0)
bfa4ad642fa0 Disallow p-norm of -Inf for matrices (bug #50194).
Rik <rik@octave.org>
parents: 23127
diff changeset
6304 %!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
6305
17115
00985134145e norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents: 16892
diff changeset
6306 %!shared q
00985134145e norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents: 16892
diff changeset
6307 %! q = rand (1e3, 3);
21317
a4faec57f4c8 maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents: 21301
diff changeset
6308 %!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
6309 %!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
6310 %!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
6311 %!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
6312 %!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
6313 %!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
6314 %!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
6315 %!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
6316 %!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
6317
22489
93ea313301f9 test: Add bug ids (<#####>) to BIST tests.
Rik <rik@octave.org>
parents: 22440
diff changeset
6318 %!test <30631>
93ea313301f9 test: Add bug ids (<#####>) to BIST tests.
Rik <rik@octave.org>
parents: 22440
diff changeset
6319 %! ## 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
6320 %! 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
6321 %! 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
6322 %! 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
6323
bedfedcd878e norm: fix error in input argument validation leading to segfault (bug #49634)
Mike Miller <mtmiller@octave.org>
parents: 22749
diff changeset
6324 ## 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
6325 %!error norm ()
bedfedcd878e norm: fix error in input argument validation leading to segfault (bug #49634)
Mike Miller <mtmiller@octave.org>
parents: 22749
diff changeset
6326 %!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
6327 %!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
6328 %!error <unrecognized option> norm (1, "rows", "invalid")
22791
da106618264a norm: fix input validation tests
Mike Miller <mtmiller@octave.org>
parents: 22789
diff changeset
6329 %!error <unrecognized option> norm (1, "invalid", "rows")
da106618264a norm: fix input validation tests
Mike Miller <mtmiller@octave.org>
parents: 22789
diff changeset
6330 %!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
6331 %!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
6332 %!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
6333 */
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
6334
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6335 static octave_value
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6336 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
6337 const octave_value_list& args)
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6338 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6339 if (args.length () != 1)
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6340 print_usage ();
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6341
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
6342 return unary_op (op, args(0));
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6343 }
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6344
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6345 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
6346 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
6347 @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
6348 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
6349
24618
c99163d188df doc: Use @var{} around variables in operator functions such as and, or, uplus.
Rik <rik@octave.org>
parents: 24517
diff changeset
6350 This function is equivalent to the operator syntax @w{@code{! @var{x}}}.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6351 @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
6352 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6353 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6354 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
6355 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6356
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6357 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
6358 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6359 @deftypefn {} {@var{B} =} uplus (@var{A})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6360 This function and @w{@tcode{+ @var{A}}} are equivalent.
29514
ec768b0f7dcd doc: Use Texinfo commands to improve transpose() docstring rendering.
Rik <rik@octave.org>
parents: 29358
diff changeset
6361 @seealso{uminus, plus}
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6362 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6363 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6364 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
6365 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6366
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6367 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
6368 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6369 @deftypefn {} {@var{B} =} uminus (@var{A})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6370 This function and @w{@tcode{- @var{A}}} are equivalent.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6371 @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
6372 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6373 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6374 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
6375 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6376
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6377 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
6378 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6379 @deftypefn {} {@var{B} =} transpose (@var{A})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6380 Return the transpose of @var{A}.
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6381
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6382 This function and @tcode{@var{A}.'@:} are equivalent.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6383 @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
6384 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6385 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6386 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
6387 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6388
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
6389 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6390 %!assert (2.', 2)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6391 %!assert (2i.', 2i)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6392 %!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
6393 %!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
6394 %!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
6395 %!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
6396
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6397 %!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
6398
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6399 %!assert (single (2).', single (2))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6400 %!assert (single (2i).', single (2i))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6401 %!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
6402 %!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
6403 %!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
6404 %!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
6405
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6406 %!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
6407 */
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
6408
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6409 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
6410 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6411 @deftypefn {} {@var{B} =} ctranspose (@var{A})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6412 Return the complex conjugate transpose of @var{A}.
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6413
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6414 This function and @tcode{@var{A}'} are equivalent.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6415 @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
6416 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6417 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6418 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
6419 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6420
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
6421 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6422 %!assert (2', 2)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6423 %!assert (2i', -2i)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6424 %!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
6425 %!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
6426 %!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
6427 %!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
6428
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6429 %!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
6430
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6431 %!assert (single (2)', single (2))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6432 %!assert (single (2i)', single (-2i))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6433 %!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
6434 %!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
6435 %!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
6436 %!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
6437
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6438 %!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
6439 */
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
6440
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6441 static octave_value
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6442 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
6443 const octave_value_list& args)
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6444 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6445 if (args.length () != 2)
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6446 print_usage ();
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6447
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
6448 return 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
6449 }
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6450
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6451 static octave_value
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6452 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
6453 octave_value::assign_op aop,
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6454 const octave_value_list& args)
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6455 {
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6456 int nargin = args.length ();
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6457
25267
308a272bbe3c Emit an error if binary operator functions (or, plus, etc.) are called with 1 arg (bug 53450).
Rik <rik@octave.org>
parents: 25237
diff changeset
6458 if (nargin < 2)
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6459 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6460
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6461 octave_value retval;
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6462
25267
308a272bbe3c Emit an error if binary operator functions (or, plus, etc.) are called with 1 arg (bug 53450).
Rik <rik@octave.org>
parents: 25237
diff changeset
6463 if (nargin == 2)
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
6464 retval = 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
6465 else
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6466 {
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
6467 retval = 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
6468
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
6469 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
6470 retval.assign (aop, args(i));
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6471 }
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6472
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6473 return retval;
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6474 }
9339
c0b104835d0d allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
6475
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6476 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
6477 doc: /* -*- texinfo -*-
31141
9e9f5f1e8ec2 doc: Update plus() function to use inputs A, B.
Rik <rik@octave.org>
parents: 31105
diff changeset
6478 @deftypefn {} {@var{C} =} plus (@var{A}, @var{B})
9e9f5f1e8ec2 doc: Update plus() function to use inputs A, B.
Rik <rik@octave.org>
parents: 31105
diff changeset
6479 @deftypefnx {} {@var{C} =} plus (@var{A1}, @var{A2}, @dots{})
9e9f5f1e8ec2 doc: Update plus() function to use inputs A, B.
Rik <rik@octave.org>
parents: 31105
diff changeset
6480 This function and @w{@tcode{@var{A} + @var{B}}} are equivalent.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6481
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6482 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
6483 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
6484
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6485 @example
31141
9e9f5f1e8ec2 doc: Update plus() function to use inputs A, B.
Rik <rik@octave.org>
parents: 31105
diff changeset
6486 (@dots{}((@var{A1} + @var{A2}) + @var{A3}) + @dots{})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6487 @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
6488
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6489 @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
6490 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6491 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6492 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
6493 octave_value::op_add_eq, args);
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6494 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6495
25267
308a272bbe3c Emit an error if binary operator functions (or, plus, etc.) are called with 1 arg (bug 53450).
Rik <rik@octave.org>
parents: 25237
diff changeset
6496 /*
308a272bbe3c Emit an error if binary operator functions (or, plus, etc.) are called with 1 arg (bug 53450).
Rik <rik@octave.org>
parents: 25237
diff changeset
6497 %!assert (plus (1,1), 2)
308a272bbe3c Emit an error if binary operator functions (or, plus, etc.) are called with 1 arg (bug 53450).
Rik <rik@octave.org>
parents: 25237
diff changeset
6498 %!assert (plus (1:3, 1), 2:4)
308a272bbe3c Emit an error if binary operator functions (or, plus, etc.) are called with 1 arg (bug 53450).
Rik <rik@octave.org>
parents: 25237
diff changeset
6499 %!assert (plus (1:3, 1, 3), 5:7)
308a272bbe3c Emit an error if binary operator functions (or, plus, etc.) are called with 1 arg (bug 53450).
Rik <rik@octave.org>
parents: 25237
diff changeset
6500 %!assert (plus (1,2,3,4,5,6,7,8,9), sum (1:9))
308a272bbe3c Emit an error if binary operator functions (or, plus, etc.) are called with 1 arg (bug 53450).
Rik <rik@octave.org>
parents: 25237
diff changeset
6501
308a272bbe3c Emit an error if binary operator functions (or, plus, etc.) are called with 1 arg (bug 53450).
Rik <rik@octave.org>
parents: 25237
diff changeset
6502 ## Test input validation for all functions which use binary_assoc_op_defun_body
308a272bbe3c Emit an error if binary operator functions (or, plus, etc.) are called with 1 arg (bug 53450).
Rik <rik@octave.org>
parents: 25237
diff changeset
6503 %!error plus ()
308a272bbe3c Emit an error if binary operator functions (or, plus, etc.) are called with 1 arg (bug 53450).
Rik <rik@octave.org>
parents: 25237
diff changeset
6504 %!error plus (1)
308a272bbe3c Emit an error if binary operator functions (or, plus, etc.) are called with 1 arg (bug 53450).
Rik <rik@octave.org>
parents: 25237
diff changeset
6505 */
308a272bbe3c Emit an error if binary operator functions (or, plus, etc.) are called with 1 arg (bug 53450).
Rik <rik@octave.org>
parents: 25237
diff changeset
6506
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6507 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
6508 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6509 @deftypefn {} {@var{C} =} minus (@var{A}, @var{B})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6510 This function and @w{@tcode{@var{A} - @var{B}}} are equivalent.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6511 @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
6512 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6513 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6514 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
6515 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6516
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6517 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
6518 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6519 @deftypefn {} {@var{C} =} mtimes (@var{A}, @var{B})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6520 @deftypefnx {} {@var{C} =} mtimes (@var{A1}, @var{A2}, @dots{})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6521 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
6522
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6523 This function and @w{@tcode{@var{A} * @var{B}}} are equivalent.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6524 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
6525 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
6526
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6527 @example
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6528 (@dots{}((@var{A1} * @var{A2}) * @var{A3}) * @dots{})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6529 @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
6530
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6531 @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
6532 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6533 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6534 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
6535 octave_value::op_mul_eq, args);
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6536 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6537
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6538 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
6539 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6540 @deftypefn {} {@var{C} =} mrdivide (@var{A}, @var{B})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6541 Return the matrix right division of @var{A} and @var{B}.
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6542
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6543 This function and @w{@tcode{@var{A} / @var{B}}} are equivalent.
29825
290eff7148bb mrdivide, mldivide: Document that functions might return minimum norm solutions (bug #60839).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29817
diff changeset
6544
290eff7148bb mrdivide, mldivide: Document that functions might return minimum norm solutions (bug #60839).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29817
diff changeset
6545 If the system is not square, or if the coefficient matrix is singular, a
290eff7148bb mrdivide, mldivide: Document that functions might return minimum norm solutions (bug #60839).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29817
diff changeset
6546 minimum norm solution is computed.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6547 @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
6548 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6549 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6550 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
6551 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6552
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6553 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
6554 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6555 @deftypefn {} {@var{C} =} mpower (@var{A}, @var{B})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6556 Return the matrix power operation of @var{A} raised to the @var{B} power.
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6557
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6558 This function and @w{@tcode{@var{A} ^ @var{B}}} are equivalent.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6559 @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
6560 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6561 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6562 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
6563 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6564
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6565 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
6566 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6567 @deftypefn {} {@var{C} =} mldivide (@var{A}, @var{B})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6568 Return the matrix left division of @var{A} and @var{B}.
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6569
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6570 This function and @w{@tcode{@var{A} @backslashchar{} @var{B}}} are equivalent.
29825
290eff7148bb mrdivide, mldivide: Document that functions might return minimum norm solutions (bug #60839).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29817
diff changeset
6571
290eff7148bb mrdivide, mldivide: Document that functions might return minimum norm solutions (bug #60839).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29817
diff changeset
6572 If the system is not square, or if the coefficient matrix is singular, a
290eff7148bb mrdivide, mldivide: Document that functions might return minimum norm solutions (bug #60839).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29817
diff changeset
6573 minimum norm solution is computed.
290eff7148bb mrdivide, mldivide: Document that functions might return minimum norm solutions (bug #60839).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29817
diff changeset
6574 @seealso{mrdivide, ldivide, rdivide, linsolve}
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6575 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6576 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6577 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
6578 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6579
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6580 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
6581 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6582 @deftypefn {} {@var{TF} =} lt (@var{A}, @var{B})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6583 This function is equivalent to @w{@code{@var{A} < @var{B}}}.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6584 @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
6585 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6586 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6587 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
6588 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6589
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6590 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
6591 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6592 @deftypefn {} {@var{TF} =} le (@var{A}, @var{B})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6593 This function is equivalent to @w{@code{@var{A} <= @var{B}}}.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6594 @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
6595 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6596 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6597 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
6598 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6599
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6600 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
6601 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6602 @deftypefn {} {@var{TF} =} eq (@var{A}, @var{B})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6603 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
6604
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6605 This function is equivalent to @w{@code{@var{A} == @var{B}}}.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6606 @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
6607 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6608 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6609 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
6610 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6611
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6612 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
6613 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6614 @deftypefn {} {@var{TF} =} ge (@var{A}, @var{B})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6615 This function is equivalent to @w{@code{@var{A} >= @var{B}}}.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6616 @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
6617 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6618 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6619 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
6620 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6621
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6622 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
6623 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6624 @deftypefn {} {@var{TF} =} gt (@var{A}, @var{B})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6625 This function is equivalent to @w{@code{@var{A} > @var{B}}}.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6626 @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
6627 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6628 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6629 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
6630 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6631
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6632 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
6633 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6634 @deftypefn {} {@var{TF} =} ne (@var{A}, @var{B})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6635 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
6636
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6637 This function is equivalent to @w{@code{@var{A} != @var{B}}}.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6638 @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
6639 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6640 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6641 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
6642 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6643
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6644 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
6645 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6646 @deftypefn {} {@var{C} =} times (@var{A}, @var{B})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6647 @deftypefnx {} {@var{C} =} times (@var{A1}, @var{A2}, @dots{})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6648 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
6649
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6650 This function and @w{@tcode{@var{A} .* @var{B}}} are equivalent.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6651 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
6652 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
6653
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6654 @example
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6655 (@dots{}((@var{A1} .* @var{A2}) .* @var{A3}) .* @dots{})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6656 @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
6657
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6658 @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
6659 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6660 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6661 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
6662 octave_value::op_el_mul_eq, args);
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6663 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6664
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6665 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
6666 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6667 @deftypefn {} {@var{C} =} rdivide (@var{A}, @var{B})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6668 Return the element-by-element right division of @var{A} and @var{B}.
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6669
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6670 This function and @w{@tcode{@var{A} ./ @var{B}}} are equivalent.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6671 @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
6672 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6673 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6674 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
6675 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6676
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6677 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
6678 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6679 @deftypefn {} {@var{C} =} power (@var{A}, @var{B})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6680 Return the element-by-element operation of @var{A} raised to the
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6681 @var{B} power.
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6682
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6683 This function and @w{@tcode{@var{A} .^ @var{B}}} are equivalent.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6684
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6685 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
6686 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
6687 @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
6688
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6689 @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
6690 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6691 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6692 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
6693 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6694
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6695 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
6696 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6697 @deftypefn {} {@var{C} =} ldivide (@var{A}, @var{B})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6698 Return the element-by-element left division of @var{A} and @var{B}.
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6699
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6700 This function and @w{@tcode{@var{A} .@backslashchar{} @var{B}}} are
24618
c99163d188df doc: Use @var{} around variables in operator functions such as and, or, uplus.
Rik <rik@octave.org>
parents: 24517
diff changeset
6701 equivalent.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6702 @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
6703 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6704 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6705 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
6706 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6707
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6708 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
6709 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6710 @deftypefn {} {@var{TF} =} and (@var{x}, @var{y})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6711 @deftypefnx {} {@var{TF} =} and (@var{x1}, @var{x2}, @dots{})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6712 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
6713
24618
c99163d188df doc: Use @var{} around variables in operator functions such as and, or, uplus.
Rik <rik@octave.org>
parents: 24517
diff changeset
6714 This function is equivalent to the operator syntax
c99163d188df doc: Use @var{} around variables in operator functions such as and, or, uplus.
Rik <rik@octave.org>
parents: 24517
diff changeset
6715 @w{@code{@var{x} & @var{y}}}. If more than two arguments are given, the
c99163d188df doc: Use @var{} around variables in operator functions such as and, or, uplus.
Rik <rik@octave.org>
parents: 24517
diff changeset
6716 logical AND is applied cumulatively from left to right:
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6717
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6718 @example
24618
c99163d188df doc: Use @var{} around variables in operator functions such as and, or, uplus.
Rik <rik@octave.org>
parents: 24517
diff changeset
6719 (@dots{}((@var{x1} & @var{x2}) & @var{x3}) & @dots{})
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 @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
6721
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6722 @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
6723 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6724 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6725 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
6726 octave_value::op_el_and_eq, args);
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6727 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6728
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6729 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
6730 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6731 @deftypefn {} {@var{TF} =} or (@var{x}, @var{y})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6732 @deftypefnx {} {@var{TF} =} or (@var{x1}, @var{x2}, @dots{})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6733 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
6734
24618
c99163d188df doc: Use @var{} around variables in operator functions such as and, or, uplus.
Rik <rik@octave.org>
parents: 24517
diff changeset
6735 This function is equivalent to the operator syntax
c99163d188df doc: Use @var{} around variables in operator functions such as and, or, uplus.
Rik <rik@octave.org>
parents: 24517
diff changeset
6736 @w{@code{@var{x} | @var{y}}}. If more than two arguments are given, the
c99163d188df doc: Use @var{} around variables in operator functions such as and, or, uplus.
Rik <rik@octave.org>
parents: 24517
diff changeset
6737 logical OR is applied cumulatively from left to right:
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6738
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6739 @example
24618
c99163d188df doc: Use @var{} around variables in operator functions such as and, or, uplus.
Rik <rik@octave.org>
parents: 24517
diff changeset
6740 (@dots{}((@var{x1} | @var{x2}) | @var{x3}) | @dots{})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6741 @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
6742
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6743 @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
6744 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6745 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6746 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
6747 octave_value::op_el_or_eq, args);
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6748 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6749
19749
c913247c85a8 make colon function work (bug #44290)
John W. Eaton <jwe@octave.org>
parents: 19743
diff changeset
6750 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
6751 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
6752 @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
6753 @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
6754 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
6755 @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
6756
24618
c99163d188df doc: Use @var{} around variables in operator functions such as and, or, uplus.
Rik <rik@octave.org>
parents: 24517
diff changeset
6757 This function is equivalent to the operator syntax
c99163d188df doc: Use @var{} around variables in operator functions such as and, or, uplus.
Rik <rik@octave.org>
parents: 24517
diff changeset
6758 @w{@code{@var{base} : @var{limit}}} or
c99163d188df doc: Use @var{} around variables in operator functions such as and, or, uplus.
Rik <rik@octave.org>
parents: 24517
diff changeset
6759 @w{@code{@var{base} : @var{increment} : @var{limit}}}.
24504
5188d936c79a doc: Documentation fixes for linspace, logspace, lookup (bug #52785).
Rik <rik@octave.org>
parents: 24440
diff changeset
6760 @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
6761 @end deftypefn */)
19749
c913247c85a8 make colon function work (bug #44290)
John W. Eaton <jwe@octave.org>
parents: 19743
diff changeset
6762 {
c913247c85a8 make colon function work (bug #44290)
John W. Eaton <jwe@octave.org>
parents: 19743
diff changeset
6763 int nargin = args.length ();
c913247c85a8 make colon function work (bug #44290)
John W. Eaton <jwe@octave.org>
parents: 19743
diff changeset
6764
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6765 if (nargin < 2 || nargin > 3)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6766 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6767
28631
70cdf8de553d move non-member octave_value operator functions to octave namespace
John W. Eaton <jwe@octave.org>
parents: 28115
diff changeset
6768 return (nargin == 2
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
6769 ? colon_op (args(0), args(1))
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
6770 : 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
6771 }
c913247c85a8 make colon function work (bug #44290)
John W. Eaton <jwe@octave.org>
parents: 19743
diff changeset
6772
7065
97db94ae2cf0 [project @ 2007-10-25 05:50:55 by jwe]
jwe
parents: 7045
diff changeset
6773 static double tic_toc_timestamp = -1.0;
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6774
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6775 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
6776 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
6777 @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
6778 @deftypefnx {} {@var{id} =} tic ()
25017
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6779 Initialize a wall-clock timer.
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6780
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6781 Calling @code{tic} without an output argument resets the internal timer.
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6782 Subsequent calls to @code{toc} return the number of seconds since the timer was
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6783 set.
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6784
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6785 If called with one output argument, @code{tic} creates a new timer instance and
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6786 returns a timer identifier @var{id}. The @var{id} is a scalar of type
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6787 @code{uint64} that may be passed to @code{toc} to check elapsed time on this
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6788 timer, rather than the default internal timer.
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6789
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6790 Example 1 : benchmarking code with internal timer
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6791
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6792 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6793 @group
25017
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6794 tic;
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6795 # many computations later@dots{}
25017
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6796 elapsed_time = toc;
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6797 @end group
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6798 @end example
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6799
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6800 Example 2 : mixed timer id and internal timer
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6801
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6802 @example
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6803 @group
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6804 tic;
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6805 pause (1);
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6806 toc
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6807 @result{} Elapsed time is 1.0089 seconds.
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6808 id = tic;
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6809 pause (2);
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6810 toc (id)
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6811 @result{} Elapsed time is 2.01142 seconds.
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6812 toc
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6813 Elapsed time is 3.02308 seconds.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6814 @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
6815 @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
6816
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6817 @noindent
25017
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6818 Calling @code{tic} and @code{toc} in this way allows nested timing calls.
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6819
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6820 If you are more interested in the CPU time that your process used, you should
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6821 use the @code{cputime} function instead. The @code{tic} and @code{toc}
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6822 functions report the actual wall clock time that elapsed between the calls.
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6823 This may include time spent processing other jobs or doing nothing at all.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6824 @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
6825 @end deftypefn */)
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6826 {
20819
f428cbe7576f eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents: 20816
diff changeset
6827 if (args.length () != 0)
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6828 warning ("tic: ignoring extra arguments");
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6829
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6830 octave_value retval;
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
6831 sys::time now;
7065
97db94ae2cf0 [project @ 2007-10-25 05:50:55 by jwe]
jwe
parents: 7045
diff changeset
6832 double tmp = now.double_value ();
97db94ae2cf0 [project @ 2007-10-25 05:50:55 by jwe]
jwe
parents: 7045
diff changeset
6833
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6834 if (nargout > 0)
14635
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
6835 {
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
6836 double ip = 0.0;
23639
b488e958d024 Use modf, pow from C++ std library.
Rik <rik@octave.org>
parents: 23625
diff changeset
6837 double frac = std::modf (tmp, &ip);
14635
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
6838 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
6839 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
6840 retval = octave_uint64 (microsecs);
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
6841 }
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6842 else
7065
97db94ae2cf0 [project @ 2007-10-25 05:50:55 by jwe]
jwe
parents: 7045
diff changeset
6843 tic_toc_timestamp = tmp;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
6844
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6845 return retval;
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6846 }
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6847
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6848 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
6849 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
6850 @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
6851 @deftypefnx {} {} toc (@var{id})
25017
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6852 @deftypefnx {} {@var{elapsed_time} =} toc (@dots{})
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6853 Measure elapsed time on a wall-clock timer.
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6854
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6855 With no arguments, return the number of seconds elapsed on the internal timer
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6856 since the last call to @code{tic}.
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6857
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6858 When given the identifier @var{id} of a specific timer, return the number of
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6859 seconds elapsed since the timer @var{id} was initialized.
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6860
30377
26f2daafa270 doc: Use consistent styling for @ref, @xref, @pxref statements.
Rik <rik@octave.org>
parents: 30329
diff changeset
6861 @xref{XREFtic,,@code{tic}}, for examples of the use of @code{tic}/@code{toc}.
25017
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6862
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6863 @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
6864 @end deftypefn */)
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6865 {
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6866 int nargin = args.length ();
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6867
14635
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
6868 if (nargin > 1)
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
6869 print_usage ();
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6870
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6871 double start_time = tic_toc_timestamp;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6872
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6873 if (nargin == 1)
7065
97db94ae2cf0 [project @ 2007-10-25 05:50:55 by jwe]
jwe
parents: 7045
diff changeset
6874 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6875 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
6876
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6877 uint64_t val = id.value ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6878
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6879 start_time
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6880 = (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
6881 + 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
6882 / CLOCKS_PER_SEC);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6883
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6884 // 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
6885 // 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
6886 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
6887
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6888 if (start_time < 0)
28919
7bc983bc2cbd maint: Prepend name of function to error() messages.
Rik <rik@octave.org>
parents: 28915
diff changeset
6889 error ("toc: function called before timer initialization with tic()");
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6890
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
6891 sys::time now;
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6892
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6893 double etime = now.double_value () - start_time;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6894
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6895 octave_value retval;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6896 if (nargout > 0)
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6897 retval = etime;
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6898 else
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6899 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
6900
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6901 return retval;
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6902 }
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6903
14635
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
6904 /*
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
6905 %!shared id
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
6906 %! id = tic ();
14849
f6d3d5b0bd42 test: Use Octave coding conventions for tests for line() and toc().
Rik <octave@nomad.inbox5.com>
parents: 14846
diff changeset
6907 %!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
6908 %!assert (isa (toc (id), "double"))
14635
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
6909 */
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
6910
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6911 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
6912 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
6913 @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
6914 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
6915
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6916 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
6917 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
6918 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
6919 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
6920
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6921 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
6922 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
6923
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6924 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
6925 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
6926 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
6927 @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
6928 @end deftypefn */)
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6929 {
21078
49852ff04747 maint: Remove unnecessary declarations of retval.
Rik <rik@octave.org>
parents: 21062
diff changeset
6930 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
6931 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
6932
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
6933 sys::cpu_time cpu_tm;
21930
f0c5dd1ea2b9 hide sys/time.h, sys/times.h, and sys/resource.h headers
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
6934
f0c5dd1ea2b9 hide sys/time.h, sys/times.h, and sys/resource.h headers
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
6935 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
6936 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
6937
f0c5dd1ea2b9 hide sys/time.h, sys/times.h, and sys/resource.h headers
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
6938 return ovl (usr + sys, usr, sys);
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6939 }
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6940
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6941 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
6942 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
6943 @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
6944 @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
6945 @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
6946 @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
6947 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
6948
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6949 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
6950
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6951 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
6952
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6953 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6954 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6955 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
6956 @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
6957 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
6958 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
6959 @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
6960 @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
6961
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6962 If the optional argument @var{dim} is given, then the matrix is sorted
25471
e0906c38f18e doc: Use @var rather than @code to mark third argument to sort in docstring.
Rik <rik@octave.org>
parents: 25286
diff changeset
6963 along the dimension defined by @var{dim}. The optional argument @var{mode}
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6964 defines the order in which the values will be sorted. Valid values of
25471
e0906c38f18e doc: Use @var rather than @code to mark third argument to sort in docstring.
Rik <rik@octave.org>
parents: 25286
diff changeset
6965 @var{mode} are @qcode{"ascend"} or @qcode{"descend"}.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6967 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
6968 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
6969 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
6970
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6971 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6972 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6973 [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
6974 @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
6975 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
6976 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
6977 @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
6978 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
6979 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
6980 @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
6981 @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
6982
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6983 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
6984 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
6985
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6986 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
6987 (@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
6988 (@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
6989
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6990 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6991 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6992 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
6993 @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
6994 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
6995 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
6996 @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
6997 @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
6998
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6999 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
7000 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
7001
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7002 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
7003 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
7004 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
7005
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7006 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
7007 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
7008 @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
7009 @end deftypefn */)
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7010 {
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7011 int nargin = args.length ();
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7012
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7013 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
7014 print_usage ();
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7015
20884
f1b2a2dbc0e1 2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents: 20853
diff changeset
7016 sortmode smode = ASCENDING;
f1b2a2dbc0e1 2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents: 20853
diff changeset
7017 bool return_idx = (nargout > 1);
20921
4d3daf7e43f3 eliminate trailing whitespace in source files
John W. Eaton <jwe@octave.org>
parents: 20918
diff changeset
7018 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
7019 octave_value arg = args(0);
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7020
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7021 int dim = 0;
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7022 if (nargin > 1)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7023 {
20884
f1b2a2dbc0e1 2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents: 20853
diff changeset
7024 if (have_sortmode)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
7025 {
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
7026 std::string mode = args(1).string_value ();
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
7027 if (mode == "ascend")
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
7028 smode = ASCENDING;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
7029 else if (mode == "descend")
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
7030 smode = DESCENDING;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
7031 else
23803
90689bdbe048 Use C++11 raw string literals to avoid escaping double quotes.
Rik <rik@octave.org>
parents: 23748
diff changeset
7032 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
7033 }
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7034 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
7035 dim = args(1).nint_value () - 1;
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7036 }
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7037
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7038 if (nargin > 2)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7039 {
20884
f1b2a2dbc0e1 2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents: 20853
diff changeset
7040 if (have_sortmode)
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7041 error ("sort: DIM must be a valid dimension");
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7042
20700
68e3a747ca02 rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents: 20652
diff changeset
7043 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
7044
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7045 if (mode == "ascend")
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
7046 smode = ASCENDING;
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7047 else if (mode == "descend")
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
7048 smode = DESCENDING;
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7049 else
23803
90689bdbe048 Use C++11 raw string literals to avoid escaping double quotes.
Rik <rik@octave.org>
parents: 23748
diff changeset
7050 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
7051 }
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7052
10285
22a7913bbeb5 optimize return values of find and sort
Jaroslav Hajek <highegg@gmail.com>
parents: 10277
diff changeset
7053 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
7054 if (nargin == 1 || have_sortmode)
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7055 {
10285
22a7913bbeb5 optimize return values of find and sort
Jaroslav Hajek <highegg@gmail.com>
parents: 10277
diff changeset
7056 dim = dv.first_non_singleton ();
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7057 }
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7058 else
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7059 {
10703
5eb420d92307 fix sort and nth_element when trailing singleton dim is specified
Jaroslav Hajek <highegg@gmail.com>
parents: 10695
diff changeset
7060 if (dim < 0)
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7061 error ("sort: DIM must be a valid dimension");
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7062 }
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7063
20884
f1b2a2dbc0e1 2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents: 20853
diff changeset
7064 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
7065
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7066 if (return_idx)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7067 {
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7068 Array<octave_idx_type> sidx;
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7069
20884
f1b2a2dbc0e1 2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents: 20853
diff changeset
7070 // 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
7071 // 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
7072 retval(0) = arg.sort (sidx, dim, smode);
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
7073 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
7074 }
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7075 else
20884
f1b2a2dbc0e1 2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents: 20853
diff changeset
7076 retval = ovl (arg.sort (dim, smode));
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7077
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7078 return retval;
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7079 }
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7080
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7081 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7082 ## Double
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7083 %!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
7084 %!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
7085 %!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
7086 %!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
7087 %!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
7088 %!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
7089 %!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
7090 %!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
7091 %!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
7092 %!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
7093 %!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
7094 %!assert (sort (1), 1)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7095
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7096 %!test
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7097 %! [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
7098 %! 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
7099 %! 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
7100
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7101 ## Complex
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7102 %!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
7103 %!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
7104 %!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
7105 %!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
7106 %!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
7107 %!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
7108 %!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
7109 %!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
7110 %!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
7111 %!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
7112 %!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
7113 %!assert (sort (1i), 1i)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7114
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7115 %!test
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7116 %! [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
7117 %! 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
7118 %! 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
7119
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7120 ## Single
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7121 %!assert (sort (single ([NaN, 1, -1, 2, Inf])), single ([-1, 1, 2, Inf, NaN]))
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7122 %!assert (sort (single ([NaN, 1, -1, 2, Inf]), 1),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7123 %! single ([NaN, 1, -1, 2, Inf]))
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7124 %!assert (sort (single ([NaN, 1, -1, 2, Inf]), 2),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7125 %! single ([-1, 1, 2, Inf, NaN]))
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7126 %!assert (sort (single ([NaN, 1, -1, 2, Inf]), 3),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7127 %! single ([NaN, 1, -1, 2, Inf]))
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7128 %!assert (sort (single ([NaN, 1, -1, 2, Inf]), "ascend"),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7129 %! single ([-1, 1, 2, Inf, NaN]))
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7130 %!assert (sort (single ([NaN, 1, -1, 2, Inf]), 2, "ascend"),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7131 %! single ([-1, 1, 2, Inf, NaN]))
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7132 %!assert (sort (single ([NaN, 1, -1, 2, Inf]), "descend"),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7133 %! single ([NaN, Inf, 2, 1, -1]))
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7134 %!assert (sort (single ([NaN, 1, -1, 2, Inf]), 2, "descend"),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7135 %! single ([NaN, Inf, 2, 1, -1]))
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7136 %!assert (sort (single ([3, 1, 7, 5; 8, 2, 6, 4])),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7137 %! single ([3, 1, 6, 4; 8, 2, 7, 5]))
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7138 %!assert (sort (single ([3, 1, 7, 5; 8, 2, 6, 4]), 1),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7139 %! single ([3, 1, 6, 4; 8, 2, 7, 5]))
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7140 %!assert (sort (single ([3, 1, 7, 5; 8, 2, 6, 4]), 2),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7141 %! single ([1, 3, 5, 7; 2, 4, 6, 8]))
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7142 %!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
7143
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
7144 %!test
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7145 %! [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
7146 %! 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
7147 %! 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
7148
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7149 ## Single Complex
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7150 %!assert (sort (single ([NaN, 1i, -1, 2, Inf])), single ([1i, -1, 2, Inf, NaN]))
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7151 %!assert (sort (single ([NaN, 1i, -1, 2, Inf]), 1),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7152 %! single ([NaN, 1i, -1, 2, Inf]))
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7153 %!assert (sort (single ([NaN, 1i, -1, 2, Inf]), 2),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7154 %! single ([1i, -1, 2, Inf, NaN]))
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7155 %!assert (sort (single ([NaN, 1i, -1, 2, Inf]), 3),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7156 %! single ([NaN, 1i, -1, 2, Inf]))
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7157 %!assert (sort (single ([NaN, 1i, -1, 2, Inf]), "ascend"),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7158 %! single ([1i, -1, 2, Inf, NaN]))
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7159 %!assert (sort (single ([NaN, 1i, -1, 2, Inf]), 2, "ascend"),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7160 %! single ([1i, -1, 2, Inf, NaN]))
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7161 %!assert (sort (single ([NaN, 1i, -1, 2, Inf]), "descend"),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7162 %! single ([NaN, Inf, 2, -1, 1i]))
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7163 %!assert (sort (single ([NaN, 1i, -1, 2, Inf]), 2, "descend"),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7164 %! single ([NaN, Inf, 2, -1, 1i]))
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7165 %!assert (sort (single ([3, 1i, 7, 5; 8, 2, 6, 4])),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7166 %! single ([3, 1i, 6, 4; 8, 2, 7, 5]))
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7167 %!assert (sort (single ([3, 1i, 7, 5; 8, 2, 6, 4]), 1),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7168 %! single ([3, 1i, 6, 4; 8, 2, 7, 5]))
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7169 %!assert (sort (single ([3, 1i, 7, 5; 8, 2, 6, 4]), 2),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7170 %! single ([1i, 3, 5, 7; 2, 4, 6, 8]))
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7171 %!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
7172
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
7173 %!test
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7174 %! [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
7175 %! 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
7176 %! 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
7177
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7178 ## Bool
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7179 %!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
7180 %!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
7181 %!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
7182 %!assert (sort ([true, false, true, false], 3), [true, false, true, false])
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7183 %!assert (sort ([true, false, true, false], "ascend"),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7184 %! [false, false, true, true])
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7185 %!assert (sort ([true, false, true, false], 2, "ascend"),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7186 %! [false, false, true, true])
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7187 %!assert (sort ([true, false, true, false], "descend"),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7188 %! [true, true, false, false])
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7189 %!assert (sort ([true, false, true, false], 2, "descend"),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7190 %! [true, true, false, false])
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7191 %!assert (sort (true), true)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7192
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7193 %!test
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7194 %! [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
7195 %! 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
7196 %! 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
7197
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7198 ## Sparse Double
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7199 %!assert (sort (sparse ([0, NaN, 1, 0, -1, 2, Inf])),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7200 %! sparse ([-1, 0, 0, 1, 2, Inf, NaN]))
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7201 %!assert (sort (sparse ([0, NaN, 1, 0, -1, 2, Inf]), 1),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7202 %! sparse ([0, NaN, 1, 0, -1, 2, Inf]))
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7203 %!assert (sort (sparse ([0, NaN, 1, 0, -1, 2, Inf]), 2),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7204 %! sparse ([-1, 0, 0, 1, 2, Inf, NaN]))
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7205 %!assert (sort (sparse ([0, NaN, 1, 0, -1, 2, Inf]), 3),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7206 %! sparse ([0, NaN, 1, 0, -1, 2, Inf]))
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7207 %!assert (sort (sparse ([0, NaN, 1, 0, -1, 2, Inf]), "ascend"),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7208 %! sparse ([-1, 0, 0, 1, 2, Inf, NaN]))
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7209 %!assert (sort (sparse ([0, NaN, 1, 0, -1, 2, Inf]), 2, "ascend"),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7210 %! sparse ([-1, 0, 0, 1, 2, Inf, NaN]))
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7211 %!assert (sort (sparse ([0, NaN, 1, 0, -1, 2, Inf]), "descend"),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7212 %! sparse ([NaN, Inf, 2, 1, 0, 0, -1]))
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7213 %!assert (sort (sparse ([0, NaN, 1, 0, -1, 2, Inf]), 2, "descend"),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7214 %! sparse ([NaN, Inf, 2, 1, 0, 0, -1]))
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7215
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7216 %!shared a
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7217 %! a = randn (10, 10);
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7218 %! a(a < 0) = 0;
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7219 %!assert (sort (sparse (a)), sparse (sort (a)))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7220 %!assert (sort (sparse (a), 1), sparse (sort (a, 1)))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7221 %!assert (sort (sparse (a), 2), sparse (sort (a, 2)))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7222 %!test
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7223 %! [v, i] = sort (a);
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7224 %! [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
7225 %! assert (vs, sparse (v));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7226 %! assert (is, i);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7227
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7228 ## Sparse Complex
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7229 %!assert (sort (sparse ([0, NaN, 1i, 0, -1, 2, Inf])),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7230 %! sparse ([0, 0, 1i, -1, 2, Inf, NaN]))
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7231 %!assert (sort (sparse ([0, NaN, 1i, 0, -1, 2, Inf]), 1),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7232 %! sparse ([0, NaN, 1i, 0, -1, 2, Inf]))
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7233 %!assert (sort (sparse ([0, NaN, 1i, 0, -1, 2, Inf]), 2),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7234 %! sparse ([0, 0, 1i, -1, 2, Inf, NaN]))
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7235 %!assert (sort (sparse ([0, NaN, 1i, 0, -1, 2, Inf]), 3),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7236 %! sparse ([0, NaN, 1i, 0, -1, 2, Inf]))
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7237 %!assert (sort (sparse ([0, NaN, 1i, 0, -1, 2, Inf]), "ascend"),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7238 %! sparse ([0, 0, 1i, -1, 2, Inf, NaN]))
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7239 %!assert (sort (sparse ([0, NaN, 1i, 0, -1, 2, Inf]), 2, "ascend"),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7240 %! sparse ([0, 0, 1i, -1, 2, Inf, NaN]))
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7241 %!assert (sort (sparse ([0, NaN, 1i, 0, -1, 2, Inf]), "descend"),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7242 %! sparse ([NaN, Inf, 2, -1, 1i, 0, 0]))
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7243 %!assert (sort (sparse ([0, NaN, 1i, 0, -1, 2, Inf]), 2, "descend"),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7244 %! sparse ([NaN, Inf, 2, -1, 1i, 0, 0]))
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7245
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7246 %!shared a
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
7247 %! a = randn (10, 10);
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7248 %! a(a < 0) = 0;
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7249 %! a = 1i * a;
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7250 %!assert (sort (sparse (a)), sparse (sort (a)))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7251 %!assert (sort (sparse (a), 1), sparse (sort (a, 1)))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7252 %!assert (sort (sparse (a), 2), sparse (sort (a, 2)))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7253 %!test
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7254 %! [v, i] = sort (a);
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7255 %! [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
7256 %! assert (vs, sparse (v));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7257 %! assert (is, i);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7258
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7259 ## Sparse Bool
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7260 %!assert (sort (sparse ([true, false, true, false])),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7261 %! sparse ([false, false, true, true]))
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7262 %!assert (sort (sparse ([true, false, true, false]), 1),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7263 %! sparse ([true, false, true, false]))
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7264 %!assert (sort (sparse ([true, false, true, false]), 2),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7265 %! sparse ([false, false, true, true]))
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7266 %!assert (sort (sparse ([true, false, true, false]), 3),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7267 %! sparse ([true, false, true, false]))
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7268 %!assert (sort (sparse ([true, false, true, false]), "ascend"),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7269 %! sparse ([false, false, true, true]))
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7270 %!assert (sort (sparse ([true, false, true, false]), 2, "ascend"),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7271 %! sparse ([false, false, true, true]))
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7272 %!assert (sort (sparse ([true, false, true, false]), "descend"),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7273 %! sparse ([true, true, false, false]))
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7274 %!assert (sort (sparse ([true, false, true, false]), 2, "descend"),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7275 %! sparse ([true, true, false, false]))
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7276
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7277 %!test
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7278 %! [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
7279 %! 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
7280 %! 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
7281
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7282 ## Cell string array
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7283 %!shared a, b, c
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7284 %! a = {"Alice", "Cecile", "Eric", "Barry", "David"};
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7285 %! b = {"Alice", "Barry", "Cecile", "David", "Eric"};
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7286 %! 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
7287 %!assert (sort (a), b)
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7288 %!assert (sort (a, 1), a)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7289 %!assert (sort (a, 2), b)
10707
69c5f5ec55d7 fix invalid sort tests
Jaroslav Hajek <highegg@gmail.com>
parents: 10703
diff changeset
7290 %!assert (sort (a, 3), a)
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7291 %!assert (sort (a, "ascend"), b)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7292 %!assert (sort (a, 2, "ascend"), b)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7293 %!assert (sort (a, "descend"), c)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7294 %!assert (sort (a, 2, "descend"), c)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7295
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7296 %!test
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7297 %! [v, i] = sort (a);
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7298 %! 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
7299
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7300 %!error sort ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7301 %!error sort (1, 2, 3, 4)
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7302 */
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7303
30891
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7304 // Sort the rows of the matrix @var{a} according to the order
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7305 // specified by @var{mode}, which can either be 'ascend' or 'descend'
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7306 // and return the index vector corresponding to the sort order.
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7307 //
30892
1a3cc2811090 doc: Update documentation for __sort_rows_idx__.
Rik <rik@octave.org>
parents: 30891
diff changeset
7308 // FIXME: This function does not yet support sparse matrices.
1a3cc2811090 doc: Update documentation for __sort_rows_idx__.
Rik <rik@octave.org>
parents: 30891
diff changeset
7309
30891
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7310 DEFUN (__sort_rows_idx__, args, ,
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7311 doc: /* -*- texinfo -*-
30892
1a3cc2811090 doc: Update documentation for __sort_rows_idx__.
Rik <rik@octave.org>
parents: 30891
diff changeset
7312 @deftypefn {} {@var{idx} =} __sort_rows_idx__ (@var{A}, @var{mode})
1a3cc2811090 doc: Update documentation for __sort_rows_idx__.
Rik <rik@octave.org>
parents: 30891
diff changeset
7313 Called internally from @file{sortrows.m}.
30891
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7314 @end deftypefn */)
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7315 {
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7316 int nargin = args.length ();
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7317
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7318 if (nargin < 1 || nargin > 2)
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7319 print_usage ();
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7320
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7321 if (nargin == 2 && ! args(1).is_string ())
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7322 error ("__sort_rows_idx__: second argument must be a string");
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7323
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7324 sortmode smode = ASCENDING;
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7325 if (nargin > 1)
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7326 {
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7327 std::string mode = args(1).string_value ();
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7328 if (mode == "ascend")
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7329 smode = ASCENDING;
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7330 else if (mode == "descend")
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7331 smode = DESCENDING;
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7332 else
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7333 error (R"(__sort_rows_idx__: MODE must be either "ascend" or "descend")");
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7334 }
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7335
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7336 octave_value arg = args(0);
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7337
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7338 if (arg.issparse ())
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7339 error ("__sort_rows_idx__: sparse matrices not yet supported");
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7340
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7341 if (arg.ndims () != 2)
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7342 error ("__sort_rows_idx__: needs a 2-D object");
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7343
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7344 Array<octave_idx_type> idx = arg.sort_rows_idx (smode);
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7345
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7346 // This cannot be ovl(), relies on special overloaded octave_value call.
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7347 return octave_value (idx, true, true);
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7348 }
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7349
9765
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7350 static sortmode
20720
7c21b151b8b4 build: Fix warning messages from compiler.
Rik <rik@octave.org>
parents: 20711
diff changeset
7351 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
7352 {
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
7353 // 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
7354 // about possibly using sortmode uninitialized.
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
7355 // 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
7356 sortmode smode = UNSORTED;
9765
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7357
20711
7b608fadc663 Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents: 20704
diff changeset
7358 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
7359
25484
b7db401e1a99 Use "ascend"/"descend" for issorted direction (bug #54147).
Rik <rik@octave.org>
parents: 25473
diff changeset
7360 if (mode == "ascend")
20582
ba2b07c13913 use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents: 20574
diff changeset
7361 smode = ASCENDING;
25484
b7db401e1a99 Use "ascend"/"descend" for issorted direction (bug #54147).
Rik <rik@octave.org>
parents: 25473
diff changeset
7362 else if (mode == "descend")
20582
ba2b07c13913 use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents: 20574
diff changeset
7363 smode = DESCENDING;
ba2b07c13913 use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents: 20574
diff changeset
7364 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
7365 smode = UNSORTED;
9765
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7366 else
25484
b7db401e1a99 Use "ascend"/"descend" for issorted direction (bug #54147).
Rik <rik@octave.org>
parents: 25473
diff changeset
7367 error (R"(issorted: MODE must be "ascend", "descend", or "either")");
9765
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7368
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7369 return smode;
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7370 }
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7371
8721
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
7372 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
7373 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
7374 @deftypefn {} {@var{tf} =} issorted (@var{A})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
7375 @deftypefnx {} {@var{tf} =} issorted (@var{A}, @var{mode})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
7376 @deftypefnx {} {@var{tf} =} issorted (@var{A}, "rows", @var{mode})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
7377 Return true if the vector @var{A} is sorted according to @var{mode}, which
30594
0cb3f48da9da doc: clarifies issorted only operates on vectors (bug #61765)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents: 30565
diff changeset
7378 may be either @qcode{"ascend"}, @qcode{"descend"}, or @qcode{"either"}.
27034
df32e0cf0992 doc: Fix names of options in issorted (bug #56087).
Rik <rik@octave.org>
parents: 26376
diff changeset
7379
df32e0cf0992 doc: Fix names of options in issorted (bug #56087).
Rik <rik@octave.org>
parents: 26376
diff changeset
7380 By default, @var{mode} is @qcode{"ascend"}. NaNs are treated in the same
df32e0cf0992 doc: Fix names of options in issorted (bug #56087).
Rik <rik@octave.org>
parents: 26376
diff changeset
7381 manner as @code{sort}.
df32e0cf0992 doc: Fix names of options in issorted (bug #56087).
Rik <rik@octave.org>
parents: 26376
diff changeset
7382
30594
0cb3f48da9da doc: clarifies issorted only operates on vectors (bug #61765)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents: 30565
diff changeset
7383 If the optional argument @qcode{"rows"} is supplied, check whether the matrix
0cb3f48da9da doc: clarifies issorted only operates on vectors (bug #61765)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents: 30565
diff changeset
7384 is sorted by rows as output by the function @code{sortrows} (with no options).
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7385
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7386 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
7387 @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
7388 @end deftypefn */)
8721
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
7389 {
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
7390 int nargin = args.length ();
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
7391
9765
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7392 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
7393 print_usage ();
9765
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7394
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7395 bool by_rows = false;
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7396
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7397 sortmode smode = ASCENDING;
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7398
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7399 if (nargin > 1)
8721
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
7400 {
9765
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7401 if (nargin == 3)
20720
7c21b151b8b4 build: Fix warning messages from compiler.
Rik <rik@octave.org>
parents: 20711
diff changeset
7402 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
7403
20700
68e3a747ca02 rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents: 20652
diff changeset
7404 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
7405 if (tmp == "rows")
ba2b07c13913 use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents: 20574
diff changeset
7406 by_rows = true;
9765
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7407 else
20720
7c21b151b8b4 build: Fix warning messages from compiler.
Rik <rik@octave.org>
parents: 20711
diff changeset
7408 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
7409 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
7410
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7411 octave_value retval;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7412
9765
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7413 octave_value arg = args(0);
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7414
25850
153495e05477 issorted: return true on an empty array (bug #54599)
Mike Miller <mtmiller@octave.org>
parents: 25646
diff changeset
7415 if (arg.isempty ())
153495e05477 issorted: return true on an empty array (bug #54599)
Mike Miller <mtmiller@octave.org>
parents: 25646
diff changeset
7416 retval = true;
153495e05477 issorted: return true on an empty array (bug #54599)
Mike Miller <mtmiller@octave.org>
parents: 25646
diff changeset
7417 else if (by_rows)
9765
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7418 {
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
7419 if (arg.issparse ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
7420 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
7421
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7422 if (arg.ndims () != 2)
21014
b9d4c3615e89 maint: Capitalize D for dimension in messages and comments.
Rik <rik@octave.org>
parents: 20980
diff changeset
7423 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
7424
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7425 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
7426 }
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7427 else
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7428 {
23592
80e3bfb7bd5a maint: Deprecate is_vector and replace with isvector.
Rik <rik@octave.org>
parents: 23588
diff changeset
7429 if (! arg.dims ().isvector ())
8721
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
7430 error ("issorted: needs a vector");
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7431
23588
0549061d35b9 maint: Deprecate is_sorted and replace with issorted.
Rik <rik@octave.org>
parents: 23587
diff changeset
7432 retval = args(0).issorted (smode) != UNSORTED;
8721
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
7433 }
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
7434
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
7435 return retval;
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
7436 }
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
7437
9765
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7438 /*
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7439 %!shared sm, um, sv, uv
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7440 %! sm = [1, 2; 3, 4];
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7441 %! um = [3, 1; 2, 4];
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7442 %! sv = [1, 2, 3, 4];
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7443 %! uv = [2, 1, 4, 3];
20809
9e9892519a7c Add more BIST tests for issorted.
Rik <rik@octave.org>
parents: 20806
diff changeset
7444
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7445 %!assert (issorted (sm, "rows"))
20809
9e9892519a7c Add more BIST tests for issorted.
Rik <rik@octave.org>
parents: 20806
diff changeset
7446 %!assert (! issorted (um, "rows"))
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7447 %!assert (issorted (sv))
20809
9e9892519a7c Add more BIST tests for issorted.
Rik <rik@octave.org>
parents: 20806
diff changeset
7448 %!assert (! issorted (uv))
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7449 %!assert (issorted (sv'))
20809
9e9892519a7c Add more BIST tests for issorted.
Rik <rik@octave.org>
parents: 20806
diff changeset
7450 %!assert (! issorted (uv'))
25484
b7db401e1a99 Use "ascend"/"descend" for issorted direction (bug #54147).
Rik <rik@octave.org>
parents: 25473
diff changeset
7451 %!assert (issorted (sm, "rows", "ascend"))
b7db401e1a99 Use "ascend"/"descend" for issorted direction (bug #54147).
Rik <rik@octave.org>
parents: 25473
diff changeset
7452 %!assert (! issorted (um, "rows", "ascend"))
b7db401e1a99 Use "ascend"/"descend" for issorted direction (bug #54147).
Rik <rik@octave.org>
parents: 25473
diff changeset
7453 %!assert (issorted (sv, "ascend"))
b7db401e1a99 Use "ascend"/"descend" for issorted direction (bug #54147).
Rik <rik@octave.org>
parents: 25473
diff changeset
7454 %!assert (! issorted (uv, "ascend"))
b7db401e1a99 Use "ascend"/"descend" for issorted direction (bug #54147).
Rik <rik@octave.org>
parents: 25473
diff changeset
7455 %!assert (issorted (sv', "ascend"))
b7db401e1a99 Use "ascend"/"descend" for issorted direction (bug #54147).
Rik <rik@octave.org>
parents: 25473
diff changeset
7456 %!assert (! issorted (uv', "ascend"))
b7db401e1a99 Use "ascend"/"descend" for issorted direction (bug #54147).
Rik <rik@octave.org>
parents: 25473
diff changeset
7457 %!assert (! issorted (sm, "rows", "descend"))
b7db401e1a99 Use "ascend"/"descend" for issorted direction (bug #54147).
Rik <rik@octave.org>
parents: 25473
diff changeset
7458 %!assert (issorted (flipud (sm), "rows", "descend"))
b7db401e1a99 Use "ascend"/"descend" for issorted direction (bug #54147).
Rik <rik@octave.org>
parents: 25473
diff changeset
7459 %!assert (! issorted (sv, "descend"))
b7db401e1a99 Use "ascend"/"descend" for issorted direction (bug #54147).
Rik <rik@octave.org>
parents: 25473
diff changeset
7460 %!assert (issorted (fliplr (sv), "descend"))
b7db401e1a99 Use "ascend"/"descend" for issorted direction (bug #54147).
Rik <rik@octave.org>
parents: 25473
diff changeset
7461 %!assert (! issorted (sv', "descend"))
b7db401e1a99 Use "ascend"/"descend" for issorted direction (bug #54147).
Rik <rik@octave.org>
parents: 25473
diff changeset
7462 %!assert (issorted (fliplr (sv)', "descend"))
20809
9e9892519a7c Add more BIST tests for issorted.
Rik <rik@octave.org>
parents: 20806
diff changeset
7463 %!assert (! issorted (um, "rows", "either"))
9e9892519a7c Add more BIST tests for issorted.
Rik <rik@octave.org>
parents: 20806
diff changeset
7464 %!assert (! issorted (uv, "either"))
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7465 %!assert (issorted (sm, "rows", "either"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7466 %!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
7467 %!assert (issorted (sv, "either"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7468 %!assert (issorted (fliplr (sv), "either"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7469 %!assert (issorted (sv', "either"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7470 %!assert (issorted (fliplr (sv)', "either"))
20809
9e9892519a7c Add more BIST tests for issorted.
Rik <rik@octave.org>
parents: 20806
diff changeset
7471
25850
153495e05477 issorted: return true on an empty array (bug #54599)
Mike Miller <mtmiller@octave.org>
parents: 25646
diff changeset
7472 %!assert (issorted ([]))
153495e05477 issorted: return true on an empty array (bug #54599)
Mike Miller <mtmiller@octave.org>
parents: 25646
diff changeset
7473 %!assert (issorted ([], "rows"))
153495e05477 issorted: return true on an empty array (bug #54599)
Mike Miller <mtmiller@octave.org>
parents: 25646
diff changeset
7474 %!assert (issorted ([], "ascend"))
153495e05477 issorted: return true on an empty array (bug #54599)
Mike Miller <mtmiller@octave.org>
parents: 25646
diff changeset
7475 %!assert (issorted ([], "rows", "ascend"))
153495e05477 issorted: return true on an empty array (bug #54599)
Mike Miller <mtmiller@octave.org>
parents: 25646
diff changeset
7476 %!assert (issorted ([], "descend"))
153495e05477 issorted: return true on an empty array (bug #54599)
Mike Miller <mtmiller@octave.org>
parents: 25646
diff changeset
7477 %!assert (issorted ([], "rows", "descend"))
153495e05477 issorted: return true on an empty array (bug #54599)
Mike Miller <mtmiller@octave.org>
parents: 25646
diff changeset
7478 %!assert (issorted ({}))
153495e05477 issorted: return true on an empty array (bug #54599)
Mike Miller <mtmiller@octave.org>
parents: 25646
diff changeset
7479 %!assert (issorted ({}, "rows"))
153495e05477 issorted: return true on an empty array (bug #54599)
Mike Miller <mtmiller@octave.org>
parents: 25646
diff changeset
7480 %!assert (issorted ({}, "ascend"))
153495e05477 issorted: return true on an empty array (bug #54599)
Mike Miller <mtmiller@octave.org>
parents: 25646
diff changeset
7481 %!assert (issorted ({}, "rows", "ascend"))
153495e05477 issorted: return true on an empty array (bug #54599)
Mike Miller <mtmiller@octave.org>
parents: 25646
diff changeset
7482 %!assert (issorted ({}, "descend"))
153495e05477 issorted: return true on an empty array (bug #54599)
Mike Miller <mtmiller@octave.org>
parents: 25646
diff changeset
7483 %!assert (issorted ({}, "rows", "descend"))
153495e05477 issorted: return true on an empty array (bug #54599)
Mike Miller <mtmiller@octave.org>
parents: 25646
diff changeset
7484 %!assert (issorted (""))
153495e05477 issorted: return true on an empty array (bug #54599)
Mike Miller <mtmiller@octave.org>
parents: 25646
diff changeset
7485 %!assert (issorted ("", "rows"))
153495e05477 issorted: return true on an empty array (bug #54599)
Mike Miller <mtmiller@octave.org>
parents: 25646
diff changeset
7486 %!assert (issorted ("", "ascend"))
153495e05477 issorted: return true on an empty array (bug #54599)
Mike Miller <mtmiller@octave.org>
parents: 25646
diff changeset
7487 %!assert (issorted ("", "rows", "ascend"))
153495e05477 issorted: return true on an empty array (bug #54599)
Mike Miller <mtmiller@octave.org>
parents: 25646
diff changeset
7488 %!assert (issorted ("", "descend"))
153495e05477 issorted: return true on an empty array (bug #54599)
Mike Miller <mtmiller@octave.org>
parents: 25646
diff changeset
7489 %!assert (issorted ("", "rows", "descend"))
20809
9e9892519a7c Add more BIST tests for issorted.
Rik <rik@octave.org>
parents: 20806
diff changeset
7490
9e9892519a7c Add more BIST tests for issorted.
Rik <rik@octave.org>
parents: 20806
diff changeset
7491 ## 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
7492 %!error issorted ()
f1b2a2dbc0e1 2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents: 20853
diff changeset
7493 %!error issorted (1,2,3,4)
20809
9e9892519a7c Add more BIST tests for issorted.
Rik <rik@octave.org>
parents: 20806
diff changeset
7494 %!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
7495 %!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
7496 %!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
7497 %!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
7498 %!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
7499 */
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7500
9725
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7501 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
7502 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
7503 @deftypefn {} {@var{nel} =} nth_element (@var{x}, @var{n})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
7504 @deftypefnx {} {@var{nel} =} nth_element (@var{x}, @var{n}, @var{dim})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7505 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
7506 @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
7507
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7508 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
7509
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7510 @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
7511 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
7512
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7513 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
7514 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
7515 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
7516
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7517 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
7518 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
7519 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
7520 @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
7521 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
7522 @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
7523 @end deftypefn */)
9725
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7524 {
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7525 int nargin = args.length ();
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7526
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7527 if (nargin < 2 || nargin > 3)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7528 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7529
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7530 int dim = -1;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7531 if (nargin == 3)
9725
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7532 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7533 dim = args(2).int_value (true) - 1;
9725
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7534 if (dim < 0)
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7535 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
7536 }
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7537
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7538 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
7539 if (dim < 0)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7540 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
7541
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7542 octave_value retval;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7543
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7544 try
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7545 {
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
7546 idx_vector n = args(1).index_vector ();
9725
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7547
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7548 switch (argx.builtin_type ())
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7549 {
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7550 case btyp_double:
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7551 retval = argx.array_value ().nth_element (n, dim);
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7552 break;
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7553 case btyp_float:
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7554 retval = argx.float_array_value ().nth_element (n, dim);
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7555 break;
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7556 case btyp_complex:
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7557 retval = argx.complex_array_value ().nth_element (n, dim);
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7558 break;
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7559 case btyp_float_complex:
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7560 retval = argx.float_complex_array_value ().nth_element (n, dim);
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7561 break;
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
7562
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
7563 #define MAKE_INT_BRANCH(X) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
7564 case btyp_ ## X: \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
7565 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
7566 break;
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7567
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7568 MAKE_INT_BRANCH (int8);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7569 MAKE_INT_BRANCH (int16);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7570 MAKE_INT_BRANCH (int32);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7571 MAKE_INT_BRANCH (int64);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7572 MAKE_INT_BRANCH (uint8);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7573 MAKE_INT_BRANCH (uint16);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7574 MAKE_INT_BRANCH (uint32);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7575 MAKE_INT_BRANCH (uint64);
21540
ffb4770ba079 Make median preserve discrete types (bug #47515).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21458
diff changeset
7576 MAKE_INT_BRANCH (bool);
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
7577
9725
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7578 #undef MAKE_INT_BRANCH
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
7579
9725
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7580 default:
23575
e95738a119da maint: Deprecate is_cellstr and replace with iscellstr.
Rik <rik@octave.org>
parents: 23573
diff changeset
7581 if (argx.iscellstr ())
9725
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7582 retval = argx.cellstr_value ().nth_element (n, dim);
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7583 else
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21078
diff changeset
7584 err_wrong_type_arg ("nth_element", argx);
9725
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7585 }
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7586 }
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
7587 catch (const index_exception& ie)
29163
8f67ad8b3103 maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents: 29117
diff changeset
7588 {
8f67ad8b3103 maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents: 29117
diff changeset
7589 error ("nth_element: invalid index %s", ie.what ());
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7590 }
9725
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7591
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7592 return retval;
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7593 }
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7594
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
7595 /*
3e93a2a66cdf nth_element: allow sequence of indices to be passed as a vector (bug #51329)
Brad Kennedy <bk@co60.ca>
parents: 23693
diff changeset
7596 %!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
7597 %!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
7598 %!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
7599 %!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
7600
3e93a2a66cdf nth_element: allow sequence of indices to be passed as a vector (bug #51329)
Brad Kennedy <bk@co60.ca>
parents: 23693
diff changeset
7601 %!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
7602
3e93a2a66cdf nth_element: allow sequence of indices to be passed as a vector (bug #51329)
Brad Kennedy <bk@co60.ca>
parents: 23693
diff changeset
7603 %!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
7604 %!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
7605 %!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
7606 %!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
7607 %!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
7608 */
3e93a2a66cdf nth_element: allow sequence of indices to be passed as a vector (bug #51329)
Brad Kennedy <bk@co60.ca>
parents: 23693
diff changeset
7609
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
7610 template <typename NDT>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
7611 static NDT
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
7612 do_accumarray_sum (const idx_vector& idx, const NDT& vals,
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7613 octave_idx_type n = -1)
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7614 {
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7615 typedef typename NDT::element_type T;
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7616 if (n < 0)
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7617 n = idx.extent (0);
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7618 else if (idx.extent (n) > n)
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7619 error ("accumarray: index out of range");
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7620
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
7621 NDT retval (dim_vector (n, 1), T ());
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7622
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7623 if (vals.numel () == 1)
9858
47c5af1868df move idx_add methods to MArrayN
Jaroslav Hajek <highegg@gmail.com>
parents: 9856
diff changeset
7624 retval.idx_add (idx, vals (0));
47c5af1868df move idx_add methods to MArrayN
Jaroslav Hajek <highegg@gmail.com>
parents: 9856
diff changeset
7625 else if (vals.numel () == idx.length (n))
47c5af1868df move idx_add methods to MArrayN
Jaroslav Hajek <highegg@gmail.com>
parents: 9856
diff changeset
7626 retval.idx_add (idx, vals);
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7627 else
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7628 error ("accumarray: dimensions mismatch");
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7629
9858
47c5af1868df move idx_add methods to MArrayN
Jaroslav Hajek <highegg@gmail.com>
parents: 9856
diff changeset
7630 return retval;
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7631 }
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7632
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7633 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
7634 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
7635 @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
7636 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
7637 @end deftypefn */)
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7638 {
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7639 int nargin = args.length ();
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7640
22789
bedfedcd878e norm: fix error in input argument validation leading to segfault (bug #49634)
Mike Miller <mtmiller@octave.org>
parents: 22749
diff changeset
7641 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
7642 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7643
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23585
diff changeset
7644 if (! args(0).isnumeric ())
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7645 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
7646
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7647 octave_value retval;
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7648
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7649 try
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7650 {
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
7651 idx_vector idx = args(0).index_vector ();
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7652 octave_idx_type n = -1;
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7653 if (nargin == 3)
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7654 n = args(2).idx_type_value (true);
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7655
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7656 octave_value vals = args(1);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7657
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7658 if (vals.is_range ())
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7659 {
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
7660 range<double> r = vals.range_value ();
28636
a3db48e66ef8 use Range::increment instead of Range::inc
John W. Eaton <jwe@octave.org>
parents: 28631
diff changeset
7661 if (r.increment () == 0)
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7662 vals = r.base ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7663 }
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7664
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7665 if (vals.is_single_type ())
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7666 {
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
7667 if (vals.iscomplex ())
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7668 retval = do_accumarray_sum (idx,
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7669 vals.float_complex_array_value (),
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7670 n);
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7671 else
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7672 retval = do_accumarray_sum (idx, vals.float_array_value (), n);
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7673 }
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23585
diff changeset
7674 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
7675 {
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
7676 if (vals.iscomplex ())
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7677 retval = do_accumarray_sum (idx,
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7678 vals.complex_array_value (),
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7679 n);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7680 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7681 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
7682 }
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7683 else
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21078
diff changeset
7684 err_wrong_type_arg ("accumarray", vals);
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7685 }
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
7686 catch (const index_exception& ie)
29163
8f67ad8b3103 maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents: 29117
diff changeset
7687 {
8f67ad8b3103 maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents: 29117
diff changeset
7688 error ("__accumarray_sum__: invalid index %s", ie.what ());
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7689 }
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7690
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
7691 return retval;
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7692 }
8721
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
7693
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
7694 template <typename NDT>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
7695 static NDT
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
7696 do_accumarray_minmax (const idx_vector& idx, const NDT& vals,
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7697 octave_idx_type n, bool ismin,
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7698 const typename NDT::element_type& zero_val)
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7699 {
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7700 typedef typename NDT::element_type T;
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7701 if (n < 0)
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7702 n = idx.extent (0);
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7703 else if (idx.extent (n) > n)
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7704 error ("accumarray: index out of range");
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7705
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7706 NDT retval (dim_vector (n, 1), zero_val);
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7707
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7708 // Pick minimizer or maximizer.
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
7709 void (MArray<T>::*op) (const idx_vector&, const MArray<T>&)
27277
db687716fed6 style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents: 27081
diff changeset
7710 = ismin ? (&MArray<T>::idx_min) : (&MArray<T>::idx_max);
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7711
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7712 octave_idx_type l = idx.length (n);
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7713 if (vals.numel () == 1)
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7714 (retval.*op) (idx, NDT (dim_vector (l, 1), vals(0)));
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7715 else if (vals.numel () == l)
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7716 (retval.*op) (idx, vals);
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7717 else
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7718 error ("accumarray: dimensions mismatch");
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7719
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7720 return retval;
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7721 }
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7722
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7723 static octave_value_list
30896
c9788d7f6e65 maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents: 30892
diff changeset
7724 do_accumarray_minmax_fcn (const octave_value_list& args,
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7725 bool ismin)
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7726 {
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7727 int nargin = args.length ();
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7728
22789
bedfedcd878e norm: fix error in input argument validation leading to segfault (bug #49634)
Mike Miller <mtmiller@octave.org>
parents: 22749
diff changeset
7729 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
7730 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7731
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23585
diff changeset
7732 if (! args(0).isnumeric ())
20811
5979314bb15a Fix BIST tests for rows.
Rik <rik@octave.org>
parents: 20810
diff changeset
7733 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
7734
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7735 octave_value retval;
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7736
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7737 try
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7738 {
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
7739 idx_vector idx = args(0).index_vector ();
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7740 octave_idx_type n = -1;
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7741 if (nargin == 4)
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7742 n = args(3).idx_type_value (true);
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7743
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7744 octave_value vals = args(1);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7745 octave_value zero = args(2);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7746
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7747 switch (vals.builtin_type ())
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7748 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7749 case btyp_double:
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7750 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
7751 zero.double_value ());
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7752 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7753
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7754 case btyp_float:
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7755 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
7756 ismin, zero.float_value ());
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7757 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7758
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7759 case btyp_complex:
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7760 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
7761 n, ismin, zero.complex_value ());
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7762 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7763
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7764 case btyp_float_complex:
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7765 retval = do_accumarray_minmax (idx,
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7766 vals.float_complex_array_value (),
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7767 n, ismin,
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7768 zero.float_complex_value ());
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7769 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7770
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
7771 #define MAKE_INT_BRANCH(X) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
7772 case btyp_ ## X: \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
7773 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
7774 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
7775 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7776
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7777 MAKE_INT_BRANCH (int8);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7778 MAKE_INT_BRANCH (int16);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7779 MAKE_INT_BRANCH (int32);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7780 MAKE_INT_BRANCH (int64);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7781 MAKE_INT_BRANCH (uint8);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7782 MAKE_INT_BRANCH (uint16);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7783 MAKE_INT_BRANCH (uint32);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7784 MAKE_INT_BRANCH (uint64);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7785
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7786 #undef MAKE_INT_BRANCH
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7787
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7788 case btyp_bool:
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7789 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
7790 zero.bool_value ());
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7791 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7792
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7793 default:
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21078
diff changeset
7794 err_wrong_type_arg ("accumarray", vals);
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7795 }
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7796 }
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
7797 catch (const index_exception& ie)
29163
8f67ad8b3103 maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents: 29117
diff changeset
7798 {
30896
c9788d7f6e65 maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents: 30892
diff changeset
7799 error ("do_accumarray_minmax_fcn: invalid index %s", ie.what ());
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7800 }
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7801
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
7802 return retval;
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7803 }
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7804
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7805 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
7806 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
7807 @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
7808 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
7809 @end deftypefn */)
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7810 {
30896
c9788d7f6e65 maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents: 30892
diff changeset
7811 return do_accumarray_minmax_fcn (args, true);
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7812 }
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7813
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7814 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
7815 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
7816 @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
7817 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
7818 @end deftypefn */)
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7819 {
30896
c9788d7f6e65 maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents: 30892
diff changeset
7820 return do_accumarray_minmax_fcn (args, false);
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7821 }
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7822
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
7823 template <typename NDT>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
7824 static NDT
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
7825 do_accumdim_sum (const idx_vector& idx, const NDT& vals,
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7826 int dim = -1, octave_idx_type n = -1)
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7827 {
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7828 typedef typename NDT::element_type T;
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7829 if (n < 0)
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7830 n = idx.extent (0);
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7831 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
7832 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
7833
18100
6a71e5030df5 Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents: 17915
diff changeset
7834 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
7835 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
7836
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7837 if (dim < 0)
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7838 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
7839 else if (dim >= rdv.ndims ())
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7840 rdv.resize (dim+1, 1);
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7841
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7842 rdv(dim) = n;
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7843
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
7844 NDT retval (rdv, T ());
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7845
14113
dac62c415e8b Do more error checking on accumarray and accumdim input.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14100
diff changeset
7846 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
7847 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
7848
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7849 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
7850
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7851 return retval;
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7852 }
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7853
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7854 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
7855 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
7856 @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
7857 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
7858 @end deftypefn */)
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7859 {
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7860 int nargin = args.length ();
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7861
22789
bedfedcd878e norm: fix error in input argument validation leading to segfault (bug #49634)
Mike Miller <mtmiller@octave.org>
parents: 22749
diff changeset
7862 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
7863 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7864
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23585
diff changeset
7865 if (! args(0).isnumeric ())
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7866 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
7867
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7868 octave_value retval;
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7869
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7870 try
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7871 {
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
7872 idx_vector idx = args(0).index_vector ();
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7873 int dim = -1;
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7874 if (nargin >= 3)
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7875 dim = args(2).int_value () - 1;
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7876
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7877 octave_idx_type n = -1;
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7878 if (nargin == 4)
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7879 n = args(3).idx_type_value (true);
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7880
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7881 octave_value vals = args(1);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7882
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7883 if (vals.is_single_type ())
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7884 {
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
7885 if (vals.iscomplex ())
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7886 retval = do_accumdim_sum (idx,
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7887 vals.float_complex_array_value (),
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7888 dim, n);
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7889 else
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7890 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
7891 dim, n);
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7892 }
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23585
diff changeset
7893 else if (vals.isnumeric () || vals.islogical ())
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7894 {
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
7895 if (vals.iscomplex ())
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7896 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
7897 dim, n);
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7898 else
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7899 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
7900 }
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7901 else
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21078
diff changeset
7902 err_wrong_type_arg ("accumdim", vals);
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7903 }
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
7904 catch (const index_exception& ie)
29163
8f67ad8b3103 maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents: 29117
diff changeset
7905 {
8f67ad8b3103 maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents: 29117
diff changeset
7906 error ("__accumdim_sum__: invalid index %s", ie.what ());
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7907 }
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7908
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
7909 return retval;
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7910 }
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7911
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
7912 template <typename NDT>
9473
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7913 static NDT
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7914 do_merge (const Array<bool>& mask,
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7915 const NDT& tval, const NDT& fval)
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7916 {
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7917 typedef typename NDT::element_type T;
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7918 dim_vector dv = mask.dims ();
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7919 NDT retval (dv);
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7920
18100
6a71e5030df5 Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents: 17915
diff changeset
7921 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
7922 bool fscl = fval.numel () == 1;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
7923
21055
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7924 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
7925 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
7926
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7927 T *rv = retval.fortran_vec ();
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7928 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
7929
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7930 const T *tv = tval.data ();
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7931 const T *fv = fval.data ();
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7932 const bool *mv = mask.data ();
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7933
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7934 if (tscl)
9473
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7935 {
21055
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7936 if (fscl)
9473
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7937 {
21055
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7938 T ts = tv[0];
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7939 T fs = fv[0];
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7940 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
7941 rv[i] = (mv[i] ? ts : fs);
9473
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7942 }
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7943 else
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7944 {
21055
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7945 T ts = tv[0];
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7946 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
7947 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
7948 }
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7949 }
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7950 else
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7951 {
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7952 if (fscl)
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7953 {
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7954 T fs = fv[0];
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7955 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
7956 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
7957 }
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7958 else
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7959 {
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7960 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
7961 rv[i] = (mv[i] ? tv[i] : fv[i]);
9473
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7962 }
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7963 }
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7964
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7965 return retval;
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7966 }
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7967
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
7968 #define MAKE_INT_BRANCH(INTX) \
9473
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7969 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
7970 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
7971 retval = do_merge (mask, \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
7972 tval.INTX ## _array_value (), \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
7973 fval.INTX ## _array_value ()); \
9473
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7974 }
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7975
9505
a321a1c227c8 make ifelse an alias or merge
Jaroslav Hajek <highegg@gmail.com>
parents: 9475
diff changeset
7976 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
7977 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
7978 @deftypefn {} {@var{M} =} merge (@var{mask}, @var{tval}, @var{fval})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
7979 @deftypefnx {} {@var{M} =} ifelse (@var{mask}, @var{tval}, @var{fval})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7980 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
7981 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
7982
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7983 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
7984 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
7985 @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
7986 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
7987 @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
7988
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7989 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
7990 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
7991 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
7992
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7993 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7994 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7995 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
7996 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
7997 @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
7998 @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
7999
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
8000 @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
8001 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
8002 @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
8003 @end deftypefn */)
9473
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
8004 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8005 if (args.length () != 3)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8006 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8007
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23585
diff changeset
8008 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
8009 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
8010
9473
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
8011 octave_value retval;
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
8012
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8013 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
8014
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8015 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
8016 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
8017 else
9473
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
8018 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8019 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
8020
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8021 octave_value tval = args(1);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8022 octave_value fval = args(2);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8023
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8024 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
8025 {
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
8026 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
8027 retval = do_merge (mask,
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8028 tval.complex_array_value (),
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8029 fval.complex_array_value ());
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8030 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8031 retval = do_merge (mask,
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8032 tval.array_value (),
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8033 fval.array_value ());
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8034 }
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8035 else if (tval.is_single_type () && fval.is_single_type ())
9473
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
8036 {
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
8037 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
8038 retval = do_merge (mask,
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8039 tval.float_complex_array_value (),
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8040 fval.float_complex_array_value ());
9473
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
8041 else
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8042 retval = do_merge (mask,
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8043 tval.float_array_value (),
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8044 fval.float_array_value ());
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8045 }
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8046 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
8047 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8048 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
8049 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
8050 tval.char_array_value (),
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8051 fval.char_array_value ()),
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8052 sq_string ? '\'' : '"');
9473
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
8053 }
23576
00e518162fda maint: Deprecate is_cell and replace with iscell.
Rik <rik@octave.org>
parents: 23575
diff changeset
8054 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
8055 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8056 retval = do_merge (mask,
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8057 tval.cell_value (),
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8058 fval.cell_value ());
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8059 }
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8060
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
8061 MAKE_INT_BRANCH (int8)
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
8062 MAKE_INT_BRANCH (int16)
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
8063 MAKE_INT_BRANCH (int32)
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
8064 MAKE_INT_BRANCH (int64)
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
8065 MAKE_INT_BRANCH (uint8)
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
8066 MAKE_INT_BRANCH (uint16)
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
8067 MAKE_INT_BRANCH (uint32)
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
8068 MAKE_INT_BRANCH (uint64)
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8069
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8070 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8071 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
8072 tval.class_name ().c_str (),
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8073 fval.class_name ().c_str ());
9473
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
8074 }
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
8075
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
8076 return retval;
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
8077 }
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
8078
9505
a321a1c227c8 make ifelse an alias or merge
Jaroslav Hajek <highegg@gmail.com>
parents: 9475
diff changeset
8079 DEFALIAS (ifelse, merge);
a321a1c227c8 make ifelse an alias or merge
Jaroslav Hajek <highegg@gmail.com>
parents: 9475
diff changeset
8080
9473
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
8081 #undef MAKE_INT_BRANCH
8721
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
8082
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
8083 template <typename SparseT>
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8084 static SparseT
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8085 do_sparse_diff (const SparseT& array, octave_idx_type order,
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8086 int dim)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8087 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8088 SparseT retval = array;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8089 if (dim == 1)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8090 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8091 octave_idx_type k = retval.columns ();
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8092 while (order > 0 && k > 0)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8093 {
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
8094 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
8095 retval = SparseT (retval.index (col1, sl1))
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
8096 - SparseT (retval.index (col2, sl2));
30723
08b08b7f05b2 Replace direct calls to C library assert() with Octave specialty functions in libinterp/ (bug #61753)
Arun Giridhar <arungiridhar@gmail.com> and Rik <rik@octave.org>
parents: 30673
diff changeset
8097 error_unless (retval.columns () == k-1);
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8098 order--;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8099 k--;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8100 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8101 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8102 else
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8103 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8104 octave_idx_type k = retval.rows ();
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8105 while (order > 0 && k > 0)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8106 {
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
8107 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
8108 retval = SparseT (retval.index (sl1, col1))
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
8109 - SparseT (retval.index (sl2, col2));
30723
08b08b7f05b2 Replace direct calls to C library assert() with Octave specialty functions in libinterp/ (bug #61753)
Arun Giridhar <arungiridhar@gmail.com> and Rik <rik@octave.org>
parents: 30673
diff changeset
8110 error_unless (retval.rows () == k-1);
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8111 order--;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8112 k--;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8113 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8114 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8115
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8116 return retval;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8117 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8118
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8119 static octave_value
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8120 do_diff (const octave_value& array, octave_idx_type order,
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8121 int dim = -1)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8122 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8123 octave_value retval;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8124
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8125 const dim_vector& dv = array.dims ();
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8126 if (dim == -1)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8127 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8128 dim = array.dims ().first_non_singleton ();
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8129
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21730
diff changeset
8130 // Bother Matlab. This behavior is really wicked.
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8131 if (dv(dim) <= order)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8132 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8133 if (dv(dim) == 1)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8134 retval = array.resize (dim_vector (0, 0));
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8135 else
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8136 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8137 retval = array;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8138 while (order > 0)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8139 {
21660
53728df3e4c9 maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents: 21602
diff changeset
8140 if (dim == dv.ndims ())
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8141 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8142 retval = do_diff (array, order, dim - 1);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8143 order = 0;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8144 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8145 else if (dv(dim) == 1)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8146 dim++;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8147 else
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8148 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8149 retval = do_diff (array, dv(dim) - 1, dim);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8150 order -= dv(dim) - 1;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8151 dim++;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8152 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8153 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8154 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8155
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8156 return retval;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8157 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8158 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8159
23580
2230f9e10fb3 maint: Deprecate is_integer_type and replace with isinteger.
Rik <rik@octave.org>
parents: 23579
diff changeset
8160 if (array.isinteger ())
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8161 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8162 if (array.is_int8_type ())
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8163 retval = array.int8_array_value ().diff (order, dim);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8164 else if (array.is_int16_type ())
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8165 retval = array.int16_array_value ().diff (order, dim);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8166 else if (array.is_int32_type ())
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8167 retval = array.int32_array_value ().diff (order, dim);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8168 else if (array.is_int64_type ())
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8169 retval = array.int64_array_value ().diff (order, dim);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8170 else if (array.is_uint8_type ())
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8171 retval = array.uint8_array_value ().diff (order, dim);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8172 else if (array.is_uint16_type ())
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8173 retval = array.uint16_array_value ().diff (order, dim);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8174 else if (array.is_uint32_type ())
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8175 retval = array.uint32_array_value ().diff (order, dim);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8176 else if (array.is_uint64_type ())
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8177 retval = array.uint64_array_value ().diff (order, dim);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8178 else
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8179 panic_impossible ();
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8180 }
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
8181 else if (array.issparse ())
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8182 {
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
8183 if (array.iscomplex ())
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
8184 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
8185 order, dim);
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8186 else
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8187 retval = do_sparse_diff (array.sparse_matrix_value (), order, dim);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8188 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8189 else if (array.is_single_type ())
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8190 {
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
8191 if (array.iscomplex ())
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8192 retval = array.float_complex_array_value ().diff (order, dim);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8193 else
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8194 retval = array.float_array_value ().diff (order, dim);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8195 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8196 else
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8197 {
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
8198 if (array.iscomplex ())
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8199 retval = array.complex_array_value ().diff (order, dim);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8200 else
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8201 retval = array.array_value ().diff (order, dim);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8202 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8203
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8204 return retval;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8205 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8206
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8207 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
8208 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
8209 @deftypefn {} {@var{y} =} diff (@var{x})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
8210 @deftypefnx {} {@var{y} =} diff (@var{x}, @var{k})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
8211 @deftypefnx {} {@var{y} =} diff (@var{x}, @var{k}, @var{dim})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
8212 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
8213 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
8214 @tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
8215 $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
8216 @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
8217 @ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
8218 @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
8219 @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
8220
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
8221 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
8222 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
8223
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
8224 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
8225 @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
8226 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
8227 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
8228 @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
8229 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
8230
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
8231 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
8232 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
8233 @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
8234 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
8235 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
8236 @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
8237 @end deftypefn */)
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8238 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8239 int nargin = args.length ();
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8240
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8241 if (nargin < 1 || nargin > 3)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8242 print_usage ();
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8243
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23585
diff changeset
8244 if (! (args(0).isnumeric () || args(0).islogical ()))
10880
92c3e8068f28 allow diff(logical)
Jaroslav Hajek <highegg@gmail.com>
parents: 10846
diff changeset
8245 error ("diff: X must be numeric or logical");
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8246
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
8247 int dim = -1;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
8248 octave_idx_type order = 1;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
8249 if (nargin > 1)
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8250 {
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
8251 if (args(1).is_scalar_type ())
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
8252 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
8253 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
8254 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
8255 if (order < 0)
20726
25d676f9619c Preface error() messages with name of function when possible.
Rik <rik@octave.org>
parents: 20720
diff changeset
8256 error ("diff: order K must be non-negative");
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8257 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8258
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
8259 if (nargin > 2)
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
8260 {
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
8261 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
8262 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
8263 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
8264
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
8265 dim -= 1;
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
8266 }
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
8267
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8268 return do_diff (args(0), order, dim);
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8269 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8270
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8271 /*
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8272 %!assert (diff ([1, 2, 3, 4]), [1, 1, 1])
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8273 %!assert (diff ([1, 3, 7, 19], 2), [2, 8])
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8274 %!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
8275 %!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
8276 %!assert (isempty (diff (1)))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
8277
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
8278 %!error diff ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
8279 %!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
8280 %!error diff ("foo")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
8281 %!error diff ([1, 2; 3, 4], -1)
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8282 */
10799
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8283
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
8284 template <typename T>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
8285 static Array<T>
10799
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8286 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
8287 {
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8288 Array<T> retval;
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8289
30723
08b08b7f05b2 Replace direct calls to C library assert() with Octave specialty functions in libinterp/ (bug #61753)
Arun Giridhar <arungiridhar@gmail.com> and Rik <rik@octave.org>
parents: 30673
diff changeset
8290 if (rep.ndims () != 2 || rep.rows () != 2)
08b08b7f05b2 Replace direct calls to C library assert() with Octave specialty functions in libinterp/ (bug #61753)
Arun Giridhar <arungiridhar@gmail.com> and Rik <rik@octave.org>
parents: 30673
diff changeset
8291 error ("repelems: R must be a 2-row, N-column matrix of integers");
10799
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8292
18100
6a71e5030df5 Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents: 17915
diff changeset
8293 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
8294 octave_idx_type l = 0;
10799
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8295 for (octave_idx_type i = 0; i < n; i++)
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8296 {
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8297 octave_idx_type k = rep(1, i);
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8298 if (k < 0)
20893
384ff5aa9437 2015 Code Sprint: Eliminate useless return statements after error ().
Rik <rik@octave.org>
parents: 20884
diff changeset
8299 error ("repelems: second row must contain non-negative numbers");
10799
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8300
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8301 l += k;
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8302 }
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8303
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8304 retval.clear (1, l);
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8305 T *dest = retval.fortran_vec ();
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8306 l = 0;
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8307 for (octave_idx_type i = 0; i < n; i++)
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8308 {
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8309 octave_idx_type k = rep(1, i);
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8310 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
8311 dest += k;
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8312 }
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8313
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8314 return retval;
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8315 }
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8316
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8317 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
8318 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
8319 @deftypefn {} {@var{y} =} repelems (@var{x}, @var{r})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
8320 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
8321
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
8322 @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
8323 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
8324 @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
8325 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
8326 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
8327 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
8328 returned.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
8329
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
8330 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
8331
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
8332 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
8333 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
8334 y = [];
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
8335 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
8336 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
8337 endfor
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
8338 @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
8339 @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
8340 @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
8341 @end deftypefn */)
10799
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8342 {
20850
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8343 if (args.length () != 2)
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8344 print_usage ();
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8345
10799
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8346 octave_value retval;
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8347
20850
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8348 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
8349
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8350 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
8351 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
8352
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8353 octave_value x = args(0);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8354
27666
3e8faed1b7d8 Remove wrapper template class NoAlias<T> (bug #56752)
Carlo de Falco <carlo.defalco@polimi.it>
parents: 27568
diff changeset
8355 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
8356
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8357 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
8358 {
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8359 octave_idx_type rx = rm(i);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8360 if (static_cast<double> (rx) != rm(i))
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8361 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
8362
27666
3e8faed1b7d8 Remove wrapper template class NoAlias<T> (bug #56752)
Carlo de Falco <carlo.defalco@polimi.it>
parents: 27568
diff changeset
8363 r.xelem (i) = rx;
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8364 }
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8365
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8366 switch (x.builtin_type ())
10799
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8367 {
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
8368 #define BTYP_BRANCH(X, EX) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
8369 case btyp_ ## X: \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
8370 retval = do_repelems (x.EX ## _value (), r); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
8371 break;
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8372
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8373 BTYP_BRANCH (double, array);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8374 BTYP_BRANCH (float, float_array);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8375 BTYP_BRANCH (complex, complex_array);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8376 BTYP_BRANCH (float_complex, float_complex_array);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8377 BTYP_BRANCH (bool, bool_array);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8378 BTYP_BRANCH (char, char_array);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8379
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8380 BTYP_BRANCH (int8, int8_array);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8381 BTYP_BRANCH (int16, int16_array);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8382 BTYP_BRANCH (int32, int32_array);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8383 BTYP_BRANCH (int64, int64_array);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8384 BTYP_BRANCH (uint8, uint8_array);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8385 BTYP_BRANCH (uint16, uint16_array);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8386 BTYP_BRANCH (uint32, uint32_array);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8387 BTYP_BRANCH (uint64, uint64_array);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8388
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8389 BTYP_BRANCH (cell, cell);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8390 //BTYP_BRANCH (struct, map);//FIXME
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
8391
10799
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8392 #undef BTYP_BRANCH
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8393
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8394 default:
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21078
diff changeset
8395 err_wrong_type_arg ("repelems", x);
10799
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8396 }
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8397
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8398 return retval;
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8399 }
15050
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
8400
15252
fa0118cb67d9 move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents: 15213
diff changeset
8401 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
8402 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
8403 @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
8404 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
8405 @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
8406
28769
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8407 @seealso{base64_decode, matlab.net.base64decode, matlab.net.base64encode}
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
8408 @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
8409 {
20819
f428cbe7576f eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents: 20816
diff changeset
8410 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
8411 print_usage ();
20850
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8412
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23585
diff changeset
8413 if (! args(0).isnumeric ())
20850
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8414 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
8415
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
8416 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
8417 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
8418
15050
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
8419 octave_value_list retval;
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8420
23580
2230f9e10fb3 maint: Deprecate is_integer_type and replace with isinteger.
Rik <rik@octave.org>
parents: 23579
diff changeset
8421 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
8422 {
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
8423 #define MAKE_INT_BRANCH(X) \
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
8424 if (args(0).is_ ## X ## _type ()) \
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
8425 { \
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
8426 const X##NDArray in = args(0). X## _array_value (); \
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
8427 std::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
8428 const char *inc = reinterpret_cast<const char *> (in.data ()); \
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
8429 char *out; \
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
8430 if (base64_encode (inc, inlen, &out)) \
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
8431 { \
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
8432 retval(0) = octave_value (out); \
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
8433 ::free (out); \
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
8434 } \
15111
5dd599df36de generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15094
diff changeset
8435 }
20850
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8436
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8437 MAKE_INT_BRANCH(int8)
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8438 else MAKE_INT_BRANCH(int16)
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
8439 else MAKE_INT_BRANCH(int32)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
8440 else MAKE_INT_BRANCH(int64)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
8441 else MAKE_INT_BRANCH(uint8)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
8442 else MAKE_INT_BRANCH(uint16)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
8443 else MAKE_INT_BRANCH(uint32)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
8444 else MAKE_INT_BRANCH(uint64)
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
8445
20850
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8446 #undef MAKE_INT_BRANCH
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8447
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
8448 else
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
8449 panic_impossible ();
20850
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8450 }
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8451 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
8452 {
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8453 const Array<float> in = args(0).float_array_value ();
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29514
diff changeset
8454 std::size_t inlen;
20850
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8455 inlen = in.numel () * sizeof (float) / sizeof (char);
30390
a61e1a0f6024 maint: style check C++ files in libinterp/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 30377
diff changeset
8456 const char *inc;
23447
db1fdf4384dd maint: Use convention "static_cast<void *>" for casting of pointers.
Rik <rik@octave.org>
parents: 23289
diff changeset
8457 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
8458 char *out;
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
8459 if (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
8460 {
20850
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8461 retval(0) = octave_value (out);
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8462 ::free (out);
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
8463 }
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
8464 }
20850
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8465 else // double_type
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8466 {
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8467 const Array<double> in = args(0).array_value ();
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29514
diff changeset
8468 std::size_t inlen;
20850
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8469 inlen = in.numel () * sizeof (double) / sizeof (char);
30390
a61e1a0f6024 maint: style check C++ files in libinterp/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 30377
diff changeset
8470 const char *inc;
23447
db1fdf4384dd maint: Use convention "static_cast<void *>" for casting of pointers.
Rik <rik@octave.org>
parents: 23289
diff changeset
8471 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
8472 char *out;
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
8473 if (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
8474 {
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8475 retval(0) = octave_value (out);
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8476 ::free (out);
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8477 }
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8478 }
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8479
15052
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
8480 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
8481 }
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
8482
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
8483 /*
21458
348e335c49dd Fix failing BIST tests on big-endian systems
Mike Miller <mtmiller@octave.org>
parents: 21405
diff changeset
8484 %!test
348e335c49dd Fix failing BIST tests on big-endian systems
Mike Miller <mtmiller@octave.org>
parents: 21405
diff changeset
8485 %! ## FIXME: better test for endianness?
348e335c49dd Fix failing BIST tests on big-endian systems
Mike Miller <mtmiller@octave.org>
parents: 21405
diff changeset
8486 %! if (bitunpack (uint16 (1))(1) == 1)
348e335c49dd Fix failing BIST tests on big-endian systems
Mike Miller <mtmiller@octave.org>
parents: 21405
diff changeset
8487 %! expected = "2w9JQA==";
348e335c49dd Fix failing BIST tests on big-endian systems
Mike Miller <mtmiller@octave.org>
parents: 21405
diff changeset
8488 %! else
348e335c49dd Fix failing BIST tests on big-endian systems
Mike Miller <mtmiller@octave.org>
parents: 21405
diff changeset
8489 %! expected = "QEkP2w==";
348e335c49dd Fix failing BIST tests on big-endian systems
Mike Miller <mtmiller@octave.org>
parents: 21405
diff changeset
8490 %! endif
348e335c49dd Fix failing BIST tests on big-endian systems
Mike Miller <mtmiller@octave.org>
parents: 21405
diff changeset
8491 %! assert (base64_encode (single (pi)), expected);
348e335c49dd Fix failing BIST tests on big-endian systems
Mike Miller <mtmiller@octave.org>
parents: 21405
diff changeset
8492
15111
5dd599df36de generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15094
diff changeset
8493 %!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
8494 %!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
8495 %!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
8496 %!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
8497 %!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
8498
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
8499 %!error base64_encode ()
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
8500 %!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
8501 %!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
8502 %!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
8503 %!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
8504 */
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
8505
15252
fa0118cb67d9 move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents: 15213
diff changeset
8506 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
8507 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
8508 @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
8509 @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
8510 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
8511 @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
8512
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
8513 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
8514 dimensions of the decoded array.
28769
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8515 @seealso{base64_encode, matlab.net.base64decode, matlab.net.base64encode}
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
8516 @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
8517 {
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
8518 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
8519
15050
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
8520 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
8521 print_usage ();
20850
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8522
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8523 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
8524
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
8525 Array<double> retval = base64_decode (str);
20850
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8526
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8527 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
8528 {
15252
fa0118cb67d9 move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents: 15213
diff changeset
8529 dim_vector dims;
15052
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
8530
27277
db687716fed6 style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents: 27081
diff changeset
8531 const Array<octave_idx_type> size
db687716fed6 style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents: 27081
diff changeset
8532 = args(1).octave_idx_type_vector_value ();
20850
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8533
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8534 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
8535 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
8536 dims(i) = size(i);
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8537
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8538 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
8539 }
15052
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
8540
21127
df7891224709 maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents: 21121
diff changeset
8541 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
8542 }
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
8543
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
8544 /*
15052
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
8545 %!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
8546 %!
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
8547 %!test
15052
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
8548 %! in = randn (10);
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
8549 %! 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
8550 %! 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
8551 %! assert (outv, in(:).');
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
8552 %! assert (outm, in);
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
8553
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
8554 %!error base64_decode ()
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
8555 %!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
8556 %!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
8557 %!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
8558 %!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
8559 %!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
8560 */
28769
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8561
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8562 DEFUN (__base64_decode_bytes__, args, ,
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8563 doc: /* -*- texinfo -*-
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8564 @deftypefn {} {@var{x} =} base64_decode_bytes (@var{s})
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8565 @deftypefnx {} {@var{x} =} base64_decode_bytes (@var{s}, @var{dims})
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8566 Decode the uint8 matrix or array @var{x} from the base64 encoded string
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8567 @var{s}.
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8568
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8569 The optional input parameter @var{dims} should be a vector containing the
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8570 dimensions of the decoded array.
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8571 @seealso{base64_decode}
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8572 @end deftypefn */)
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8573 {
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8574 int nargin = args.length ();
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8575
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8576 if (nargin < 1 || nargin > 2)
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8577 print_usage ();
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8578
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8579 std::string str = args(0).string_value ();
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8580
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
8581 intNDArray<octave_uint8> retval = base64_decode_bytes (str);
28769
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8582
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8583 if (nargin == 2)
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8584 {
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8585 dim_vector dims;
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8586
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8587 const Array<octave_idx_type> size
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8588 = args(1).octave_idx_type_vector_value ();
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8589
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8590 dims = dim_vector::alloc (size.numel ());
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8591 for (octave_idx_type i = 0; i < size.numel (); i++)
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8592 dims(i) = size(i);
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8593
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8594 retval = retval.reshape (dims);
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8595 }
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8596
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8597 return ovl (retval);
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8598 }
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8599
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8600 /*
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8601 %!assert (__base64_decode_bytes__ (base64_encode (uint8 (1))), uint8 (1))
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8602
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8603 %!test
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8604 %! in = uint8 (rand (10)*255);
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8605 %! outv = __base64_decode_bytes__ (base64_encode (in));
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8606 %! outm = __base64_decode_bytes__ (base64_encode (in), size (in));
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8607 %! assert (outv, in(:).');
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8608 %! assert (outm, in);
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8609
28888
06c8e0877864 maint: Backed out changeset 09c071328135.
Rik <rik@octave.org>
parents: 28887
diff changeset
8610 %!error __base64_decode_bytes__ ()
06c8e0877864 maint: Backed out changeset 09c071328135.
Rik <rik@octave.org>
parents: 28887
diff changeset
8611 %!error __base64_decode_bytes__ (1,2,3)
28769
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8612 %!error __base64_decode_bytes__ (1, "this is not a valid set of dimensions")
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8613 %!error <input was not valid base64> __base64_decode_bytes__ (1)
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8614 */
29958
32c3a5805893 move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29955
diff changeset
8615
31605
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 31603
diff changeset
8616 OCTAVE_END_NAMESPACE(octave)