annotate libinterp/corefcn/data.cc @ 30565:83f9f8bda883

maint: Merge stable to default.
author John W. Eaton <jwe@octave.org>
date Tue, 28 Dec 2021 18:59:33 -0500
parents 841a10208c38 796f54d4ddbf
children 0cb3f48da9da
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 //
30564
796f54d4ddbf update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 30390
diff changeset
3 // Copyright (C) 1994-2022 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
29958
32c3a5805893 move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29955
diff changeset
69 OCTAVE_NAMESPACE_BEGIN
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 -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
73 @deftypefn {} {} all (@var{x})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
74 @deftypefnx {} {} all (@var{x}, @var{dim})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
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
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
78 For a matrix argument, return a row vector of logical ones and
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
79 zeros with each element indicating whether all of the elements of the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
80 corresponding column of the matrix are nonzero. For example:
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
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
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
89 If the optional argument @var{dim} is supplied, work along dimension
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
90 @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
91 @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
92 @end deftypefn */)
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
93 {
20943
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
94 int nargin = args.length ();
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
95
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
96 if (nargin < 1 || nargin > 2)
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
97 print_usage ();
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
98
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
99 int dim = (nargin == 1 ? -1
26357
bba4b338757d data.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents: 26292
diff changeset
100 : 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
101
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
102 if (dim < -1)
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
103 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
104
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
105 return ovl (args(0).all (dim));
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
106 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
107
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
108 /*
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
109 %!test
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
110 %! 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
111 %! x(1,1) = 0;
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
112 %! 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
113 %! 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
114 %! 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
115 %! 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
116
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
117 %!test
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
118 %! 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
119 %! x(1,1) = 0;
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
120 %! 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
121 %! 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
122 %! 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
123 %! 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
124
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
125 %!error all ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
126 %!error all (1, 2, 3)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
127 */
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
128
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1940
diff changeset
129 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
130 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
131 @deftypefn {} {} any (@var{x})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
132 @deftypefnx {} {} any (@var{x}, @var{dim})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
133 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
134 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
135
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
136 For a matrix argument, return a row vector of logical ones and
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
137 zeros with each element indicating whether any of the elements of the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
138 corresponding column of the matrix are nonzero. For example:
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
139
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
140 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
141 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
142 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
143 @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
144 @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
145 @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
146
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
147 If the optional argument @var{dim} is supplied, work along dimension
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
148 @var{dim}. For example:
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
149
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
150 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
151 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
152 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
153 @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
154 @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
155 @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
156 @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
157 @end deftypefn */)
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
158 {
20943
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
159 int nargin = args.length ();
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
160
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
161 if (nargin < 1 || nargin > 2)
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
162 print_usage ();
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
163
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
164 int dim = (nargin == 1 ? -1
26357
bba4b338757d data.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents: 26292
diff changeset
165 : 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
166
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
167 if (dim < -1)
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
168 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
169
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
170 return ovl (args(0).any (dim));
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
171 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
172
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
173 /*
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
174 %!test
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
175 %! 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
176 %! x(3,3) = 1;
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
177 %! 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
178 %! 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
179 %! 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
180 %! 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
181
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
182 %!test
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
183 %! 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
184 %! x(3,3) = 1;
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
185 %! 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
186 %! 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
187 %! 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
188 %! 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
189
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
190 %!error any ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
191 %!error any (1, 2, 3)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
192 */
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
193
649
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
194 // 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
195
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1940
diff changeset
196 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
197 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
198 @deftypefn {} {} atan2 (@var{y}, @var{x})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
199 Compute atan (@var{y} / @var{x}) for corresponding elements of @var{y}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
200 and @var{x}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
201
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
202 @var{y} and @var{x} must match in size and orientation. The signs of
22440
20e6de770ca4 * data.cc (Fatan2): Fix typo "quadrats" → "quadrants".
Mike Miller <mtmiller@octave.org>
parents: 22429
diff changeset
203 elements of @var{y} and @var{x} are used to determine the quadrants of each
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
204 resulting value.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
205
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
206 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
207 @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
208 @end deftypefn */)
649
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
209 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
210 if (args.length () != 2)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
211 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
212
4233
ccfdb55c8156 [project @ 2002-12-20 22:43:54 by jwe]
jwe
parents: 4176
diff changeset
213 octave_value retval;
649
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
214
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23585
diff changeset
215 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
216 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
217
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23585
diff changeset
218 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
219 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
220
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
221 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
222 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
223
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
224 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
225 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
226 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
227 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
228 else
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents: 10405
diff changeset
229 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
230 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
231 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
232 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
233 }
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
234 }
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
235 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
236 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
237 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
238 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
239 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
240 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
241 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
242 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
243 retval = binmap<double> (m0, m1, std::atan2, "atan2");
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents: 10405
diff changeset
244 }
7494
bd2bd04e68ca Treat integer types for mod/rem correctly
David Bateman <dbateman@free.fr>
parents: 7433
diff changeset
245 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
246 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
247 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
248 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
249 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
250 }
649
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
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
253 return retval;
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
254 }
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
255
7506
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
256 /*
7741
72c0489653ac fix tests
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
257 %!assert (size (atan2 (zeros (0, 2), zeros (0, 2))), [0, 2])
72c0489653ac fix tests
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
258 %!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
259 %!assert (size (atan2 (rand (2, 3, 4), 1)), [2, 3, 4])
72c0489653ac fix tests
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
260 %!assert (size (atan2 (1, rand (2, 3, 4))), [2, 3, 4])
72c0489653ac fix tests
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
261 %!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
262
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
263 %!test
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
264 %! rt2 = sqrt (2);
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
265 %! rt3 = sqrt (3);
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
266 %! 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
267 %! 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
268 %! 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
269 %! 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
270
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
271 %!test
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
272 %! rt2 = sqrt (2);
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
273 %! rt3 = sqrt (3);
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
274 %! 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
275 %! 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
276 %! 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
277 %! 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
278
18789
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
279 ## Test sparse implementations
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
280 %!shared xs
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
281 %! xs = sparse (0:3);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
282 %!test
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
283 %! y = atan2 (1, xs);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
284 %! assert (issparse (y), false);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
285 %! assert (nnz (y), 4);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
286 %! 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
287 %!test
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
288 %! y = atan2 (0, xs);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
289 %! assert (issparse (y), false);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
290 %! assert (nnz (y), 0);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
291 %! 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
292 %!test
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
293 %! y = atan2 (xs, 1);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
294 %! assert (issparse (y));
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
295 %! assert (nnz (y), 3);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
296 %! 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
297 %!test
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
298 %! y = atan2 (xs, 0);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
299 %! assert (issparse (y));
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
300 %! assert (nnz (y), 3);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
301 %! 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
302 %!test
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
303 %! 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
304 %! assert (issparse (y));
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
305 %! assert (nnz (y), 3);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
306 %! 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
307 %!test
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
308 %! 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
309 %! assert (issparse (y));
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
310 %! assert (nnz (y), 3);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
311 %! 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
312
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
313 %!error atan2 ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
314 %!error atan2 (1, 2, 3)
7506
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
315 */
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
316
10538
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
317 static octave_value
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
318 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
319 {
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
320 octave_value retval;
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
321
18100
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 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
323 octave_value arg1 = y;
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23585
diff changeset
324 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
325 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
326 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
327 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
328
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
329 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
330 arg0 = arg0.abs ();
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
331 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
332 arg1 = arg1.abs ();
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
333
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
334 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
335 {
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
336 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
337 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
338 else
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
339 {
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
340 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
341 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
342 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
343 }
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
344 }
10538
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
345 else
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
346 {
21118
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
347 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
348 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
349 else if (arg0.issparse () || arg1.issparse ())
10538
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
350 {
21118
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
351 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
352 SparseMatrix m1 = arg1.sparse_matrix_value ();
23625
b0a2367823f5 Use hypot, hypotf from C++ std library.
Rik <rik@octave.org>
parents: 23599
diff changeset
353 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
354 }
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
355 else
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
356 {
21118
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
357 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
358 NDArray a1 = arg1.array_value ();
23625
b0a2367823f5 Use hypot, hypotf from C++ std library.
Rik <rik@octave.org>
parents: 23599
diff changeset
359 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
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
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
363 return retval;
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
364 }
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
365
7631
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
366 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
367 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
368 @deftypefn {} {} hypot (@var{x}, @var{y})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
369 @deftypefnx {} {} hypot (@var{x}, @var{y}, @var{z}, @dots{})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
370 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
371 @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
372
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
373 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
374 @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
375 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
376
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
377 @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
378 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
379
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
380 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
381 @group
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 (@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
383 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
384 @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
385 @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
386 @end deftypefn */)
7631
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
387 {
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
388 int nargin = args.length ();
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
389
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
390 if (nargin < 2)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
391 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
392
7631
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
393 octave_value retval;
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
394
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents: 10405
diff changeset
395 if (nargin == 2)
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
396 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
397 else
10538
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
398 {
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
399 retval = args(0);
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
400
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
401 for (int i = 1; i < nargin; i++)
10538
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
402 retval = do_hypot (retval, args(i));
7631
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
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
405 return retval;
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
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
408 /*
7741
72c0489653ac fix tests
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
409 %!assert (size (hypot (zeros (0, 2), zeros (0, 2))), [0, 2])
72c0489653ac fix tests
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
410 %!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
411 %!assert (size (hypot (rand (2, 3, 4), 1)), [2, 3, 4])
72c0489653ac fix tests
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
412 %!assert (size (hypot (1, rand (2, 3, 4))), [2, 3, 4])
72c0489653ac fix tests
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
413 %!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
414 %!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
415 %!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
416
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
417 ## Test sparse implementations
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
418 %!shared xs
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
419 %! xs = sparse (0:3);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
420 %!test
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
421 %! y = hypot (1, xs);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
422 %! assert (nnz (y), 4);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
423 %! 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
424 %!test
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
425 %! y = hypot (0, xs);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
426 %! assert (nnz (y), 3);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
427 %! assert (y, xs);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
428 %!test
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
429 %! y = hypot (xs, 1);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
430 %! assert (nnz (y), 4);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
431 %! 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
432 %!test
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
433 %! y = hypot (xs, 0);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
434 %! assert (nnz (y), 3);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
435 %! assert (y, xs);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
436 %!test
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
437 %! y = hypot (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
438 %! assert (nnz (y), 1);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
439 %! 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
440 %!test
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
441 %! y = hypot (sparse ([0 1]), sparse ([0 0]));
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
442 %! assert (nnz (y), 1);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
443 %! assert (y, sparse ([0 1]));
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
444
7631
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
445 */
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
446
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
447 template <typename T, typename ET>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
448 void
9813
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
449 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
450 {
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
451 f = Array<T>(x.dims ());
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
452 e = Array<ET>(x.dims ());
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
453 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
454 {
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
455 int exp;
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
456 f.xelem (i) = math::log2 (x(i), exp);
9813
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
457 e.xelem (i) = exp;
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
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
461 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
462 doc: /* -*- texinfo -*-
29817
ba571657651a Improve documentation for log2 function (bug #60817).
Rik <rik@octave.org>
parents: 29654
diff changeset
463 @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
464 @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
465 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
466
29817
ba571657651a Improve documentation for log2 function (bug #60817).
Rik <rik@octave.org>
parents: 29654
diff changeset
467 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
468 @tex
ba571657651a Improve documentation for log2 function (bug #60817).
Rik <rik@octave.org>
parents: 29654
diff changeset
469 $2^y = x$.
ba571657651a Improve documentation for log2 function (bug #60817).
Rik <rik@octave.org>
parents: 29654
diff changeset
470 @end tex
ba571657651a Improve documentation for log2 function (bug #60817).
Rik <rik@octave.org>
parents: 29654
diff changeset
471 @ifnottex
ba571657651a Improve documentation for log2 function (bug #60817).
Rik <rik@octave.org>
parents: 29654
diff changeset
472 @code{2^@var{y} = @var{x}}.
ba571657651a Improve documentation for log2 function (bug #60817).
Rik <rik@octave.org>
parents: 29654
diff changeset
473 @end ifnottex
ba571657651a Improve documentation for log2 function (bug #60817).
Rik <rik@octave.org>
parents: 29654
diff changeset
474
ba571657651a Improve documentation for log2 function (bug #60817).
Rik <rik@octave.org>
parents: 29654
diff changeset
475 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
476 (@var{f}) and exponent (@var{e}) such that
ba571657651a Improve documentation for log2 function (bug #60817).
Rik <rik@octave.org>
parents: 29654
diff changeset
477 @tex
ba571657651a Improve documentation for log2 function (bug #60817).
Rik <rik@octave.org>
parents: 29654
diff changeset
478 $x = f \cdot 2^e$
ba571657651a Improve documentation for log2 function (bug #60817).
Rik <rik@octave.org>
parents: 29654
diff changeset
479 @end tex
ba571657651a Improve documentation for log2 function (bug #60817).
Rik <rik@octave.org>
parents: 29654
diff changeset
480 @ifnottex
ba571657651a Improve documentation for log2 function (bug #60817).
Rik <rik@octave.org>
parents: 29654
diff changeset
481 @code{@var{x} = @var{f} * 2^@var{e}}
ba571657651a Improve documentation for log2 function (bug #60817).
Rik <rik@octave.org>
parents: 29654
diff changeset
482 @end ifnottex
ba571657651a Improve documentation for log2 function (bug #60817).
Rik <rik@octave.org>
parents: 29654
diff changeset
483 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
484 @tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
485 ${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
486 @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
487 @ifnottex
29817
ba571657651a Improve documentation for log2 function (bug #60817).
Rik <rik@octave.org>
parents: 29654
diff changeset
488 @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
489 @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
490 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
491 @tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
492 $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
493 @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
494 @ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
495 @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
496 @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
497 @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
498 @end deftypefn */)
9813
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
499 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
500 if (args.length () != 1)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
501 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
502
9813
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
503 octave_value_list retval;
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
504
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
505 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
506 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
507 else if (args(0).is_single_type ())
9813
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
508 {
23582
0cc2011d800e maint: Deprecate is_real_type and replace with isreal.
Rik <rik@octave.org>
parents: 23581
diff changeset
509 if (args(0).isreal ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
510 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
511 FloatNDArray f;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
512 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
513 // 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
514 FloatMatrix e;
9813
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
515 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
516 retval = ovl (f, e);
9813
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
517 }
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
518 else if (args(0).iscomplex ())
9813
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
519 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
520 FloatComplexNDArray f;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
521 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
522 // 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
523 FloatNDArray e;
9813
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
524 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
525 retval = ovl (f, e);
9813
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
526 }
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
527 }
23582
0cc2011d800e maint: Deprecate is_real_type and replace with isreal.
Rik <rik@octave.org>
parents: 23581
diff changeset
528 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
529 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
530 NDArray f;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
531 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
532 // 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
533 Matrix e;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
534 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
535 retval = ovl (f, e);
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
536 }
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
537 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
538 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
539 ComplexNDArray f;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
540 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
541 // 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
542 NDArray e;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
543 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
544 retval = ovl (f, e);
9813
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
545 }
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
546 else
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21078
diff changeset
547 err_wrong_type_arg ("log2", args(0));
9813
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
548
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
549 return retval;
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
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
552 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
553 %!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
554 %!assert (log2 (Inf), Inf)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
555 %!assert (isnan (log2 (NaN)))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
556 %!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
557 %!assert (log2 (complex (0,Inf)), Inf + log2 (i))
9813
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
558
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
559 %!test
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
560 %! [f, e] = log2 ([0,-1; 2,-4; Inf,-Inf]);
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
561 %! 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
562 %! assert (e(1:2,:), [0,1;2,3]);
9813
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
563
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
564 %!test
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
565 %! [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
566 %! 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
567 %! 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
568
23573
1b4f4ec53b4a use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents: 23572
diff changeset
569 %!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
570 */
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
571
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
572 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
573 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
574 @deftypefn {} {} rem (@var{x}, @var{y})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
575 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
576
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
577 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
578
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
579 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
580 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
581 @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
582
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
583 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
584 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
585
26292
d00577d95369 doc: Add warning note about integers exceeding flintmax to mod, rem (bug #55238).
Rik <rik@octave.org>
parents: 26199
diff changeset
586 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
587 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
588 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
589 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
590 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
591 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
592
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
593 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
594
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
595 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
596 @group
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) = 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
598 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
599 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
600 @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
601 @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
602
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
603 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
604 @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
605 @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
606 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
607 @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
608 @end deftypefn */)
4311
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
609 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
610 if (args.length () != 2)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
611 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
612
4311
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
613 octave_value retval;
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
614
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23585
diff changeset
615 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
616 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
617
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23585
diff changeset
618 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
619 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
620
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
621 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
622 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
623
23580
2230f9e10fb3 maint: Deprecate is_integer_type and replace with isinteger.
Rik <rik@octave.org>
parents: 23579
diff changeset
624 if (args(0).isinteger () || args(1).isinteger ())
4311
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
625 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
626 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
627 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
628 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
629 btyp0 = btyp1;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
630 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
631 btyp1 = btyp0;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
632
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
633 if (btyp0 != btyp1)
26107
05dfcb24ef12 Supply missing arguments to variable length *printf functions (bug #55046).
Rik <rik@octave.org>
parents: 26046
diff changeset
634 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
635 args(0).class_name ().c_str (),
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
636 args(1).class_name ().c_str ());
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
637
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
638 switch (btyp0)
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
639 {
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
640 #define MAKE_INT_BRANCH(X) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
641 case btyp_ ## X: \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
642 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
643 X##NDArray a0 = args(0).X##_array_value (); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
644 X##NDArray a1 = args(1).X##_array_value (); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
645 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
646 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
647 break
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
648
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
649 MAKE_INT_BRANCH (int8);
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
650 MAKE_INT_BRANCH (int16);
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
651 MAKE_INT_BRANCH (int32);
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
652 MAKE_INT_BRANCH (int64);
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
653 MAKE_INT_BRANCH (uint8);
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
654 MAKE_INT_BRANCH (uint16);
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
655 MAKE_INT_BRANCH (uint32);
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
656 MAKE_INT_BRANCH (uint64);
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
657
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
658 #undef MAKE_INT_BRANCH
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
659
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
660 default:
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
661 panic_impossible ();
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
662 }
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
663 }
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
664 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
665 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
666 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
667 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
668 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
669 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
670 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
671 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
672 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
673 }
4311
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
674 }
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
675 else
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
676 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
677 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
678 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
679 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
680 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
681 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
682 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
683 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
684 }
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents: 10405
diff changeset
685 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
686 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
687 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
688 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
689 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
690 }
4311
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
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
693 return retval;
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
694 }
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
695
7506
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
696 /*
19118
9c5a17d5fc19 Deprecate fmod function.
Rik <rik@octave.org>
parents: 19079
diff changeset
697 %!assert (size (rem (zeros (0, 2), zeros (0, 2))), [0, 2])
9c5a17d5fc19 Deprecate fmod function.
Rik <rik@octave.org>
parents: 19079
diff changeset
698 %!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
699 %!assert (size (rem (rand (2, 3, 4), 1)), [2, 3, 4])
9c5a17d5fc19 Deprecate fmod function.
Rik <rik@octave.org>
parents: 19079
diff changeset
700 %!assert (size (rem (1, rand (2, 3, 4))), [2, 3, 4])
9c5a17d5fc19 Deprecate fmod function.
Rik <rik@octave.org>
parents: 19079
diff changeset
701 %!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
702
14429
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), [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
704 %!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
705 %!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
706 %!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
707 %! 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
708 %!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
709 %! 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
710 %!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
711
18789
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
712 ## Test sparse implementations
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
713 %!shared xs
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
714 %! xs = sparse (0:3);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
715 %!test
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
716 %! y = rem (11, xs);
20374
0cefba1a1030 Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents: 20232
diff changeset
717 %! 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
718 %! assert (y, sparse (rem (11, 0:3)));
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
719 %!test
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
720 %! y = rem (0, xs);
20374
0cefba1a1030 Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents: 20232
diff changeset
721 %! assert (nnz (y), 1);
0cefba1a1030 Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents: 20232
diff changeset
722 %! assert (y, sparse ([NaN 0 0 0]));
18789
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
723 %!test
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
724 %! y = rem (xs, 2);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
725 %! assert (nnz (y), 2);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
726 %! 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
727 %!test
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
728 %! y = rem (xs, 1);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
729 %! assert (nnz (y), 0);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
730 %! 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
731 %!test
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
732 %! 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
733 %! assert (nnz (y), 3);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
734 %! 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
735 %!test
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
736 %! 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
737 %! assert (nnz (y), 1);
0cefba1a1030 Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents: 20232
diff changeset
738 %! 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
739
23573
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 %!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
742
1b4f4ec53b4a use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents: 23572
diff changeset
743 %!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
744
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
745 %!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
746 %!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
747 %!error rem ()
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)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
749 %!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
750 %!error rem (i, 1)
7506
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
751 */
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
752
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
753 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
754 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
755 @deftypefn {} {} mod (@var{x}, @var{y})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
756 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
757
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
758 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
759
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
760 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
761 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
762 @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
763
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
764 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
765 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
766 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
767 @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
768
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
769 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
770 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
771
26292
d00577d95369 doc: Add warning note about integers exceeding flintmax to mod, rem (bug #55238).
Rik <rik@octave.org>
parents: 26199
diff changeset
772 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
773 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
774 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
775 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
776 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
777 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
778
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
779 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
780
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
781 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
782 @group
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}, 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
784 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
785 @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
786 @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
787
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
788 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
789 @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
790 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
791 @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
792 @end deftypefn */)
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
793 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
794 if (args.length () != 2)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
795 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
796
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
797 octave_value retval;
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
798
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23585
diff changeset
799 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
800 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
801
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23585
diff changeset
802 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
803 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
804
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
805 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
806 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
807
23580
2230f9e10fb3 maint: Deprecate is_integer_type and replace with isinteger.
Rik <rik@octave.org>
parents: 23579
diff changeset
808 if (args(0).isinteger () || args(1).isinteger ())
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
809 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
810 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
811 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
812 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
813 btyp0 = btyp1;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
814 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
815 btyp1 = btyp0;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
816
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
817 if (btyp0 != btyp1)
26107
05dfcb24ef12 Supply missing arguments to variable length *printf functions (bug #55046).
Rik <rik@octave.org>
parents: 26046
diff changeset
818 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
819 args(0).class_name ().c_str (),
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
820 args(1).class_name ().c_str ());
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
821
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
822 switch (btyp0)
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
823 {
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
824 #define MAKE_INT_BRANCH(X) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
825 case btyp_ ## X: \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
826 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
827 X##NDArray a0 = args(0).X##_array_value (); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
828 X##NDArray a1 = args(1).X##_array_value (); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
829 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
830 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
831 break
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
832
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
833 MAKE_INT_BRANCH (int8);
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
834 MAKE_INT_BRANCH (int16);
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
835 MAKE_INT_BRANCH (int32);
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
836 MAKE_INT_BRANCH (int64);
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
837 MAKE_INT_BRANCH (uint8);
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
838 MAKE_INT_BRANCH (uint16);
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
839 MAKE_INT_BRANCH (uint32);
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
840 MAKE_INT_BRANCH (uint64);
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
841
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
842 #undef MAKE_INT_BRANCH
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
843
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
844 default:
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
845 panic_impossible ();
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
846 }
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
847 }
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
848 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
849 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
850 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
851 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
852 else
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
853 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
854 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
855 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
856 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
857 }
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
858 }
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
859 else
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
860 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
861 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
862 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
863 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
864 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
865 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
866 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
867 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
868 }
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
869 else
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
870 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
871 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
872 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
873 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
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
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
877 return retval;
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 /*
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
881 ## empty input test
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
882 %!assert (isempty (mod ([], [])))
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
883
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
884 ## 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
885 %!assert (mod (5, 3), 2)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
886 %!assert (mod (-5, 3), 1)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
887 %!assert (mod (0, 3), 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]), [1; 2; 0])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
890 %!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
891
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
892 ## x mod 0 tests
14429
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, 0), -5)
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; 0; 3]), [1; 5; 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], [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
898 %!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
899
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
900 ## mixed scalar/matrix tests
14429
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], 0), [-5, 5; 0, 3])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
902 %!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
903 %!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
904 %!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
905 %!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
906
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
907 ## integer types
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
908 %!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
909 %!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
910 %!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
911 %!error mod (uint8 (5), int8 (4))
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
912
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
913 ## mixed integer/real types
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
914 %!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
915 %!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
916 %!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
917
903c1a3df301 Add additional tests for mod with non-integer real values.
Rik <octave@nomad.inbox5.com>
parents: 11242
diff changeset
918 ## non-integer real numbers
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.1), 0)
903c1a3df301 Add additional tests for mod with non-integer real values.
Rik <octave@nomad.inbox5.com>
parents: 11242
diff changeset
920 %!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
921
23573
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 %!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
924
1b4f4ec53b4a use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents: 23572
diff changeset
925 %!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
926
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))
1f52a96c8c21 Fix mod operation for signed integer types (bug #54602).
Gene Harvey <gharveymn@gmail.com>
parents: 25578
diff changeset
928 %!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
929 %!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
930 %!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
931
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
932 */
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
933
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
934 #define DATA_REDUCTION(FCN) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
935 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
936 int nargin = args.length (); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
937 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
938 if (nargin < 1 || nargin > 2) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
939 print_usage (); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
940 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
941 octave_value retval; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
942 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
943 octave_value arg = args(0); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
944 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
945 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
946 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
947 if (dim < -1) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
948 error (#FCN ": invalid dimension argument = %d", dim + 1); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
949 \
23582
0cc2011d800e maint: Deprecate is_real_type and replace with isreal.
Rik <rik@octave.org>
parents: 23581
diff changeset
950 if (arg.isreal ()) \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
951 { \
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
952 if (arg.issparse ()) \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
953 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
954 SparseMatrix tmp = arg.sparse_matrix_value (); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
955 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
956 retval = tmp.FCN (dim); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
957 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
958 else if (arg.is_single_type ()) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
959 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
960 FloatNDArray tmp = arg.float_array_value (); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
961 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
962 retval = tmp.FCN (dim); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
963 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
964 else \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
965 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
966 NDArray tmp = arg.array_value (); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
967 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
968 retval = tmp.FCN (dim); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
969 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
970 } \
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
971 else if (arg.iscomplex ()) \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
972 { \
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
973 if (arg.issparse ()) \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
974 { \
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
975 SparseComplexMatrix tmp = arg.sparse_complex_matrix_value (); \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
976 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
977 retval = tmp.FCN (dim); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
978 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
979 else if (arg.is_single_type ()) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
980 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
981 FloatComplexNDArray tmp \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
982 = arg.float_complex_array_value (); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
983 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
984 retval = tmp.FCN (dim); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
985 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
986 else \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
987 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
988 ComplexNDArray tmp = arg.complex_array_value (); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
989 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
990 retval = tmp.FCN (dim); \
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 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
993 else \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
994 err_wrong_type_arg (#FCN, arg); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
995 \
3723
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
996 return retval
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
997
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1940
diff changeset
998 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
999 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
1000 @deftypefn {} {} cumprod (@var{x})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1001 @deftypefnx {} {} cumprod (@var{x}, @var{dim})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1002 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
1003
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1004 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
1005 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
1006
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1007 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1008 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1009 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
1010 @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
1011 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
1012 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
1013 @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
1014 @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
1015 @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
1016 @end deftypefn */)
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1017 {
3723
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
1018 DATA_REDUCTION (cumprod);
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1019 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1020
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1021 /*
14429
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 ([-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
1024 %!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
1025 %!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
1026 %! [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
1027
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]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1029 %!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
1030 %!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
1031 %! 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
1032 %!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
1033 %! 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
1034
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], 1), [2, 3; 8, 15])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1036 %!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
1037
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]), 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
1039 %!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
1040
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1041 %!error cumprod ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1042 */
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1043
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1940
diff changeset
1044 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
1045 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
1046 @deftypefn {} {} cumsum (@var{x})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1047 @deftypefnx {} {} cumsum (@var{x}, @var{dim})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1048 @deftypefnx {} {} cumsum (@dots{}, "native")
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1049 @deftypefnx {} {} cumsum (@dots{}, "double")
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1050 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
1051
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1052 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
1053 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
1054
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1055 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1056 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1057 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
1058 @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
1059 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
1060 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
1061 @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
1062 @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
1063
28960
e5a1087f15d5 doc: Use @xref, @pxref rather than "see @code{}" in TexInfo in libinterp/
Rik <rik@octave.org>
parents: 28930
diff changeset
1064 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
1065 @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
1066 @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
1067 @end deftypefn */)
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1068 {
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1069 int nargin = args.length ();
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1070
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1071 bool isnative = false;
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1072 bool isdouble = false;
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1073
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1074 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
1075 {
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1076 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
1077
19743
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
1078 if (str == "native")
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
1079 isnative = true;
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
1080 else if (str == "double")
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
1081 isdouble = true;
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
1082 else
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
1083 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
1084
21062
d9c1884d1aaa maint: Eliminate space between variable and decrement '--' operator.
Rik <rik@octave.org>
parents: 21055
diff changeset
1085 nargin--;
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1086 }
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1087
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1088 if (nargin < 1 || nargin > 2)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1089 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1090
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1091 int dim = -1;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1092 if (nargin == 2)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1093 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1094 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
1095 if (dim < 0)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1096 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
1097 }
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1098
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
1099 octave_value retval;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
1100 octave_value arg = args(0);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
1101
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1102 switch (arg.builtin_type ())
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1103 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1104 case btyp_double:
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
1105 if (arg.issparse ())
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1106 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
1107 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1108 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
1109 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1110 case btyp_complex:
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
1111 if (arg.issparse ())
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1112 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
1113 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1114 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
1115 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1116 case btyp_float:
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1117 if (isdouble)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1118 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
1119 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1120 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
1121 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1122 case btyp_float_complex:
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1123 if (isdouble)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1124 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
1125 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1126 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
1127 break;
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1128
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
1129 #define MAKE_INT_BRANCH(X) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
1130 case btyp_ ## X: \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
1131 if (isnative) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
1132 retval = arg.X ## _array_value ().cumsum (dim); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
1133 else \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
1134 retval = arg.array_value ().cumsum (dim); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
1135 break;
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1136
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1137 MAKE_INT_BRANCH (int8);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1138 MAKE_INT_BRANCH (int16);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1139 MAKE_INT_BRANCH (int32);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1140 MAKE_INT_BRANCH (int64);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1141 MAKE_INT_BRANCH (uint8);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1142 MAKE_INT_BRANCH (uint16);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1143 MAKE_INT_BRANCH (uint32);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1144 MAKE_INT_BRANCH (uint64);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1145
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1146 #undef MAKE_INT_BRANCH
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1147
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1148 case btyp_bool:
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
1149 if (arg.issparse ())
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1150 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1151 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
1152 if (isnative)
26357
bba4b338757d data.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents: 26292
diff changeset
1153 retval = (cs != 0.0);
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1154 else
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1155 retval = cs;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1156 }
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1157 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1158 {
22773
7f70e420e342 deprecate boolNDArray::sum and boolNDArray::cumsum
John W. Eaton <jwe@octave.org>
parents: 22763
diff changeset
1159 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
1160 if (isnative)
26357
bba4b338757d data.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents: 26292
diff changeset
1161 retval = (cs != 0.0);
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1162 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1163 retval = cs;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1164 }
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1165 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1166
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1167 default:
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21078
diff changeset
1168 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
1169 }
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1170
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1171 return retval;
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1172 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1173
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1174 /*
14429
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 ([-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
1177 %!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
1178 %!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
1179 %! [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
1180
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]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1182 %!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
1183 %!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
1184 %! 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
1185 %!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
1186 %! 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
1187
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], 1), [1, 2; 4, 6])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1189 %!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
1190
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]), 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
1192 %!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
1193
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1194 %!error cumsum ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1195 */
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1196
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1940
diff changeset
1197 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
1198 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
1199 @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
1200 @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
1201 @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
1202 @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
1203 @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
1204 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
1205
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 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
1207 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
1208 @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
1209 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
1210
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1211 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1212 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1213 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
1214 @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
1215 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
1216 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
1217 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
1218 @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
1219 @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
1220
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1221 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1222 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
1223 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
1224 columns.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1225
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1226 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
1227 @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
1228 @end deftypefn */)
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1229 {
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1230 int nargin = args.length ();
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1231
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1232 if (nargin < 1 || nargin > 3)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1233 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1234
4233
ccfdb55c8156 [project @ 2002-12-20 22:43:54 by jwe]
jwe
parents: 4176
diff changeset
1235 octave_value retval;
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1236
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1237 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
1238 retval = args(0).diag ();
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1239 else if (nargin == 2)
7620
36594d5bbe13 Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents: 7618
diff changeset
1240 {
21041
63374982750b Usage of corresponding value extractor for octave_idx_type. Improves support
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 21014
diff changeset
1241 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
1242
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20700
diff changeset
1243 retval = args(0).diag (k);
7620
36594d5bbe13 Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents: 7618
diff changeset
1244 }
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1245 else
12570
1a93988610a3 Reverse changset cc8ccdfec424. Restore 3-input form of diag().
Rik <octave@nomad.inbox5.com>
parents: 12567
diff changeset
1246 {
1a93988610a3 Reverse changset cc8ccdfec424. Restore 3-input form of diag().
Rik <octave@nomad.inbox5.com>
parents: 12567
diff changeset
1247 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
1248
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1249 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
1250 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
1251
27325
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 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
1253 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
1254
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1255 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
1256 }
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1257
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1258 return retval;
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1259 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1260
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
1261 /*
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
1262
14843
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1263 %!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
1264 %!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
1265 %!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
1266 %! [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
1267 %!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
1268 %! [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
1269 %!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
1270 %! [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
1271
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1272 %!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
1273 %!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
1274 %! [1; 2; 3])
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1275 %!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
1276 %! [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
1277 %!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
1278 %!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
1279
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1280 %!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
1281 %! 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
1282 %!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
1283 %! 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
1284 %!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
1285 %! 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
1286 %!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
1287 %! 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
1288 %!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
1289 %! 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
1290
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1291 %!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
1292 %!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
1293 %! 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
1294 %!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
1295 %! 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
1296
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1297 %!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
1298 %!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
1299 %! 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
1300 %!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
1301 %! 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
1302 %!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
1303 %! 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
1304 %!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
1305 %! 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
1306
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1307 %!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
1308 %!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
1309 %! 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
1310 %!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
1311 %! 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
1312
27325
983dab0902f7 More explicit error messages for invalid 2nd and 3rd inputs to diag().
Rik <rik@octave.org>
parents: 27324
diff changeset
1313 %!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
1314 %!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
1315 %!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
1316 %!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
1317 %!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
1318 %!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
1319 %!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
1320 %!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
1321
23573
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)), diag([5 0 0 ]))
1b4f4ec53b4a use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents: 23572
diff changeset
1323 %!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
1324 %!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
1325 %! [[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
1326
14490
3959f3f81e33 Initialise memory in non-square diag call (bug #35946)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14171
diff changeset
1327 ## 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
1328 %!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
1329 %!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
1330 %!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
1331 %!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
1332 %!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
1333
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
1334 ## 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
1335 %!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
1336 %!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
1337 %!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
1338
22737
7abc25e6206a maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22708
diff changeset
1339 ## Test input validation
14491
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 ()
5bd9e47e9277 maint: periodic merge of stable to default
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14429 14490
diff changeset
1341 %!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
1342 %!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
1343 %!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
1344 %!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
1345
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
1346 */
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
1347
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1940
diff changeset
1348 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
1349 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
1350 @deftypefn {} {} prod (@var{x})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1351 @deftypefnx {} {} prod (@var{x}, @var{dim})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1352 @deftypefnx {} {} prod (@dots{}, "native")
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1353 @deftypefnx {} {} prod (@dots{}, "double")
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1354 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
1355
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1356 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
1357
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1358 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
1359 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
1360 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
1361 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
1362
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1363 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
1364
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1365 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1366 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1367 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
1368 @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
1369 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
1370 @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
1371 @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
1372 @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
1373
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1374 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
1375 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
1376 @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
1377 @end deftypefn */)
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1378 {
18725
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1379 int nargin = args.length ();
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1380
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1381 bool isnative = false;
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1382 bool isdouble = false;
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1383
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1384 if (nargin > 1 && args(nargin - 1).is_string ())
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1385 {
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1386 std::string str = args(nargin - 1).string_value ();
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1387
19743
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
1388 if (str == "native")
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
1389 isnative = true;
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
1390 else if (str == "double")
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
1391 isdouble = true;
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
1392 else
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
1393 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
1394
21062
d9c1884d1aaa maint: Eliminate space between variable and decrement '--' operator.
Rik <rik@octave.org>
parents: 21055
diff changeset
1395 nargin--;
18725
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1396 }
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1397
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1398 if (nargin < 1 || nargin > 2)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1399 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1400
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
1401 octave_value retval;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
1402
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1403 octave_value arg = args(0);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1404
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1405 int dim = -1;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1406 if (nargin == 2)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1407 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1408 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
1409 if (dim < 0)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1410 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
1411 }
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1412
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1413 switch (arg.builtin_type ())
18725
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1414 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1415 case btyp_double:
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
1416 if (arg.issparse ())
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1417 retval = arg.sparse_matrix_value ().prod (dim);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1418 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1419 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
1420 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1421 case btyp_complex:
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
1422 if (arg.issparse ())
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1423 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
1424 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1425 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
1426 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1427 case btyp_float:
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1428 if (isdouble)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1429 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
1430 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1431 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
1432 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1433 case btyp_float_complex:
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1434 if (isdouble)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1435 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
1436 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1437 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
1438 break;
18725
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1439
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
1440 #define MAKE_INT_BRANCH(X) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
1441 case btyp_ ## X: \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
1442 if (isnative) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
1443 retval = arg.X ## _array_value ().prod (dim); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
1444 else \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
1445 retval = arg.array_value ().prod (dim); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
1446 break;
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1447
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1448 MAKE_INT_BRANCH (int8);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1449 MAKE_INT_BRANCH (int16);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1450 MAKE_INT_BRANCH (int32);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1451 MAKE_INT_BRANCH (int64);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1452 MAKE_INT_BRANCH (uint8);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1453 MAKE_INT_BRANCH (uint16);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1454 MAKE_INT_BRANCH (uint32);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1455 MAKE_INT_BRANCH (uint64);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1456
18725
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1457 #undef MAKE_INT_BRANCH
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1458
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
1459 // GAGME: Accursed Matlab compatibility...
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1460 case btyp_char:
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1461 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
1462 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1463
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1464 case btyp_bool:
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
1465 if (arg.issparse ())
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1466 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1467 if (isnative)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1468 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
1469 else
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1470 retval = arg.sparse_matrix_value ().prod (dim);
18725
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1471 }
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1472 else if (isnative)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1473 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
1474 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1475 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
1476 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1477
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1478 default:
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21078
diff changeset
1479 err_wrong_type_arg ("prod", arg);
18725
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
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1482 return retval;
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1483 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1484
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1485 /*
14429
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 ([-1; -2; -3]), -6)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1488 %!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
1489 %!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
1490
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 ([-1; -2; -3])), single (-6))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1493 %!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
1494 %!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
1495 %! 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
1496
22737
7abc25e6206a maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22708
diff changeset
1497 ## Test sparse
18725
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 %!assert (prod (sparse ([-1; -2; -3])), sparse (-6))
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1500 ## Commented out until bug #42290 is fixed
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1501 #%!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
1502 #%!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
1503 #%! sparse ([-1+i, -8+8i, -27+27i]))
18725
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1504
14429
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], 1), [3, 8])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1506 %!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
1507 %!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
1508 %!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
1509 %!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
1510 %!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
1511 %!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
1512 %!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
1513 %!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
1514 %!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
1515 %!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
1516 %!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
1517 %!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
1518 %!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
1519
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]), 1), single ([3, 8]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1521 %!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
1522 %!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
1523 %!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
1524 %!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
1525 %!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
1526 %!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
1527 %!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
1528 %!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
1529 %!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
1530 %!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
1531 %!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
1532 %!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
1533 %!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
1534
22737
7abc25e6206a maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22708
diff changeset
1535 ## Test "double" type argument
18725
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 ([-1; -2; -3]), "double"), -6)
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1538 %!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
1539 %!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
1540 %! [-1+i, -8+8i, -27+27i])
18725
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1541
22737
7abc25e6206a maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22708
diff changeset
1542 ## Test "native" type argument
18725
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 (6))
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1544 %!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
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 (int8 ([-1; -2; -3]), "native"), int8 (-6))
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1547 %!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
1548 %!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
1549
22737
7abc25e6206a maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22708
diff changeset
1550 ## Test input validation
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1551 %!error prod ()
18725
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1552 %!error prod (1,2,3)
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1553 %!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
1554 */
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1555
10758
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1556 static bool
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1557 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
1558 {
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1559 int n_args = args.length ();
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1560 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
1561 if (args(i).numel () != 1)
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1562 return false;
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1563
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1564 return true;
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1565 }
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1566
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
1567 template <typename TYPE, typename T>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
1568 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
1569 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
1570 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
1571 int dim)
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10498
diff changeset
1572 {
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10498
diff changeset
1573 int n_args = args.length ();
10758
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1574 if (! (equal_types<T, char>::value
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1575 || equal_types<T, octave_value>::value)
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1576 && 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
1577 {
10758
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1578 // Optimize all scalars case.
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1579 dim_vector dv (1, 1);
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1580 if (dim == -1 || dim == -2)
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1581 dim = -dim - 1;
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1582 else if (dim >= 2)
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1583 dv.resize (dim+1, 1);
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1584 dv(dim) = n_args;
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1585
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1586 result.clear (dv);
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1587
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1588 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
1589 {
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1590 octave_quit ();
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1591
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1592 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
1593 }
10533
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10498
diff changeset
1594 }
10758
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1595 else
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1596 {
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1597 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
1598
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1599 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
1600 {
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1601 octave_quit ();
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1602
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1603 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
1604 }
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1605
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1606 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
1607 }
10533
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10498
diff changeset
1608 }
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10498
diff changeset
1609
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
1610 template <typename TYPE, typename T>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
1611 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
1612 single_type_concat (Sparse<T>& result,
10498
8615b55b5caf fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents: 10436
diff changeset
1613 const octave_value_list& args,
8615b55b5caf fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents: 10436
diff changeset
1614 int dim)
8615b55b5caf fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents: 10436
diff changeset
1615 {
10533
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10498
diff changeset
1616 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
1617 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
1618
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1619 for (int j = 0; j < n_args; j++)
10498
8615b55b5caf fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents: 10436
diff changeset
1620 {
8615b55b5caf fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents: 10436
diff changeset
1621 octave_quit ();
8615b55b5caf fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents: 10436
diff changeset
1622
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1623 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
1624 }
10533
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10498
diff changeset
1625
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1626 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
1627 }
8615b55b5caf fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents: 10436
diff changeset
1628
10533
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10498
diff changeset
1629 // Dispatcher.
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
1630 template <typename TYPE>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
1631 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
1632 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
1633 {
10533
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10498
diff changeset
1634 TYPE result;
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10498
diff changeset
1635
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10498
diff changeset
1636 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
1637
8615b55b5caf fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents: 10436
diff changeset
1638 return result;
8615b55b5caf fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents: 10436
diff changeset
1639 }
8615b55b5caf fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents: 10436
diff changeset
1640
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
1641 template <typename MAP>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
1642 static void
10758
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1643 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
1644 const octave_value_list& args,
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1645 int dim)
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1646 {
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1647 int n_args = args.length ();
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1648 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
1649
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1650 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
1651 {
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1652 octave_quit ();
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1653
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1654 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
1655 }
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1656
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1657 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
1658 }
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1659
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1660 static octave_map
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1661 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
1662 int dim)
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1663 {
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1664 octave_map result;
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1665 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
1666 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
1667 else
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1668 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
1669
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1670 return result;
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1671 }
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1672
4824
4829055e154f [project @ 2004-03-08 18:16:04 by jwe]
jwe
parents: 4806
diff changeset
1673 static octave_value
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1674 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
1675 {
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1676 octave_value retval;
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1677
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1678 // 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
1679 // 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
1680 // type.
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1681
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1682 std::string cname = ov.class_name ();
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1683
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
1684 symbol_table& symtab = __get_symbol_table__ ("attempt_type_conversion");
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23592
diff changeset
1685
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23592
diff changeset
1686 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
1687
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1688 if (fcn.is_defined ())
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1689 {
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20726
diff changeset
1690 octave_value_list result;
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20726
diff changeset
1691
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20726
diff changeset
1692 try
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20726
diff changeset
1693 {
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
1694 result = feval (fcn, ovl (ov), 1);
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20726
diff changeset
1695 }
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
1696 catch (execution_exception& ee)
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20726
diff changeset
1697 {
29163
8f67ad8b3103 maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents: 29117
diff changeset
1698 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
1699 cname.c_str ());
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20726
diff changeset
1700 }
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20726
diff changeset
1701
21885
0806871e3e1e maint: Prefer is_empty() rather than "length () == 0".
Rik <rik@octave.org>
parents: 21782
diff changeset
1702 if (result.empty ())
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1703 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
1704 cname.c_str ());
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1705
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1706 retval = result(0);
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1707 }
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1708 else
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1709 {
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1710 // 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
1711 // dispatch type.
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1712
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23592
diff changeset
1713 fcn = symtab.find_method (dtype, dtype);
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1714
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
1715 if (! fcn.is_defined ())
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
1716 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
1717
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
1718 octave_value_list result;
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
1719
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
1720 try
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1721 {
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
1722 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
1723 }
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
1724 catch (execution_exception& ee)
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
1725 {
29163
8f67ad8b3103 maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents: 29117
diff changeset
1726 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
1727 cname.c_str ());
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1728 }
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
1729
21885
0806871e3e1e maint: Prefer is_empty() rather than "length () == 0".
Rik <rik@octave.org>
parents: 21782
diff changeset
1730 if (result.empty ())
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
1731 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
1732 cname.c_str ());
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1733
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1734 retval = result(0);
13294
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
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1737 return retval;
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
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1740 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
1741 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
1742 const std::string& cattype, int dim)
4806
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1743 {
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1744 octave_value retval;
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1745
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1746 // Get dominant type for list
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1747
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
1748 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
1749
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
1750 symbol_table& symtab = __get_symbol_table__ ("do_class_concat");
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23592
diff changeset
1751
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23592
diff changeset
1752 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
1753
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1754 if (fcn.is_defined ())
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1755 {
20726
25d676f9619c Preface error() messages with name of function when possible.
Rik <rik@octave.org>
parents: 20720
diff changeset
1756 // 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
1757
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20726
diff changeset
1758 octave_value_list tmp2;
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20726
diff changeset
1759
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20726
diff changeset
1760 try
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1761 {
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
1762 tmp2 = feval (fcn, ovl, 1);
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20726
diff changeset
1763 }
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
1764 catch (execution_exception& ee)
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20726
diff changeset
1765 {
29163
8f67ad8b3103 maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents: 29117
diff changeset
1766 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
1767 }
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1768
21885
0806871e3e1e maint: Prefer is_empty() rather than "length () == 0".
Rik <rik@octave.org>
parents: 21782
diff changeset
1769 if (tmp2.empty ())
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20726
diff changeset
1770 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
1771 cattype.c_str ());
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1772
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1773 retval = tmp2(0);
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1774 }
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1775 else
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1776 {
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1777 // 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
1778 // 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
1779 // default operation for octave_class values.
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1780
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1781 octave_idx_type j = 0;
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1782 octave_idx_type len = ovl.length ();
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1783 octave_value_list tmp (len, octave_value ());
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1784 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
1785 {
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1786 octave_value elt = ovl(k);
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1787
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1788 std::string t1_type = elt.class_name ();
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1789
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1790 if (t1_type == dtype)
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1791 tmp(j++) = elt;
23587
0c468af9dc00 maint: Deprecate is_object and replace with isobject.
Rik <rik@octave.org>
parents: 23586
diff changeset
1792 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
1793 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
1794 }
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1795
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1796 tmp.resize (j);
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1797
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1798 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
1799
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1800 std::string cname = tmp(0).class_name ();
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1801 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
1802
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1803 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
1804 }
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1805
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1806 return retval;
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
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1809 static octave_value
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1810 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
1811 {
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1812 octave_value retval;
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1813
20811
5979314bb15a Fix BIST tests for rows.
Rik <rik@octave.org>
parents: 20810
diff changeset
1814 // 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
1815 // 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
1816 // counts.
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1817 octave_value_list args = xargs;
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1818
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
1819 int n_args = args.length ();
4806
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1820
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1821 if (n_args == 0)
5714
24f6a13878c2 [project @ 2006-03-23 21:46:09 by jwe]
jwe
parents: 5677
diff changeset
1822 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
1823 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
1824 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
1825 else if (n_args > 1)
4824
4829055e154f [project @ 2004-03-08 18:16:04 by jwe]
jwe
parents: 4806
diff changeset
1826 {
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1827 std::string result_type;
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1828
19399
2304ddfd736f Restore warning Octave:num-to-str missing since 3.2.4 (bug #43814).
Rik <rik@octave.org>
parents: 18869
diff changeset
1829 bool all_strings_p = true;
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1830 bool all_sq_strings_p = true;
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1831 bool all_dq_strings_p = true;
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1832 bool all_real_p = true;
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1833 bool all_cmplx_p = true;
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1834 bool any_sparse_p = false;
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1835 bool any_cell_p = false;
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1836 bool any_class_p = false;
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1837
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1838 bool first_elem_is_struct = false;
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1839
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1840 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
1841 {
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1842 if (i == 0)
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1843 {
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1844 result_type = args(i).class_name ();
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1845
23584
7ed6b258db91 maint: Deprecate is_map and replace with isstruct.
Rik <rik@octave.org>
parents: 23583
diff changeset
1846 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
1847 }
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1848 else
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
1849 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
1850
19399
2304ddfd736f Restore warning Octave:num-to-str missing since 3.2.4 (bug #43814).
Rik <rik@octave.org>
parents: 18869
diff changeset
1851 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
1852 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
1853 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
1854 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
1855 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
1856 all_dq_strings_p = false;
23582
0cc2011d800e maint: Deprecate is_real_type and replace with isreal.
Rik <rik@octave.org>
parents: 23581
diff changeset
1857 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
1858 all_real_p = false;
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
1859 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
1860 || args(i).isreal ()))
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1861 all_cmplx_p = false;
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
1862 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
1863 any_sparse_p = true;
23576
00e518162fda maint: Deprecate is_cell and replace with iscell.
Rik <rik@octave.org>
parents: 23575
diff changeset
1864 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
1865 any_cell_p = true;
23587
0c468af9dc00 maint: Deprecate is_object and replace with isobject.
Rik <rik@octave.org>
parents: 23586
diff changeset
1866 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
1867 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
1868 }
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1869
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1870 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
1871 {
22895
0ab9eecbb165 Concatenate empty matrices/cells in cat() the same as the parser (bug #49759).
Rik <rik@octave.org>
parents: 22853
diff changeset
1872 int j = 0;
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1873 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
1874 {
23576
00e518162fda maint: Deprecate is_cell and replace with iscell.
Rik <rik@octave.org>
parents: 23575
diff changeset
1875 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
1876 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
1877 else
0ab9eecbb165 Concatenate empty matrices/cells in cat() the same as the parser (bug #49759).
Rik <rik@octave.org>
parents: 22853
diff changeset
1878 {
23577
80c42f4cca13 maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents: 23576
diff changeset
1879 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
1880 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
1881 else
0ab9eecbb165 Concatenate empty matrices/cells in cat() the same as the parser (bug #49759).
Rik <rik@octave.org>
parents: 22853
diff changeset
1882 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
1883 }
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1884 }
22895
0ab9eecbb165 Concatenate empty matrices/cells in cat() the same as the parser (bug #49759).
Rik <rik@octave.org>
parents: 22853
diff changeset
1885 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
1886 args.resize (n_args);
13294
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
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1889 if (any_class_p)
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1890 {
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
1891 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
1892 }
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1893 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
1894 {
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1895 if (any_sparse_p)
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
1896 {
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1897 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
1898 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
1899 else
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1900 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
1901 }
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1902 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1903 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1904 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
1905 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
1906 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
1907 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
1908 }
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1909 }
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1910 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
1911 {
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1912 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
1913 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
1914 else
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1915 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
1916 }
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1917 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
1918 {
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23449
diff changeset
1919 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
1920
19399
2304ddfd736f Restore warning Octave:num-to-str missing since 3.2.4 (bug #43814).
Rik <rik@octave.org>
parents: 18869
diff changeset
1921 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
1922 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
1923 "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
1924 else
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
1925 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
1926
2304ddfd736f Restore warning Octave:num-to-str missing since 3.2.4 (bug #43814).
Rik <rik@octave.org>
parents: 18869
diff changeset
1927 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
1928
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1929 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
1930 }
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1931 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
1932 {
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1933 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
1934 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
1935 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
1936 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
1937 }
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1938 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
1939 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
1940 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
1941 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
1942 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
1943 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
1944 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
1945 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
1946 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
1947 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
1948 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
1949 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
1950 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
1951 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
1952 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
1953 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
1954 else if (result_type == "cell")
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1955 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
1956 else if (result_type == "struct")
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1957 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
1958 else
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1959 {
20218
b2100e1659ac maint: Use cuddled parentheses when indexing dimension_vectors.
Rik <rik@octave.org>
parents: 20183
diff changeset
1960 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
1961
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1962 // Default concatenation.
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1963 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
1964 = &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
1965
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1966 if (dim == -1 || dim == -2)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1967 {
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1968 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
1969 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
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
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1972 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
1973 {
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1974 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
1975 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
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
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1978 // 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
1979 // 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
1980 // 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
1981 // 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
1982 // 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
1983 // 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
1984 // 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
1985 //
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1986 // 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
1987 //
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
1988 // 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
1989 //
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21730
diff changeset
1990 // 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
1991 // 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
1992
18112
b560bac0fca2 maint: Don't use space between 'args' and '(' when doing indexing.
Rik <rik@octave.org>
parents: 18100
diff changeset
1993 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
1994 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
1995
21660
53728df3e4c9 maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents: 21602
diff changeset
1996 int dv_len = dv.ndims ();
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1997 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
1998
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1999 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
2000 {
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
2001 // 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
2002 // 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
2003 // 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
2004 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
2005
18112
b560bac0fca2 maint: Don't use space between 'args' and '(' when doing indexing.
Rik <rik@octave.org>
parents: 18100
diff changeset
2006 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
2007
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
2008 if (dim >= dv_len)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
2009 {
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
2010 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
2011 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
2012
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
2013 break;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
2014 }
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
2015 else
21660
53728df3e4c9 maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents: 21602
diff changeset
2016 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
2017 }
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
2018 retval = tmp;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
2019 }
4806
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
2020 }
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
2021 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
2022 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
2023
4806
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
2024 return retval;
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
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
2027 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
2028 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
2029 @deftypefn {} {} horzcat (@var{array1}, @var{array2}, @dots{}, @var{arrayN})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2030 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
2031 @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
2032
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2033 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
2034 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
2035
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2036 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2037 @var{hcat} = [ @var{array1}, @var{array2}, @dots{} ]
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2038 @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
2039 @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
2040 @end deftypefn */)
4806
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
2041 {
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
2042 return do_cat (args, -2, "horzcat");
4806
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
2043 }
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
2044
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
2045 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2046 ## 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
2047 %!test
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2048 %! 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
2049 %! assert (horzcat ("", 65*ones (1,10)), "AAAAAAAAAA");
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2050 %! 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
2051
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2052 %!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
2053 %!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
2054 %!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
2055 %!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
2056 %!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
2057 %!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
2058 %!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
2059 %!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
2060 %!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
2061 %!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
2062 %!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
2063 %!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
2064 %!test
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2065 %! 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
2066 %! 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
2067
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2068 %!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
2069 %!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
2070 %!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
2071 %!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
2072 %!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
2073 %!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
2074 %!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
2075 %!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
2076 %!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
2077 %!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
2078 %!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
2079 %!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
2080 %!test
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2081 %! 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
2082 %! 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
2083
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2084 %!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
2085 %!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
2086 %!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
2087 %!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
2088 %!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
2089 %!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
2090 %!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
2091 %!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
2092 %!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
2093 %!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
2094 %!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
2095 %!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
2096 %!test
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2097 %! 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
2098 %! 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
2099
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2100 %!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
2101 %!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
2102 %!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
2103 %!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
2104 %!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
2105 %!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
2106 %!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
2107 %!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
2108 %!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
2109 %!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
2110 %!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
2111 %!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
2112 %!test
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2113 %! 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
2114 %! 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
2115
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2116 %!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
2117 %!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
2118 %!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
2119 %!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
2120 %!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
2121 %!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
2122 %!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
2123 %!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
2124 %!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
2125 %!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
2126 %!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
2127 %!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
2128 %!test
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2129 %! 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
2130 %! 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
2131
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2132 %!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
2133 %!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
2134 %!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
2135 %!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
2136 %!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
2137 %!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
2138 %!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
2139 %!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
2140 %!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
2141 %!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
2142 %!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
2143 %!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
2144 %!test
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2145 %! 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
2146 %! 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
2147
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2148 %!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
2149 %!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
2150 %!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
2151 %!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
2152 %!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
2153 %!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
2154 %!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
2155 %!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
2156 %!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
2157 %!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
2158 %!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
2159 %!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
2160 %!test
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2161 %! 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
2162 %! 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
2163
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2164 %!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
2165 %!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
2166 %!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
2167 %!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
2168 %!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
2169 %!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
2170 %!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
2171 %!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
2172 %!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
2173 %!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
2174 %!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
2175 %!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
2176 %!test
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2177 %! 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
2178 %! 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
2179
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2180 %!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
2181 %!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
2182 %!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
2183 %!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
2184 %!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
2185 %!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
2186 %!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
2187 %!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
2188 %!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
2189 %!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
2190 %!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
2191 %!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
2192 %!test
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2193 %! 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
2194 %! 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
2195
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2196 %!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
2197 %!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
2198 %!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
2199 %!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
2200 %!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
2201 %!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
2202 %!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
2203 %!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
2204 %!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
2205 %!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
2206 %!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
2207 %!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
2208 %!test
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2209 %! 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
2210 %! 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
2211
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2212 %!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
2213 %!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
2214 %!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
2215 %!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
2216 %!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
2217 %!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
2218 %!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
2219 %!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
2220 %!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
2221 %!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
2222 %!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
2223 %!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
2224 %!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
2225
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2226 %!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
2227 %!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
2228 %!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
2229 %!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
2230 %!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
2231 %!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
2232 %!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
2233 %!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
2234 %!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
2235 %!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
2236 %!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
2237 %!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
2238 %!test
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2239 %! 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
2240 %! 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
2241
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2242 %!test
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2243 %! 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
2244 %! 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
2245 %! 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
2246 %! 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
2247 %! 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
2248 %! 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
2249 %! 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
2250 %! 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
2251 %! 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
2252 %! 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
2253 %! 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
2254 %! 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
2255 %! 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
2256 %! 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
2257
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2258 %!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
2259
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2260 %!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
2261
28915
c40a367a84c0 maint: Use Octave convention of space after function name in libinterp/.
Rik <rik@octave.org>
parents: 28888
diff changeset
2262 %!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
2263 %!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
2264 */
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
2265
4806
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
2266 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
2267 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
2268 @deftypefn {} {} vertcat (@var{array1}, @var{array2}, @dots{}, @var{arrayN})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2269 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
2270 @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
2271
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2272 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
2273 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
2274
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2275 @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 @var{vcat} = [ @var{array1}; @var{array2}; @dots{} ]
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2277 @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
2278 @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
2279 @end deftypefn */)
4806
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
2280 {
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
2281 return do_cat (args, -1, "vertcat");
4806
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
2282 }
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
2283
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
2284 /*
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
2285 %!test
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2286 %! 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
2287 %! 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
2288 %! {"foo"; "bar"; "bazoloa"; "a"; "bc"; "def"});
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
4758
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
2291 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
2292 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
2293 @deftypefn {} {} cat (@var{dim}, @var{array1}, @var{array2}, @dots{}, @var{arrayN})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2294 Return the concatenation of N-D array objects, @var{array1},
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2295 @var{array2}, @dots{}, @var{arrayN} along dimension @var{dim}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2296
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2297 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2298 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2299 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
2300 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
2301 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
2302 @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
2303 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
2304 @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
2305 @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
2306
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2307 Alternatively, we can concatenate @var{A} and @var{B} along the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2308 second dimension in the following way:
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2309
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2310 @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 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2312 [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
2313 @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
2314 @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
2315
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2316 @var{dim} can be larger than the dimensions of the N-D array objects
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2317 and the result will thus have @var{dim} dimensions as the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2318 following example shows:
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2319
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2320 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2321 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2322 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
2323 @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
2324
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2325 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
2326 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
2327
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2328 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
2329
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2330 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
2331 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
2332 @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
2333 @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
2334 @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
2335 @end deftypefn */)
4758
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
2336 {
20850
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
2337 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
2338 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
2339
20850
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
2340 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
2341
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
2342 if (dim < 0)
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
2343 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
2344
21127
df7891224709 maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents: 21121
diff changeset
2345 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
2346 }
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
2347
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
2348 /*
14085
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 14022
diff changeset
2349 %!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
2350 %! 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
2351 %!
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2352 %! 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
2353 %! 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
2354 %! 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
2355 %! 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
2356 %! 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
2357 %! 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
2358 %! 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
2359 %! 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
2360 %! 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
2361 %! 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
2362 %!
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2363 %! 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
2364 %! 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
2365 %! 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
2366 %! 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
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));
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2371 %!
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2372 %! if (nargin == 3 || cmplx)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2373 %! 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
2374 %! 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
2375 %! 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
2376 %! 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
2377 %! 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
2378 %! 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
2379 %! 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
2380 %! 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
2381 %! 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
2382 %! 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
2383 %! 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
2384 %! 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
2385 %! 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
2386 %! 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
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));
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2391 %!
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2392 %! 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
2393 %! 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
2394 %! 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
2395 %! 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
2396 %! 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
2397 %! 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
2398 %! 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
2399 %! 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
2400 %! 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
2401 %! 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
2402 %! 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
2403 %! 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
2404 %! 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
2405 %! 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
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));
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2410 %!
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2411 %! 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
2412 %! 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
2413 %! 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
2414 %! 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
2415 %! 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
2416 %! 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
2417 %! 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
2418 %! 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
2419 %! 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
2420 %! 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
2421 %! 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
2422 %! 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
2423 %! 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
2424 %! 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
2425 %!
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2426 %! 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
2427 %! 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
2428 %! 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
2429 %! 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
2430 %! 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
2431 %! 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
2432 %! 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
2433 %! 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
2434 %! 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
2435 %! 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
2436 %! endif
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2437 %! ret = true;
14085
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 14022
diff changeset
2438 %!endfunction
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 14022
diff changeset
2439
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2440 %!assert (__testcat ("double", "double", "double"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2441 %!assert (__testcat ("single", "double", "single"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2442 %!assert (__testcat ("double", "single", "single"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2443 %!assert (__testcat ("single", "single", "single"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2444
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2445 %!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
2446 %!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
2447 %!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
2448 %!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
2449 %!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
2450 %!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
2451 %!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
2452 %!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
2453 %!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
2454 %!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
2455 %!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
2456 %!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
2457 %!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
2458 %!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
2459 %!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
2460 %!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
2461 %!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
2462 %!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
2463 %!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
2464 %!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
2465
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2466 %!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
2467 %!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
2468 %!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
2469 %!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
2470 %!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
2471 %!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
2472 %!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
2473 %!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
2474 %!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
2475 %!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
2476 %!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
2477 %!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
2478 %!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
2479 %!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
2480 %!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
2481 %!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
2482 %!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
2483 %!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
2484 %!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
2485 %!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
2486
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 14022
diff changeset
2487 %!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
2488 %!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
2489 %!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
2490 %!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
2491
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), cat (3, 1, 2))
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 (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
2495
18678
6113e0c6920b maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents: 18676
diff changeset
2496 %!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
2497 %!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
2498
23573
1b4f4ec53b4a use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents: 23572
diff changeset
2499 %!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
2500 %! A = [];
0ab9eecbb165 Concatenate empty matrices/cells in cat() the same as the parser (bug #49759).
Rik <rik@octave.org>
parents: 22853
diff changeset
2501 %! 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
2502 %! 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
2503 %! 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
2504
14085
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 14022
diff changeset
2505 %!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
2506 %!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
2507 */
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
2508
4593
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
2509 static octave_value
6959
47f4f4e88166 [project @ 2007-10-04 20:43:32 by jwe]
jwe
parents: 6953
diff changeset
2510 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
2511 {
20850
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
2512 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
2513 print_usage ();
4593
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
2514
20850
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
2515 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
2516
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
2517 // 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
2518 // and pass that to permute?
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
2519 int n = vec.numel ();
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
2520 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
2521 vec(i)--;
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
2522
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
2523 return octave_value (args(0).permute (vec, inv));
4593
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
2524 }
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
2525
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
2526 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
2527 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2528 @deftypefn {} {} permute (@var{A}, @var{perm})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2529 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
2530
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2531 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
2532 @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
2533 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
2534 @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
2535
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2536 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2537 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2538 @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
2539 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
2540 @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
2541
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2542 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
2543 @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
2544
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2545 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
2546 @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
2547
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2548 ## 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
2549 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
2550 @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
2551 @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
2552 @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
2553 @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
2554 @end deftypefn */)
4593
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
2555 {
6959
47f4f4e88166 [project @ 2007-10-04 20:43:32 by jwe]
jwe
parents: 6953
diff changeset
2556 return do_permute (args, false);
4593
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
2557 }
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
2558
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
2559 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
2560 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
2561 @deftypefn {} {} ipermute (@var{A}, @var{iperm})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2562 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
2563
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2564 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
2565
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2566 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2567 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
2568 @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
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 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2571 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
2572 @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
2573 @end deftypefn */)
4593
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
2574 {
6959
47f4f4e88166 [project @ 2007-10-04 20:43:32 by jwe]
jwe
parents: 6953
diff changeset
2575 return do_permute (args, true);
4593
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
2576 }
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
2577
3195
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3186
diff changeset
2578 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
2579 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
2580 @deftypefn {} {} length (@var{a})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2581 Return the length of the object @var{a}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2582
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2583 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
2584 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
2585 of elements along the largest dimension
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2586 (equivalent to @w{@code{max (size (@var{a}))}}).
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2587 @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
2588 @end deftypefn */)
3195
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3186
diff changeset
2589 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2590 if (args.length () != 1)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
2591 print_usage ();
3195
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3186
diff changeset
2592
21127
df7891224709 maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents: 21121
diff changeset
2593 return ovl (args(0).length ());
3195
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3186
diff changeset
2594 }
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3186
diff changeset
2595
4554
78e34346f6fd [project @ 2003-10-27 22:01:49 by jwe]
jwe
parents: 4545
diff changeset
2596 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
2597 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
2598 @deftypefn {} {} ndims (@var{a})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2599 Return the number of dimensions of @var{a}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2600
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2601 For any array, the result will always be greater than or equal to 2.
26046
ff0aa19333c9 doc: grammarcheck C++ files in libinterp/ directory.
Rik <rik@octave.org>
parents: 25928
diff changeset
2602 Trailing singleton dimensions are not counted, i.e., tailing dimensions @var{d}
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
2603 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
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 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2606 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2607 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
2608 @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
2609 @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
2610 @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
2611 @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
2612 @end deftypefn */)
4554
78e34346f6fd [project @ 2003-10-27 22:01:49 by jwe]
jwe
parents: 4545
diff changeset
2613 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2614 if (args.length () != 1)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
2615 print_usage ();
4554
78e34346f6fd [project @ 2003-10-27 22:01:49 by jwe]
jwe
parents: 4545
diff changeset
2616
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
2617 // 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
2618 // 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
2619 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
2620
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 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
2622
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 // 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
2624 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
2625 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
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 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
2628 }
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
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 %!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
2632 %!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
2633 %!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
2634 */
4554
78e34346f6fd [project @ 2003-10-27 22:01:49 by jwe]
jwe
parents: 4545
diff changeset
2635
4559
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4556
diff changeset
2636 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
2637 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
2638 @deftypefn {} {} numel (@var{a})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2639 @deftypefnx {} {} numel (@var{a}, @var{idx1}, @var{idx2}, @dots{})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2640 Return the number of elements in the object @var{a}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2641
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2642 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
2643 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
2644
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2645 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2646 @var{a}(@var{idx1}, @var{idx2}, @dots{})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2647 @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
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 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
2650
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2651 @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 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2653 @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
2654 @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
2655 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
2656 @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
2657 @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
2658
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2659 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2660 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
2661 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
2662 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
2663
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2664 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2665 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2666 @var{a} = ones (5, 3);
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2667 numel (@var{a}, 2, ":")
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2668 @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
2669 @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
2670
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2671 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2672 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
2673
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2674 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
2675 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
2676 @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
2677 @end deftypefn */)
4559
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4556
diff changeset
2678 {
20850
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
2679 int nargin = args.length ();
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
2680
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
2681 if (nargin == 0)
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
2682 print_usage ();
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
2683
4559
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4556
diff changeset
2684 octave_value retval;
9329
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
2685
9705
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2686 if (nargin == 1)
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2687 retval = args(0).numel ();
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2688 else if (nargin > 1)
4559
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4556
diff changeset
2689 {
9705
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2690 // 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
2691 // 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
2692 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
2693 }
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4556
diff changeset
2694
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4556
diff changeset
2695 return retval;
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4556
diff changeset
2696 }
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4556
diff changeset
2697
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1940
diff changeset
2698 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
2699 doc: /* -*- texinfo -*-
22699
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2700 @deftypefn {} {@var{sz} =} size (@var{a})
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2701 @deftypefnx {} {@var{dim_sz} =} size (@var{a}, @var{dim})
30230
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2702 @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
2703 @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
2704 Return a row vector with the size (number of elements) of each dimension for
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2705 the object @var{a}.
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2706
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2707 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
2708 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
2709 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
2710
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2711 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
2712 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
2713 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
2714 first argument, the number of columns, dimension 2, is returned in the
25578
32ddc111ff49 doc: small fixes to size() and plot.txi (bug #54283).
Rik <rik@octave.org>
parents: 25574
diff changeset
2715 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
2716 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
2717 remaining dimensions in the final output argument.
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2718
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2719 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
2720
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2721 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2722 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2723 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
2724 @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
2725 @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
2726 @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
2727
22699
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2728 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
2729
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2730 @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 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2732 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
2733 @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
2734 @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
2735 @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
2736
22699
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2737 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
2738
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2739 @example
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2740 @group
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2741 [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
2742 @result{} nr = 3
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2743 @result{} nc = 2
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2744 @end group
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2745 @end example
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2746
25574
0e09d5fd7dab doc: Clarify description of Example 4 for size() (bug #54283).
Rik <rik@octave.org>
parents: 25471
diff changeset
2747 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
2748
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2749 @example
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2750 @group
22845
e23f7f47d8a3 doc: Small fixes to docstrings (bug #49733).
Rik <rik@octave.org>
parents: 22827
diff changeset
2751 [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
2752 @result{} nr = 2
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2753 @result{} remainder = 60
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2754 @end group
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2755 @end example
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2756
22429
00986ee43956 doc: Add more @seealso links to numel, size, size_equal.
Rik <rik@octave.org>
parents: 22407
diff changeset
2757 @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
2758 @end deftypefn */)
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
2759 {
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
2760 int nargin = args.length ();
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
2761
30230
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2762 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
2763 print_usage ();
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2764
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2765 // 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
2766
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2767 Matrix m;
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 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
2770 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
2771
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4512
diff changeset
2772 if (nargin == 1)
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
2773 {
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4512
diff changeset
2774 if (nargout > 1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
2775 {
30230
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2776 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
2777 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
2778 }
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2779
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2780 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
2781
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2782 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
2783 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
2784 }
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2785 else
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2786 {
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2787 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
2788
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2789 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
2790 {
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2791 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
2792
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2793 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
2794 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
2795 }
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4512
diff changeset
2796 else
30230
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2797 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
2798
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2799 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
2800 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
2801
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2802 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
2803
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2804 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
2805
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2806 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
2807 {
30230
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2808 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
2809
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2810 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
2811 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
2812 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
2813
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2814 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
2815 }
1031
59f5eb2d5eb3 [project @ 1995-01-15 21:11:11 by jwe]
jwe
parents: 1009
diff changeset
2816 }
30230
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 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
2819 {
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2820 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
2821
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2822 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
2823 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
2824
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2825 return retval;
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2826 }
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2827
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2828 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
2829 }
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 ## Plain call
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 %!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
2835
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2836 %!test
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2837 %! [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
2838 %! 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
2839 %! 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
2840
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2841 %!test
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2842 %! [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
2843 %! 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
2844 %! 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
2845
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2846 ## 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
2847
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2848 %!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
2849 %!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
2850
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2851 ## 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
2852
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], 3), 1)
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2854 %!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
2855
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2856 ## 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
2857
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2858 %!test
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2859 %! [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
2860 %! 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
2861 %! 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
2862 %! 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
2863 %! 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
2864
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2865 ## 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
2866
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2867 %!test
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2868 %! 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
2869 %! 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
2870 %! 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
2871 %! 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
2872 %! 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
2873 %! [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
2874 %! 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
2875 %! 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
2876 %! [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
2877 %! 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
2878 %! 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
2879 %! end
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2880 %! end
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2881
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2882 ## 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
2883
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2884 %!test
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2885 %! 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
2886 %! 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
2887 %! 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
2888 %! 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
2889 %! 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
2890 %! 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
2891 %! [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
2892 %! 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
2893 %! 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
2894 %! 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
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 %! end
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2900 %! end
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2901 %! end
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2902
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2903 %!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
2904 %! [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
2905 */
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
2906
6156
a46f14cdbecd [project @ 2006-11-13 19:20:23 by jwe]
jwe
parents: 6133
diff changeset
2907 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
2908 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
2909 @deftypefn {} {} size_equal (@var{a}, @var{b}, @dots{})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2910 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
2911
22429
00986ee43956 doc: Add more @seealso links to numel, size, size_equal.
Rik <rik@octave.org>
parents: 22407
diff changeset
2912 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
2913 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
2914 @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
2915 @end deftypefn */)
6156
a46f14cdbecd [project @ 2006-11-13 19:20:23 by jwe]
jwe
parents: 6133
diff changeset
2916 {
6561
dc83c15d7149 [project @ 2007-04-23 16:58:17 by jwe]
jwe
parents: 6556
diff changeset
2917 int nargin = args.length ();
dc83c15d7149 [project @ 2007-04-23 16:58:17 by jwe]
jwe
parents: 6556
diff changeset
2918
8947
1e4b3149365a allow size_equal called with 1 arg
Jaroslav Hajek <highegg@gmail.com>
parents: 8934
diff changeset
2919 if (nargin >= 1)
6156
a46f14cdbecd [project @ 2006-11-13 19:20:23 by jwe]
jwe
parents: 6133
diff changeset
2920 {
a46f14cdbecd [project @ 2006-11-13 19:20:23 by jwe]
jwe
parents: 6133
diff changeset
2921 dim_vector a_dims = args(0).dims ();
6561
dc83c15d7149 [project @ 2007-04-23 16:58:17 by jwe]
jwe
parents: 6556
diff changeset
2922
dc83c15d7149 [project @ 2007-04-23 16:58:17 by jwe]
jwe
parents: 6556
diff changeset
2923 for (int i = 1; i < nargin; ++i)
dc83c15d7149 [project @ 2007-04-23 16:58:17 by jwe]
jwe
parents: 6556
diff changeset
2924 {
dc83c15d7149 [project @ 2007-04-23 16:58:17 by jwe]
jwe
parents: 6556
diff changeset
2925 dim_vector b_dims = args(i).dims ();
dc83c15d7149 [project @ 2007-04-23 16:58:17 by jwe]
jwe
parents: 6556
diff changeset
2926
dc83c15d7149 [project @ 2007-04-23 16:58:17 by jwe]
jwe
parents: 6556
diff changeset
2927 if (a_dims != b_dims)
21078
49852ff04747 maint: Remove unnecessary declarations of retval.
Rik <rik@octave.org>
parents: 21062
diff changeset
2928 return ovl (false);
6561
dc83c15d7149 [project @ 2007-04-23 16:58:17 by jwe]
jwe
parents: 6556
diff changeset
2929 }
6156
a46f14cdbecd [project @ 2006-11-13 19:20:23 by jwe]
jwe
parents: 6133
diff changeset
2930 }
a46f14cdbecd [project @ 2006-11-13 19:20:23 by jwe]
jwe
parents: 6133
diff changeset
2931
21078
49852ff04747 maint: Remove unnecessary declarations of retval.
Rik <rik@octave.org>
parents: 21062
diff changeset
2932 return ovl (true);
6156
a46f14cdbecd [project @ 2006-11-13 19:20:23 by jwe]
jwe
parents: 6133
diff changeset
2933 }
a46f14cdbecd [project @ 2006-11-13 19:20:23 by jwe]
jwe
parents: 6133
diff changeset
2934
5602
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5533
diff changeset
2935 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
2936 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
2937 @deftypefn {} {@var{n} =} nnz (@var{a})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2938 Return the number of nonzero elements in @var{a}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2939 @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
2940 @end deftypefn */)
5602
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5533
diff changeset
2941 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2942 if (args.length () != 1)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
2943 print_usage ();
5602
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5533
diff changeset
2944
21127
df7891224709 maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents: 21121
diff changeset
2945 return ovl (args(0).nnz ());
5602
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5533
diff changeset
2946 }
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5533
diff changeset
2947
24859
00ecff875f8a Add nnz implementation for Range type (bug #53185).
maorshutman <maorus12@gmail.com>
parents: 24634
diff changeset
2948 /*
00ecff875f8a Add nnz implementation for Range type (bug #53185).
maorshutman <maorus12@gmail.com>
parents: 24634
diff changeset
2949 %!assert (nnz (1:5), 5)
00ecff875f8a Add nnz implementation for Range type (bug #53185).
maorshutman <maorus12@gmail.com>
parents: 24634
diff changeset
2950 %!assert (nnz (-5:-1), 5)
00ecff875f8a Add nnz implementation for Range type (bug #53185).
maorshutman <maorus12@gmail.com>
parents: 24634
diff changeset
2951 %!assert (nnz (0:5), 5)
00ecff875f8a Add nnz implementation for Range type (bug #53185).
maorshutman <maorus12@gmail.com>
parents: 24634
diff changeset
2952 %!assert (nnz (-5:0), 5)
00ecff875f8a Add nnz implementation for Range type (bug #53185).
maorshutman <maorus12@gmail.com>
parents: 24634
diff changeset
2953 %!assert (nnz (-5:5), 10)
00ecff875f8a Add nnz implementation for Range type (bug #53185).
maorshutman <maorus12@gmail.com>
parents: 24634
diff changeset
2954 %!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
2955 %!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
2956 %!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
2957 %!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
2958 %!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
2959 %!assert (nnz ([1:5] * 0), 0)
00ecff875f8a Add nnz implementation for Range type (bug #53185).
maorshutman <maorus12@gmail.com>
parents: 24634
diff changeset
2960 %!assert (nnz ([-5:-1] * 0), 0)
00ecff875f8a Add nnz implementation for Range type (bug #53185).
maorshutman <maorus12@gmail.com>
parents: 24634
diff changeset
2961 %!assert (nnz ([-1:1] * 0), 0)
00ecff875f8a Add nnz implementation for Range type (bug #53185).
maorshutman <maorus12@gmail.com>
parents: 24634
diff changeset
2962 */
00ecff875f8a Add nnz implementation for Range type (bug #53185).
maorshutman <maorus12@gmail.com>
parents: 24634
diff changeset
2963
5604
2857357f9d3c [project @ 2006-01-31 18:22:59 by jwe]
jwe
parents: 5602
diff changeset
2964 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
2965 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
2966 @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
2967 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
2968
27081
c0d8ce61c1c9 Always reserve at least 1 element of storage for sparse matrices (bug #56232).
Rik <rik@octave.org>
parents: 27034
diff changeset
2969 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
2970 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
2971 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
2972
c0d8ce61c1c9 Always reserve at least 1 element of storage for sparse matrices (bug #56232).
Rik <rik@octave.org>
parents: 27034
diff changeset
2973 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
2974 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
2975 @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
2976 @end deftypefn */)
5604
2857357f9d3c [project @ 2006-01-31 18:22:59 by jwe]
jwe
parents: 5602
diff changeset
2977 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2978 if (args.length () != 1)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
2979 print_usage ();
5604
2857357f9d3c [project @ 2006-01-31 18:22:59 by jwe]
jwe
parents: 5602
diff changeset
2980
21127
df7891224709 maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents: 21121
diff changeset
2981 return ovl (args(0).nzmax ());
5604
2857357f9d3c [project @ 2006-01-31 18:22:59 by jwe]
jwe
parents: 5602
diff changeset
2982 }
2857357f9d3c [project @ 2006-01-31 18:22:59 by jwe]
jwe
parents: 5602
diff changeset
2983
5677
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
2984 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
2985 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
2986 @deftypefn {} {} rows (@var{a})
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
2987 Return the number of rows of @var{a}. This is equivalent 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
2988 @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
2989 @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
2990 @end deftypefn */)
5677
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
2991 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2992 if (args.length () != 1)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
2993 print_usage ();
5677
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
2994
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
2995 // 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
2996 // 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
2997
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
2998 return ovl ((octave_value (args(0)).size ())(0));
5677
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
2999 }
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
3000
20810
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
3001 /*
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
3002 %!assert (rows (ones (2,5)), 2)
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
3003 %!assert (rows (ones (5,2)), 5)
20811
5979314bb15a Fix BIST tests for rows.
Rik <rik@octave.org>
parents: 20810
diff changeset
3004 %!assert (rows (ones (5,4,3,2)), 5)
20810
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
3005 %!assert (rows (ones (3,4,5,2)), 3)
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
3006
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
3007 %!assert (rows (cell (2,5)), 2)
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
3008 %!assert (rows (cell (5,2)), 5)
20811
5979314bb15a Fix BIST tests for rows.
Rik <rik@octave.org>
parents: 20810
diff changeset
3009 %!assert (rows (cell (5,4,3,2)), 5)
20810
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
3010 %!assert (rows (cell (3,4,5,2)), 3)
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
3011
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
3012 %!test
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
3013 %! x(2,5,3).a = 1;
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
3014 %! assert (rows (x), 2);
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
3015 %! y(5,4,3).b = 2;
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
3016 %! assert (rows (y), 5);
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 %!assert (rows ("Hello World"), 1)
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
3019
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
3020 %!assert (rows ([]), 0)
20815
6935b8f038cc Fix BIST tests for rows()
Rik <rik@octave.org>
parents: 20811
diff changeset
3021 %!assert (rows (zeros (2,0)), 2)
20810
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
3022
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
3023 ## Test input validation
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
3024 %!error rows ()
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
3025 %!error rows (1,2)
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
3026 */
5677
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
3027
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
3028 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
3029 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
3030 @deftypefn {} {} columns (@var{a})
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
3031 Return the number of columns of @var{a}. This is equivalent 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
3032 @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
3033 @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
3034 @end deftypefn */)
5677
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
3035 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3036 if (args.length () != 1)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
3037 print_usage ();
5677
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
3038
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
3039 // 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
3040 // 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
3041
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
3042 return ovl ((octave_value (args(0)).size ())(1));
5677
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
3043 }
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
3044
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1940
diff changeset
3045 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
3046 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
3047 @deftypefn {} {} sum (@var{x})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3048 @deftypefnx {} {} sum (@var{x}, @var{dim})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3049 @deftypefnx {} {} sum (@dots{}, "native")
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3050 @deftypefnx {} {} sum (@dots{}, "double")
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3051 @deftypefnx {} {} sum (@dots{}, "extra")
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3052 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
3053
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3054 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
3055
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3056 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
3057 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
3058 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
3059 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
3060 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
3061 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
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 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
3064
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3065 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3066 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3067 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
3068 @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
3069 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
3070 @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
3071 @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
3072 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3073
25286
44c0aca121cc doc: Clarify docstring for sum (bug #53698).
Rik <rik@octave.org>
parents: 25103
diff changeset
3074 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
3075 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
3076
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3077 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
3078 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
3079 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
3080 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
3081 @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
3082 @end deftypefn */)
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
3083 {
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
3084 int nargin = args.length ();
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
3085
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
3086 bool isnative = false;
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
3087 bool isdouble = false;
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
3088 bool isextra = false;
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
3089
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
3090 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
3091 {
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
3092 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
3093
19743
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
3094 if (str == "native")
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
3095 isnative = true;
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
3096 else if (str == "double")
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
3097 isdouble = true;
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
3098 else if (str == "extra")
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
3099 isextra = true;
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
3100 else
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
3101 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
3102
21062
d9c1884d1aaa maint: Eliminate space between variable and decrement '--' operator.
Rik <rik@octave.org>
parents: 21055
diff changeset
3103 nargin--;
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
3104 }
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
3105
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3106 if (nargin < 1 || nargin > 2)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3107 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3108
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3109 int dim = -1;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3110 if (nargin == 2)
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
3111 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3112 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
3113 if (dim < 0)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3114 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
3115 }
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3116
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3117 octave_value retval;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3118 octave_value arg = args(0);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3119
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3120 switch (arg.builtin_type ())
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3121 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3122 case btyp_double:
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
3123 if (arg.issparse ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3124 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3125 if (isextra)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3126 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
3127 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
3128 }
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3129 else if (isextra)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3130 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
3131 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3132 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
3133 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3134
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3135 case btyp_complex:
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
3136 if (arg.issparse ())
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3137 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3138 if (isextra)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3139 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
3140 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
3141 }
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3142 else if (isextra)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3143 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
3144 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3145 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
3146 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3147
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3148 case btyp_float:
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3149 if (isdouble || isextra)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3150 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
3151 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3152 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
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_complex:
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_complex_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_complex_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;
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
3161
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
3162 #define MAKE_INT_BRANCH(X) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
3163 case btyp_ ## X: \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
3164 if (isnative) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
3165 retval = arg.X ## _array_value ().sum (dim); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
3166 else \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
3167 retval = arg.X ## _array_value ().dsum (dim); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
3168 break;
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3169
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3170 MAKE_INT_BRANCH (int8);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3171 MAKE_INT_BRANCH (int16);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3172 MAKE_INT_BRANCH (int32);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3173 MAKE_INT_BRANCH (int64);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3174 MAKE_INT_BRANCH (uint8);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3175 MAKE_INT_BRANCH (uint16);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3176 MAKE_INT_BRANCH (uint32);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3177 MAKE_INT_BRANCH (uint64);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3178
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
3179 #undef MAKE_INT_BRANCH
19597
db92e7e28e1f strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 19596
diff changeset
3180
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
3181 // GAGME: Accursed Matlab compatibility...
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3182 case btyp_char:
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3183 if (isextra)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3184 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
3185 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3186 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
3187 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3188
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3189 case btyp_bool:
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
3190 if (arg.issparse ())
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3191 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3192 if (isnative)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3193 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
3194 else
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3195 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
3196 }
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3197 else if (isnative)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3198 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
3199 else
22773
7f70e420e342 deprecate boolNDArray::sum and boolNDArray::cumsum
John W. Eaton <jwe@octave.org>
parents: 22763
diff changeset
3200 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
3201 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3202
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3203 default:
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21078
diff changeset
3204 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
3205 }
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
3206
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
3207 return retval;
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
3208 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
3209
7112
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
3210 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3211 %!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
3212 %!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
3213 %!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
3214 %!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
3215
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3216 %!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
3217 %!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
3218 %!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
3219 %!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
3220 %! 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
3221
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3222 %!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
3223 %!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
3224 %!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
3225 %!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
3226 %!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
3227 %!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
3228 %!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
3229 %!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
3230 %!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
3231 %!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
3232 %!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
3233 %!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
3234 %!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
3235 %!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
3236 %!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
3237 %!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
3238 %!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
3239 %!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
3240 %!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
3241
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3242 %!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
3243 %!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
3244 %!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
3245 %!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
3246 %!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
3247 %!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
3248 %!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
3249 %!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
3250 %!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
3251 %!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
3252 %!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
3253 %!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
3254 %!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
3255 %!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
3256 %!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
3257 %!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
3258 %!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
3259 %!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
3260 %!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
3261
18726
5baada25d5a2 Rewrite docstring of sum() to match prod().
Rik <rik@octave.org>
parents: 18725
diff changeset
3262 ## Test "native"
5baada25d5a2 Rewrite docstring of sum() to match prod().
Rik <rik@octave.org>
parents: 18725
diff changeset
3263 %!assert (sum ([true,true]), 2)
5baada25d5a2 Rewrite docstring of sum() to match prod().
Rik <rik@octave.org>
parents: 18725
diff changeset
3264 %!assert (sum ([true,true], "native"), true)
5baada25d5a2 Rewrite docstring of sum() to match prod().
Rik <rik@octave.org>
parents: 18725
diff changeset
3265 %!assert (sum (int8 ([127,10,-20])), 117)
5baada25d5a2 Rewrite docstring of sum() to match prod().
Rik <rik@octave.org>
parents: 18725
diff changeset
3266 %!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
3267
15623
d928ad126b66 maint: add a new test for Fsum corresponding to cset e9d842dcfc91
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 15621
diff changeset
3268 ;-)
d928ad126b66 maint: add a new test for Fsum corresponding to cset e9d842dcfc91
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 15621
diff changeset
3269 %!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
3270
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3271 %!error sum ()
18726
5baada25d5a2 Rewrite docstring of sum() to match prod().
Rik <rik@octave.org>
parents: 18725
diff changeset
3272 %!error sum (1,2,3)
5baada25d5a2 Rewrite docstring of sum() to match prod().
Rik <rik@octave.org>
parents: 18725
diff changeset
3273 %!error <unrecognized type argument 'foobar'> sum (1, "foobar")
7112
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
3274 */
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
3275
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1940
diff changeset
3276 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
3277 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
3278 @deftypefn {} {} sumsq (@var{x})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3279 @deftypefnx {} {} sumsq (@var{x}, @var{dim})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3280 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
3281
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3282 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
3283
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3284 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
3285
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3286 @example
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 (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
3288 @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
3289
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3290 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3291 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
3292 @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
3293 @end deftypefn */)
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
3294 {
3723
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
3295 DATA_REDUCTION (sumsq);
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
3296 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
3297
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
3298 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3299 %!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
3300 %!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
3301 %!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
3302
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3303 %!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
3304 %!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
3305 %!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
3306
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3307 %!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
3308 %!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
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, 4]), 1), single ([10, 20]))
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; 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
3312
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3313 %!error sumsq ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3314 */
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
3315
6688
b26a8e0e42cd [project @ 2007-06-04 06:25:21 by jwe]
jwe
parents: 6671
diff changeset
3316 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
3317 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
3318 @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
3319 @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
3320 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
3321 @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
3322 @end deftypefn */)
3209
fbb332b96e4f [project @ 1998-11-03 20:48:54 by jwe]
jwe
parents: 3206
diff changeset
3323 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3324 if (args.length () != 1)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
3325 print_usage ();
3209
fbb332b96e4f [project @ 1998-11-03 20:48:54 by jwe]
jwe
parents: 3206
diff changeset
3326
23579
c20a0fa91c0c maint: Deprecate is_bool_type and replace with islogical.
Rik <rik@octave.org>
parents: 23577
diff changeset
3327 return ovl (args(0).islogical ());
3209
fbb332b96e4f [project @ 1998-11-03 20:48:54 by jwe]
jwe
parents: 3206
diff changeset
3328 }
fbb332b96e4f [project @ 1998-11-03 20:48:54 by jwe]
jwe
parents: 3206
diff changeset
3329
6688
b26a8e0e42cd [project @ 2007-06-04 06:25:21 by jwe]
jwe
parents: 6671
diff changeset
3330 DEFALIAS (isbool, islogical);
3209
fbb332b96e4f [project @ 1998-11-03 20:48:54 by jwe]
jwe
parents: 3206
diff changeset
3331
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
3332 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3333 %!assert (islogical (true), true)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3334 %!assert (islogical (false), true)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3335 %!assert (islogical ([true, false]), true)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3336 %!assert (islogical (1), false)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3337 %!assert (islogical (1i), false)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3338 %!assert (islogical ([1,1]), false)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3339 %!assert (islogical (single (1)), false)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3340 %!assert (islogical (single (1i)), false)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3341 %!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
3342 %!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
3343 %!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
3344 */
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
3345
6223
a6cc01dd09f9 [project @ 2007-01-03 20:59:28 by jwe]
jwe
parents: 6197
diff changeset
3346 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
3347 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
3348 @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
3349 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
3350
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3351 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
3352 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
3353 @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
3354 @end deftypefn */)
6223
a6cc01dd09f9 [project @ 2007-01-03 20:59:28 by jwe]
jwe
parents: 6197
diff changeset
3355 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3356 if (args.length () != 1)
6223
a6cc01dd09f9 [project @ 2007-01-03 20:59:28 by jwe]
jwe
parents: 6197
diff changeset
3357 print_usage ();
a6cc01dd09f9 [project @ 2007-01-03 20:59:28 by jwe]
jwe
parents: 6197
diff changeset
3358
23580
2230f9e10fb3 maint: Deprecate is_integer_type and replace with isinteger.
Rik <rik@octave.org>
parents: 23579
diff changeset
3359 return ovl (args(0).isinteger ());
6223
a6cc01dd09f9 [project @ 2007-01-03 20:59:28 by jwe]
jwe
parents: 6197
diff changeset
3360 }
a6cc01dd09f9 [project @ 2007-01-03 20:59:28 by jwe]
jwe
parents: 6197
diff changeset
3361
22749
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3362 /*
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3363 %!assert (isinteger (int8 (16)))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3364 %!assert (isinteger (int16 (16)))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3365 %!assert (isinteger (int32 (16)))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3366 %!assert (isinteger (int64 (16)))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3367
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3368 %!assert (isinteger (uint8 (16)))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3369 %!assert (isinteger (uint16 (16)))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3370 %!assert (isinteger (uint32 (16)))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3371 %!assert (isinteger (uint64 (16)))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3372
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3373 %!assert (isinteger (intmax ("int8")))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3374 %!assert (isinteger (intmax ("int16")))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3375 %!assert (isinteger (intmax ("int32")))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3376 %!assert (isinteger (intmax ("int64")))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3377
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3378 %!assert (isinteger (intmax ("uint8")))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3379 %!assert (isinteger (intmax ("uint16")))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3380 %!assert (isinteger (intmax ("uint32")))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3381 %!assert (isinteger (intmax ("uint64")))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3382
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3383 %!assert (isinteger (intmin ("int8")))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3384 %!assert (isinteger (intmin ("int16")))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3385 %!assert (isinteger (intmin ("int32")))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3386 %!assert (isinteger (intmin ("int64")))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3387
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3388 %!assert (isinteger (intmin ("uint8")))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3389 %!assert (isinteger (intmin ("uint16")))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3390 %!assert (isinteger (intmin ("uint32")))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3391 %!assert (isinteger (intmin ("uint64")))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3392
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3393 %!assert (isinteger (uint8 ([1:10])))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3394 %!assert (isinteger (uint8 ([1:10; 1:10])))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3395
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3396 %!assert (! isinteger (16))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3397 %!assert (! isinteger ("parrot"))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3398 %!assert (! isinteger ([1, 2, 3]))
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 %!error isinteger ()
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3401 %!error isinteger ("multiple", "parameters")
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
4028
ef75c970c8f5 [project @ 2002-08-09 07:19:02 by jwe]
jwe
parents: 4025
diff changeset
3404 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
3405 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
3406 @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
3407 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
3408 @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
3409 @end deftypefn */)
3186
edaa9a2d3d9c [project @ 1998-10-02 19:12:19 by jwe]
jwe
parents: 3174
diff changeset
3410 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3411 if (args.length () != 1)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
3412 print_usage ();
3186
edaa9a2d3d9c [project @ 1998-10-02 19:12:19 by jwe]
jwe
parents: 3174
diff changeset
3413
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
3414 return ovl (args(0).iscomplex ());
3186
edaa9a2d3d9c [project @ 1998-10-02 19:12:19 by jwe]
jwe
parents: 3174
diff changeset
3415 }
edaa9a2d3d9c [project @ 1998-10-02 19:12:19 by jwe]
jwe
parents: 3174
diff changeset
3416
26198
d57d30caffd6 Add BISTS tests for iscomplex().
Rik <rik@octave.org>
parents: 26164
diff changeset
3417 /*
d57d30caffd6 Add BISTS tests for iscomplex().
Rik <rik@octave.org>
parents: 26164
diff changeset
3418 %!assert (iscomplex (4), false)
d57d30caffd6 Add BISTS tests for iscomplex().
Rik <rik@octave.org>
parents: 26164
diff changeset
3419 %!assert (iscomplex (i), true)
d57d30caffd6 Add BISTS tests for iscomplex().
Rik <rik@octave.org>
parents: 26164
diff changeset
3420 %!assert (iscomplex (4+3i), true)
d57d30caffd6 Add BISTS tests for iscomplex().
Rik <rik@octave.org>
parents: 26164
diff changeset
3421 %!assert (iscomplex ([1, 2, 3]), false)
d57d30caffd6 Add BISTS tests for iscomplex().
Rik <rik@octave.org>
parents: 26164
diff changeset
3422 %!assert (iscomplex ([1, 2i, 3]), true)
d57d30caffd6 Add BISTS tests for iscomplex().
Rik <rik@octave.org>
parents: 26164
diff changeset
3423
d57d30caffd6 Add BISTS tests for iscomplex().
Rik <rik@octave.org>
parents: 26164
diff changeset
3424 %!assert (iscomplex (0j), false)
d57d30caffd6 Add BISTS tests for iscomplex().
Rik <rik@octave.org>
parents: 26164
diff changeset
3425 %!assert (iscomplex (complex (0,0)), true)
d57d30caffd6 Add BISTS tests for iscomplex().
Rik <rik@octave.org>
parents: 26164
diff changeset
3426 %!assert (iscomplex ("4"), false)
d57d30caffd6 Add BISTS tests for iscomplex().
Rik <rik@octave.org>
parents: 26164
diff changeset
3427 %!assert (iscomplex ({i}), false)
d57d30caffd6 Add BISTS tests for iscomplex().
Rik <rik@octave.org>
parents: 26164
diff changeset
3428
d57d30caffd6 Add BISTS tests for iscomplex().
Rik <rik@octave.org>
parents: 26164
diff changeset
3429 ## Test input validation
d57d30caffd6 Add BISTS tests for iscomplex().
Rik <rik@octave.org>
parents: 26164
diff changeset
3430 %!error iscomplex ()
d57d30caffd6 Add BISTS tests for iscomplex().
Rik <rik@octave.org>
parents: 26164
diff changeset
3431 %!error iscomplex (1, 2)
d57d30caffd6 Add BISTS tests for iscomplex().
Rik <rik@octave.org>
parents: 26164
diff changeset
3432 */
d57d30caffd6 Add BISTS tests for iscomplex().
Rik <rik@octave.org>
parents: 26164
diff changeset
3433
7576
7ebdc99a0bab new isfloat function
John W. Eaton <jwe@octave.org>
parents: 7515
diff changeset
3434 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
3435 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
3436 @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
3437 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
3438
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3439 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
3440 @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
3441 @end deftypefn */)
7576
7ebdc99a0bab new isfloat function
John W. Eaton <jwe@octave.org>
parents: 7515
diff changeset
3442 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3443 if (args.length () != 1)
7576
7ebdc99a0bab new isfloat function
John W. Eaton <jwe@octave.org>
parents: 7515
diff changeset
3444 print_usage ();
7ebdc99a0bab new isfloat function
John W. Eaton <jwe@octave.org>
parents: 7515
diff changeset
3445
23585
570170b6eb09 maint: Deprecate is_float_type and replace with isfloat.
Rik <rik@octave.org>
parents: 23584
diff changeset
3446 return ovl (args(0).isfloat ());
7576
7ebdc99a0bab new isfloat function
John W. Eaton <jwe@octave.org>
parents: 7515
diff changeset
3447 }
7ebdc99a0bab new isfloat function
John W. Eaton <jwe@octave.org>
parents: 7515
diff changeset
3448
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
3449 // FIXME: perhaps this should be implemented with an
5476
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3450 // octave_value member function?
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3451
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3452 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
3453 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
3454 @deftypefn {} {} complex (@var{x})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3455 @deftypefnx {} {} complex (@var{re}, @var{im})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3456 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
3457
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3458 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
3459 @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
3460
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3461 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
3462 @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
3463 @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
3464 @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
3465 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
3466
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3467 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3468 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3469 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
3470 @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
3471 @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
3472 @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
3473 @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
3474 @end deftypefn */)
5476
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3475 {
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3476 int nargin = args.length ();
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3477
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3478 if (nargin < 1 || nargin > 2)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3479 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3480
5476
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3481 octave_value retval;
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3482
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3483 if (nargin == 1)
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3484 {
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3485 octave_value arg = args(0);
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3486
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
3487 if (arg.iscomplex ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3488 retval = arg;
5476
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3489 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3490 {
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
3491 if (arg.issparse ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3492 {
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20700
diff changeset
3493 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
3494
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3495 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
3496 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3497 else if (arg.is_single_type ())
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3498 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3499 if (arg.numel () == 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3500 {
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20700
diff changeset
3501 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
3502
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3503 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
3504 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3505 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3506 {
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20700
diff changeset
3507 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
3508
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3509 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
3510 }
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 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3513 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3514 if (arg.numel () == 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3515 {
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20700
diff changeset
3516 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
3517
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3518 retval = octave_value (new octave_complex (val));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3519 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3520 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3521 {
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20700
diff changeset
3522 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
3523
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3524 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
3525 }
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 }
5476
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3528 }
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3529 else
5476
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3530 {
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3531 octave_value re = args(0);
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3532 octave_value im = args(1);
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3533
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
3534 if (re.issparse () && im.issparse ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3535 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3536 const SparseMatrix re_val = re.sparse_matrix_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3537 const SparseMatrix im_val = im.sparse_matrix_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3538
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3539 if (re.numel () == 1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3540 {
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3541 SparseComplexMatrix result;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3542 if (re_val.nnz () == 0)
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3543 result = Complex (0, 1) * SparseComplexMatrix (im_val);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3544 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3545 {
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3546 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
3547 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
3548 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
3549
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3550 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
3551 {
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3552 octave_idx_type off = j * nr;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3553 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
3554 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
3555 result.data (im_val.ridx (i) + off)
db687716fed6 style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents: 27081
diff changeset
3556 += Complex (0, im_val.data (i));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3557 }
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 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
3560 }
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3561 else if (im.numel () == 1)
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 SparseComplexMatrix result;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3564 if (im_val.nnz () == 0)
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3565 result = SparseComplexMatrix (re_val);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3566 else
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3567 {
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3568 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
3569 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
3570 result = SparseComplexMatrix (nr, nc,
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3571 Complex (0, im_val(0)));
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3572
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3573 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
3574 {
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3575 octave_idx_type off = j * nr;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3576 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
3577 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
3578 result.data (re_val.ridx (i) + off)
db687716fed6 style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents: 27081
diff changeset
3579 += re_val.data (i);
20562
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 }
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3582 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
3583 }
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3584 else
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3585 {
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3586 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
3587 error ("complex: dimension mismatch");
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3588
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3589 SparseComplexMatrix result;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3590 result = SparseComplexMatrix (re_val)
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
3591 + Complex (0, 1) * SparseComplexMatrix (im_val);
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3592 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
3593 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3594 }
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7743
diff changeset
3595 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
3596 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3597 if (re.numel () == 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3598 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3599 float re_val = re.float_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3600
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3601 if (im.numel () == 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3602 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3603 float im_val = im.double_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3604
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3605 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
3606 (FloatComplex (re_val, im_val)));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3607 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3608 else
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 const FloatNDArray im_val = im.float_array_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3611
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3612 FloatComplexNDArray result (im_val.dims (),
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3613 FloatComplex ());
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3614
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3615 for (octave_idx_type i = 0; i < im_val.numel (); i++)
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3616 result.xelem (i) = FloatComplex (re_val, im_val(i));
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3617
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_matrix
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3619 (result));
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 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3622 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3623 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3624 const FloatNDArray re_val = re.float_array_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3625
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3626 if (im.numel () == 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3627 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3628 float im_val = im.float_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3629
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3630 FloatComplexNDArray result (re_val.dims (),
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3631 FloatComplex ());
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3632
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3633 for (octave_idx_type i = 0; i < re_val.numel (); i++)
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3634 result.xelem (i) = FloatComplex (re_val(i), im_val);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3635
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3636 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
3637 (result));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3638 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3639 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3640 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3641 const FloatNDArray im_val = im.float_array_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3642
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3643 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
3644 error ("complex: dimension mismatch");
20921
4d3daf7e43f3 eliminate trailing whitespace in source files
John W. Eaton <jwe@octave.org>
parents: 20918
diff changeset
3645
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3646 FloatComplexNDArray result (re_val.dims (),
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3647 FloatComplex ());
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3648
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3649 for (octave_idx_type i = 0; i < re_val.numel (); i++)
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3650 result.xelem (i) = FloatComplex (re_val(i),
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3651 im_val(i));
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3652
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3653 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
3654 (result));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3655 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3656 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3657 }
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7743
diff changeset
3658 else if (re.numel () == 1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3659 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3660 double re_val = re.double_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3661
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3662 if (im.numel () == 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3663 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3664 double im_val = im.double_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3665
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3666 retval = octave_value (new octave_complex
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3667 (Complex (re_val, im_val)));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3668 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3669 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3670 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3671 const NDArray im_val = im.array_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3672
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3673 ComplexNDArray result (im_val.dims (), Complex ());
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3674
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3675 for (octave_idx_type i = 0; i < im_val.numel (); i++)
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3676 result.xelem (i) = Complex (re_val, im_val(i));
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3677
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3678 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
3679 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3680 }
5476
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3681 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3682 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3683 const NDArray re_val = re.array_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3684
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3685 if (im.numel () == 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3686 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3687 double im_val = im.double_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3688
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3689 ComplexNDArray result (re_val.dims (), Complex ());
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3690
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3691 for (octave_idx_type i = 0; i < re_val.numel (); i++)
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3692 result.xelem (i) = Complex (re_val(i), im_val);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3693
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3694 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
3695 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3696 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3697 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3698 const NDArray im_val = im.array_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3699
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3700 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
3701 error ("complex: dimension mismatch");
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3702
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3703 ComplexNDArray result (re_val.dims (), Complex ());
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3704
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3705 for (octave_idx_type i = 0; i < re_val.numel (); i++)
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3706 result.xelem (i) = Complex (re_val(i), im_val(i));
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3707
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3708 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
3709 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3710 }
5476
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3711 }
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3712
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3713 return retval;
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3714 }
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3715
22590
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3716 /*
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3717 %!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
3718 %!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
3719
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3720 %!test <31974>
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3721 %! 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
3722 %!
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3723 %! 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
3724 %! 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
3725 %!
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3726 %! ## 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
3727 %! 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
3728 %! 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
3729 %!
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3730 %! 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
3731 %!
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 * 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
3733
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3734 %!test <31974>
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3735 %! x = Inf;
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3736 %! 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
3737 %! 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
3738 %! 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
3739
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3740 %!test <31974>
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3741 %! 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
3742 %! 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
3743 %! 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
3744 %! 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
3745 %! 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
3746
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3747 %!test <31974>
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3748 %! 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
3749 %! 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
3750 %! 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
3751
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3752 %!test <31974>
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3753 %! 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
3754 %! 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
3755 %! 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
3756 %! 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
3757 */
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3758
3258
4964d5391acc [project @ 1999-07-21 21:51:33 by jwe]
jwe
parents: 3238
diff changeset
3759 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
3760 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
3761 @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
3762 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
3763
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3764 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
3765 matrices.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3766 @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
3767 @end deftypefn */)
3258
4964d5391acc [project @ 1999-07-21 21:51:33 by jwe]
jwe
parents: 3238
diff changeset
3768 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3769 if (args.length () != 1)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
3770 print_usage ();
3258
4964d5391acc [project @ 1999-07-21 21:51:33 by jwe]
jwe
parents: 3238
diff changeset
3771
23582
0cc2011d800e maint: Deprecate is_real_type and replace with isreal.
Rik <rik@octave.org>
parents: 23581
diff changeset
3772 return ovl (args(0).isreal ());
3258
4964d5391acc [project @ 1999-07-21 21:51:33 by jwe]
jwe
parents: 3238
diff changeset
3773 }
4964d5391acc [project @ 1999-07-21 21:51:33 by jwe]
jwe
parents: 3238
diff changeset
3774
3202
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3195
diff changeset
3775 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
3776 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
3777 @deftypefn {} {@var{tf} =} isempty (@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
3778 Return true if @var{a} is an empty matrix (any one of its dimensions is
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3779 zero).
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3780 @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
3781 @end deftypefn */)
3202
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3195
diff changeset
3782 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3783 if (args.length () != 1)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
3784 print_usage ();
3202
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3195
diff changeset
3785
23577
80c42f4cca13 maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents: 23576
diff changeset
3786 return ovl (args(0).isempty ());
3202
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3195
diff changeset
3787 }
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3195
diff changeset
3788
16779
8fce0ed4894a Specialize is_empty and numel methods for sparse matrices (debian bug #706376)
David Bateman <dbateman@free.fr>
parents: 16077
diff changeset
3789 /*
22737
7abc25e6206a maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22708
diff changeset
3790 ## Debian bug #706376
28915
c40a367a84c0 maint: Use Octave convention of space after function name in libinterp/.
Rik <rik@octave.org>
parents: 28888
diff changeset
3791 %!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
3792 */
8fce0ed4894a Specialize is_empty and numel methods for sparse matrices (debian bug #706376)
David Bateman <dbateman@free.fr>
parents: 16077
diff changeset
3793
3206
d0d2b69dc6c2 [project @ 1998-11-03 02:43:31 by jwe]
jwe
parents: 3204
diff changeset
3794 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
3795 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
3796 @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
3797 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
3798 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
3799
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3800 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
3801 @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
3802 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
3803 @end deftypefn */)
3206
d0d2b69dc6c2 [project @ 1998-11-03 02:43:31 by jwe]
jwe
parents: 3204
diff changeset
3804 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3805 if (args.length () != 1)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
3806 print_usage ();
3206
d0d2b69dc6c2 [project @ 1998-11-03 02:43:31 by jwe]
jwe
parents: 3204
diff changeset
3807
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23585
diff changeset
3808 return ovl (args(0).isnumeric ());
3206
d0d2b69dc6c2 [project @ 1998-11-03 02:43:31 by jwe]
jwe
parents: 3204
diff changeset
3809 }
d0d2b69dc6c2 [project @ 1998-11-03 02:43:31 by jwe]
jwe
parents: 3204
diff changeset
3810
11435
20f53b3a558f Add tests for sparse forms of logical matrices to islogical, isnumeric.
Rik <octave@nomad.inbox5.com>
parents: 11431
diff changeset
3811 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3812 %!assert (isnumeric (1), true)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3813 %!assert (isnumeric (1i), true)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3814 %!assert (isnumeric ([1,1]), true)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3815 %!assert (isnumeric (single (1)), true)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3816 %!assert (isnumeric (single (1i)), true)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3817 %!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
3818 %!assert (isnumeric (int8 (1)), true)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3819 %!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
3820 %!assert (isnumeric ("Hello World"), false)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3821 %!assert (isnumeric (true), false)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3822 %!assert (isnumeric (false), false)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3823 %!assert (isnumeric ([true, false]), false)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3824 %!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
3825 */
20f53b3a558f Add tests for sparse forms of logical matrices to islogical, isnumeric.
Rik <octave@nomad.inbox5.com>
parents: 11431
diff changeset
3826
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
3827 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
3828 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
3829 @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
3830 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
3831
711cf9b1be49 doc: Reword isscalar, isvector, isrow, iscolumn, ismatrix, issquare docstrings.
Rik <rik@octave.org>
parents: 28012
diff changeset
3832 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
3833 returns @w{@code{[1, 1]}}.
711cf9b1be49 doc: Reword isscalar, isvector, isrow, iscolumn, ismatrix, issquare docstrings.
Rik <rik@octave.org>
parents: 28012
diff changeset
3834 @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
3835 @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
3836 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3837 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
3838 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
3839
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
3840 // 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
3841 // 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
3842 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
3843
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
3844 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
3845 }
bc52657a7d29 Convert isscalar from an m-file to a built-in function (bug #42422).
Jason Alan Palmer <jalanpalmer@gmail.com>
parents: 18812
diff changeset
3846
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 /*
bc52657a7d29 Convert isscalar from an m-file to a built-in function (bug #42422).
Jason Alan Palmer <jalanpalmer@gmail.com>
parents: 18812
diff changeset
3848 %!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
3849 %!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
3850 %!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
3851 %!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
3852
bc52657a7d29 Convert isscalar from an m-file to a built-in function (bug #42422).
Jason Alan Palmer <jalanpalmer@gmail.com>
parents: 18812
diff changeset
3853 %!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
3854 %!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
3855 %!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
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 %!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
3858 %! 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
3859 %! 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
3860
22737
7abc25e6206a maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22708
diff changeset
3861 ## 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
3862 %!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
3863 %!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
3864 */
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
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3866 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
3867 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
3868 @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
3869 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
3870
28714
d8dcb36bb904 maint: spellcheck documentation ahead of 6.1 release.
Rik <rik@octave.org>
parents: 28043
diff changeset
3871 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
3872 @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
3873 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
3874 @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
3875 @end deftypefn */)
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3876 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3877 if (args.length () != 1)
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3878 print_usage ();
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3879
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
3880 // 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
3881 // 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
3882 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
3883
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
3884 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
3885 }
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3886
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3887 /*
19700
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3888 %!assert (isvector (1), true)
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3889 %!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
3890 %!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
3891 %!assert (isvector ([]), false)
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3892 %!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
3893
19700
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3894 %!assert (isvector ("t"), true)
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3895 %!assert (isvector ("test"), true)
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3896 %!assert (isvector (["test"; "ing"]), false)
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 %!test
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3899 %! s.a = 1;
19700
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3900 %! assert (isvector (s), true);
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3901
22737
7abc25e6206a maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22708
diff changeset
3902 ## Test input validation
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3903 %!error isvector ()
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3904 %!error isvector ([1, 2], 2)
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3905 */
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3906
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3907 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
3908 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
3909 @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
3910 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
3911
711cf9b1be49 doc: Reword isscalar, isvector, isrow, iscolumn, ismatrix, issquare docstrings.
Rik <rik@octave.org>
parents: 28012
diff changeset
3912 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
3913 @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
3914 @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
3915 @end deftypefn */)
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3916 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3917 if (args.length () != 1)
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3918 print_usage ();
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3919
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
3920 // 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
3921 // 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
3922 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
3923
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
3924 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
3925 }
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3926
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3927 /*
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3928 %!assert (isrow ([1, 2, 3]))
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3929 %!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
3930 %!assert (isrow (1))
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3931 %!assert (isrow ([]), false)
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3932 %!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
3933
19700
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3934 %!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
3935 %!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
3936 %!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
3937 %!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
3938 %!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
3939
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3940 %!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
3941 %!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
3942
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3943 %!assert (isrow ("t"), true)
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3944 %!assert (isrow ("test"), true)
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3945 %!assert (isrow (["test"; "ing"]), false)
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3946
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3947 %!test
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3948 %! s.a = 1;
19700
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3949 %! assert (isrow (s), true);
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3950
22737
7abc25e6206a maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22708
diff changeset
3951 ## Test input validation
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3952 %!error isrow ()
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3953 %!error isrow ([1, 2], 2)
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3954 */
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3955
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3956 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
3957 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
3958 @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
3959 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
3960
711cf9b1be49 doc: Reword isscalar, isvector, isrow, iscolumn, ismatrix, issquare docstrings.
Rik <rik@octave.org>
parents: 28012
diff changeset
3961 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
3962 @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
3963 @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
3964 @end deftypefn */)
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3965 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3966 if (args.length () != 1)
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3967 print_usage ();
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3968
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
3969 // 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
3970 // 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
3971 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
3972
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
3973 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
3974 }
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3975
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3976 /*
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3977 %!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
3978 %!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
3979 %!assert (iscolumn (1), true)
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3980 %!assert (iscolumn ([]), false)
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3981 %!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
3982
19700
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3983 %!assert (iscolumn ("t"), true)
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3984 %!assert (iscolumn ("test"), false)
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3985 %!assert (iscolumn (["test"; "ing"]), false)
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3986
19700
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3987 %!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
3988 %!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
3989 %!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
3990 %!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
3991 %!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
3992
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3993 %!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
3994 %!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
3995
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3996 %!test
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3997 %! s.a = 1;
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3998 %! assert (iscolumn (s));
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3999
22737
7abc25e6206a maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22708
diff changeset
4000 ## Test input validation
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
4001 %!error iscolumn ()
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
4002 %!error iscolumn ([1, 2], 2)
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
4003 */
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
4004
4028
ef75c970c8f5 [project @ 2002-08-09 07:19:02 by jwe]
jwe
parents: 4025
diff changeset
4005 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
4006 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
4007 @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
4008 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
4009
711cf9b1be49 doc: Reword isscalar, isvector, isrow, iscolumn, ismatrix, issquare docstrings.
Rik <rik@octave.org>
parents: 28012
diff changeset
4010 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
4011 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
4012 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
4013 @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
4014 @end deftypefn */)
3202
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3195
diff changeset
4015 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
4016 if (args.length () != 1)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
4017 print_usage ();
3202
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3195
diff changeset
4018
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
4019 // 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
4020 // 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
4021 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
4022
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
4023 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
4024 }
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3195
diff changeset
4025
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
4026 /*
19700
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
4027 %!assert (ismatrix ([]), true)
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
4028 %!assert (ismatrix (1), true)
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
4029 %!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
4030 %!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
4031
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
4032 %!assert (ismatrix (zeros (0)), true)
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
4033 %!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
4034 %!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
4035 %!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
4036
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
4037 %!assert (ismatrix (single ([])), true)
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
4038 %!assert (ismatrix (single (1)), true)
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
4039 %!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
4040 %!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
4041
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
4042 %!assert (ismatrix ("t"), true)
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
4043 %!assert (ismatrix ("test"), true)
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
4044 %!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
4045
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
4046 %!test
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
4047 %! s.a = 1;
19700
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
4048 %! assert (ismatrix (s), true);
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4049
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4050 %!error ismatrix ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4051 %!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
4052 */
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
4053
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
4054 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
4055 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
4056 @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
4057 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
4058
711cf9b1be49 doc: Reword isscalar, isvector, isrow, iscolumn, ismatrix, issquare docstrings.
Rik <rik@octave.org>
parents: 28012
diff changeset
4059 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
4060 @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
4061 @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
4062 @end deftypefn */)
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
4063 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
4064 if (args.length () != 1)
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
4065 print_usage ();
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
4066
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
4067 // 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
4068 // 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
4069 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
4070
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
4071 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
4072 }
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
4073
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
4074 /*
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
4075 %!assert (issquare ([]))
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
4076 %!assert (issquare (1))
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
4077 %!assert (! issquare ([1, 2]))
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
4078 %!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
4079 %!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
4080 %!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
4081 %!assert (issquare ("t"))
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
4082 %!assert (! issquare ("test"))
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
4083 %!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
4084 %!test
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
4085 %! s.a = 1;
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
4086 %! assert (issquare (s));
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
4087 %!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
4088 %!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
4089
22737
7abc25e6206a maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22708
diff changeset
4090 ## Test input validation
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
4091 %!error issquare ()
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
4092 %!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
4093 */
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
4094
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3333
diff changeset
4095 static octave_value
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4096 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
4097 {
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3333
diff changeset
4098 octave_value retval;
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
4099
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
4100 int nargin = args.length ();
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
4101
4946
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
4102 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
4103
4946
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
4104 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
4105 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
4106 bool iscomplex = false;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
4107
4481
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4479
diff changeset
4108 if (nargin > 0 && args(nargin-1).is_string ())
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4479
diff changeset
4109 {
4946
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
4110 std::string nm = args(nargin-1).string_value ();
4481
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4479
diff changeset
4111 nargin--;
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4479
diff changeset
4112
4946
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
4113 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
4114 }
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4479
diff changeset
4115
29086
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4116 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
4117 && 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
4118 {
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4119 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
4120 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
4121 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
4122 nargin -= 2;
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4123 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
4124 }
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4125
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
4126 switch (nargin)
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
4127 {
712
36ba0576bd1b [project @ 1994-09-19 14:18:15 by jwe]
jwe
parents: 649
diff changeset
4128 case 0:
36ba0576bd1b [project @ 1994-09-19 14:18:15 by jwe]
jwe
parents: 649
diff changeset
4129 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 767
diff changeset
4130
610
14b2a186a5c0 [project @ 1994-08-14 00:55:49 by jwe]
jwe
parents: 597
diff changeset
4131 case 1:
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
4132 get_dimensions (args(0), fcn, dims);
610
14b2a186a5c0 [project @ 1994-08-14 00:55:49 by jwe]
jwe
parents: 597
diff changeset
4133 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 767
diff changeset
4134
4563
742993a501b9 [project @ 2003-10-29 06:25:12 by jwe]
jwe
parents: 4559
diff changeset
4135 default:
742993a501b9 [project @ 2003-10-29 06:25:12 by jwe]
jwe
parents: 4559
diff changeset
4136 {
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4137 dims.resize (nargin);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4138
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4139 for (int i = 0; i < nargin; i++)
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
4140 dims(i) = (args(i).isempty () ? 0 : args(i).idx_type_value (true));
4563
742993a501b9 [project @ 2003-10-29 06:25:12 by jwe]
jwe
parents: 4559
diff changeset
4141 }
742993a501b9 [project @ 2003-10-29 06:25:12 by jwe]
jwe
parents: 4559
diff changeset
4142 break;
4481
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4479
diff changeset
4143 }
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4479
diff changeset
4144
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4145 dims.chop_trailing_singletons ();
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4146
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
4147 check_dimensions (dims, fcn);
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4148
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
4149 // 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
4150 // 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
4151
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4152 // 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
4153 // NDArray to scalar.
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4154
29086
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4155 if (issparse)
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4156 {
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4157 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
4158 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
4159
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4160 switch (dt)
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4161 {
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4162 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
4163 if (iscomplex)
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4164 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
4165 else
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4166 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
4167 break;
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4168
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4169 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
4170 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
4171 break;
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 default:
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4174 // 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
4175 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
4176 break;
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
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4179 return retval;
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4180 }
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4181
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4182 switch (dt)
4481
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4479
diff changeset
4183 {
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4184 case oct_data_conv::dt_int8:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4185 retval = int8NDArray (dims, val);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4186 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4187
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4188 case oct_data_conv::dt_uint8:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4189 retval = uint8NDArray (dims, val);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4190 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4191
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4192 case oct_data_conv::dt_int16:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4193 retval = int16NDArray (dims, val);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4194 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4195
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4196 case oct_data_conv::dt_uint16:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4197 retval = uint16NDArray (dims, val);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4198 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4199
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4200 case oct_data_conv::dt_int32:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4201 retval = int32NDArray (dims, val);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4202 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4203
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4204 case oct_data_conv::dt_uint32:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4205 retval = uint32NDArray (dims, val);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4206 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4207
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4208 case oct_data_conv::dt_int64:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4209 retval = int64NDArray (dims, val);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4210 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4211
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4212 case oct_data_conv::dt_uint64:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4213 retval = uint64NDArray (dims, val);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4214 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4215
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4216 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
4217 if (iscomplex)
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4218 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
4219 else
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4220 retval = FloatNDArray (dims, val);
20562
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_double:
29086
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4224 if (iscomplex)
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4225 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
4226 else if (dims.ndims () == 2 && dims(0) == 1)
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4227 {
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4228 // FIXME: If this optimization provides a significant
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4229 // benefit, then maybe there should be a special storage
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4230 // type for constant value arrays.
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4231 double dval = static_cast<double> (val);
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
4232 retval = range<double>::make_constant (dval, dims(1));
29086
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4233 }
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 = NDArray (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_logical:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4239 retval = boolNDArray (dims, val);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4240 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4241
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4242 default:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4243 error ("%s: invalid class name", fcn);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4244 break;
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
4245 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
4246
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
4247 return retval;
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
4248 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
4249
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4250 static octave_value
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
4251 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
4252 const char *fcn)
7795
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4253 {
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4254 octave_value retval;
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4255
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4256 int nargin = args.length ();
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4257
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4258 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
4259
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4260 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
4261 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
4262 bool iscomplex = false;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
4263
7795
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4264 if (nargin > 0 && args(nargin-1).is_string ())
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4265 {
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4266 std::string nm = args(nargin-1).string_value ();
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4267 nargin--;
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4268
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4269 dt = oct_data_conv::string_to_data_type (nm);
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4270 }
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4271
29086
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4272 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
4273 && 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
4274 && (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
4275 || 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
4276 {
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4277 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
4278 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
4279 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
4280 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
4281 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
4282 nargin -= 2;
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4283 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
4284 }
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4285
7795
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4286 switch (nargin)
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4287 {
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4288 case 0:
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4289 break;
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4290
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4291 case 1:
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
4292 get_dimensions (args(0), fcn, dims);
7795
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4293 break;
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 default:
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4296 {
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4297 dims.resize (nargin);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4298
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4299 for (int i = 0; i < nargin; i++)
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
4300 dims(i) = (args(i).isempty () ? 0 : args(i).idx_type_value (true));
7795
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 break;
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4303 }
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4304
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4305 dims.chop_trailing_singletons ();
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4306
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
4307 check_dimensions (dims, fcn);
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4308
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4309 // 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
4310 // NDArray to scalar.
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4311
29086
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4312 if (issparse)
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4313 {
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4314 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
4315 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
4316
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4317 if (iscomplex)
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4318 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
4319 else
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4320 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
4321
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4322 return retval;
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4323 }
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4324
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4325 switch (dt)
7795
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4326 {
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4327 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
4328 if (iscomplex)
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4329 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
4330 else
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4331 retval = FloatNDArray (dims, fval);
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4332 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4333
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4334 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
4335 if (iscomplex)
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4336 retval = ComplexNDArray (dims, Complex (val, 0));
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
4337 else if (dims.ndims () == 2 && dims(0) == 1 && math::isfinite (val))
28638
98192ec1621f replace Range with range<double>
John W. Eaton <jwe@octave.org>
parents: 28636
diff changeset
4338 // FIXME: If this optimization provides a significant benefit,
98192ec1621f replace Range with range<double>
John W. Eaton <jwe@octave.org>
parents: 28636
diff changeset
4339 // then maybe there should be a special storage type for
98192ec1621f replace Range with range<double>
John W. Eaton <jwe@octave.org>
parents: 28636
diff changeset
4340 // constant value arrays.
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
4341 retval = range<double>::make_constant (val, dims(1));
27568
e78b6e7f743c Store constant row vectors for ones(), zeros(), pi(), e() as Ranges for compactness.
Rik <rik@octave.org>
parents: 27435
diff changeset
4342 else
e78b6e7f743c Store constant row vectors for ones(), zeros(), pi(), e() as Ranges for compactness.
Rik <rik@octave.org>
parents: 27435
diff changeset
4343 retval = NDArray (dims, val);
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 default:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4347 error ("%s: invalid class name", fcn);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4348 break;
7795
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4349 }
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4350
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4351 return retval;
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4352 }
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4353
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4354 static octave_value
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4355 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
4356 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4357 octave_value retval;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4358
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4359 int nargin = args.length ();
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4360
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4361 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
4362
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4363 dim_vector dims (1, 1);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
4364
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4365 if (nargin > 0 && args(nargin-1).is_string ())
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4366 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4367 std::string nm = args(nargin-1).string_value ();
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4368 nargin--;
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 dt = oct_data_conv::string_to_data_type (nm);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4371 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4372
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4373 switch (nargin)
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4374 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4375 case 0:
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4376 break;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4377
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4378 case 1:
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
4379 get_dimensions (args(0), fcn, dims);
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4380 break;
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 default:
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4383 {
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4384 dims.resize (nargin);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4385
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4386 for (int i = 0; i < nargin; i++)
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
4387 dims(i) = (args(i).isempty () ? 0 : args(i).idx_type_value (true));
5747
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 break;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4390 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4391
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4392 dims.chop_trailing_singletons ();
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4393
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
4394 check_dimensions (dims, fcn);
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4395
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4396 // 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
4397 // NDArray to scalar.
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4398
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4399 switch (dt)
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4400 {
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4401 case oct_data_conv::dt_single:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4402 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
4403 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4404
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4405 case oct_data_conv::dt_double:
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
4406 if (dims.ndims () == 2 && dims(0) == 1 && math::isfinite (val))
28638
98192ec1621f replace Range with range<double>
John W. Eaton <jwe@octave.org>
parents: 28636
diff changeset
4407 // FIXME: If this optimization provides a significant benefit,
98192ec1621f replace Range with range<double>
John W. Eaton <jwe@octave.org>
parents: 28636
diff changeset
4408 // then maybe there should be a special storage type for
98192ec1621f replace Range with range<double>
John W. Eaton <jwe@octave.org>
parents: 28636
diff changeset
4409 // constant value arrays.
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
4410 retval = range<double>::make_constant (val, dims(1));
27568
e78b6e7f743c Store constant row vectors for ones(), zeros(), pi(), e() as Ranges for compactness.
Rik <rik@octave.org>
parents: 27435
diff changeset
4411 else
e78b6e7f743c Store constant row vectors for ones(), zeros(), pi(), e() as Ranges for compactness.
Rik <rik@octave.org>
parents: 27435
diff changeset
4412 retval = NDArray (dims, val);
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4413 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4414
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4415 default:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4416 error ("%s: invalid class name", fcn);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4417 break;
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4418 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4419
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4420 return retval;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4421 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4422
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4423 static octave_value
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4424 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
4425 const char *fcn)
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4426 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4427 octave_value retval;
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 int nargin = args.length ();
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4430
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4431 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
4432
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4433 dim_vector dims (1, 1);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
4434
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4435 if (nargin > 0 && args(nargin-1).is_string ())
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 std::string nm = args(nargin-1).string_value ();
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4438 nargin--;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4439
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4440 dt = oct_data_conv::string_to_data_type (nm);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4441 }
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 switch (nargin)
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4444 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4445 case 0:
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4446 break;
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 case 1:
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
4449 get_dimensions (args(0), fcn, dims);
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4450 break;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4451
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4452 default:
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4453 {
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4454 dims.resize (nargin);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4455
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4456 for (int i = 0; i < nargin; i++)
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
4457 dims(i) = (args(i).isempty () ? 0 : args(i).idx_type_value (true));
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4458 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4459 break;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4460 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4461
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4462 dims.chop_trailing_singletons ();
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4463
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
4464 check_dimensions (dims, fcn);
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4465
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4466 // 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
4467 // NDArray to scalar.
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4468
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4469 switch (dt)
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4470 {
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4471 case oct_data_conv::dt_single:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4472 retval = FloatComplexNDArray (dims,
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4473 static_cast<FloatComplex> (val));
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4474 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4475
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4476 case oct_data_conv::dt_double:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4477 retval = ComplexNDArray (dims, val);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4478 break;
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 default:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4481 error ("%s: invalid class name", fcn);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4482 break;
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4483 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4484
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4485 return retval;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4486 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4487
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4488 static octave_value
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4489 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
4490 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4491 octave_value retval;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4492
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4493 int nargin = args.length ();
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 dim_vector dims (1, 1);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
4496
28115
de2c73ae450f allow data type argument for true and false functions
John W. Eaton <jwe@octave.org>
parents: 28043
diff changeset
4497 // 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
4498 // 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
4499
de2c73ae450f allow data type argument for true and false functions
John W. Eaton <jwe@octave.org>
parents: 28043
diff changeset
4500 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
4501 {
de2c73ae450f allow data type argument for true and false functions
John W. Eaton <jwe@octave.org>
parents: 28043
diff changeset
4502 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
4503 nargin--;
de2c73ae450f allow data type argument for true and false functions
John W. Eaton <jwe@octave.org>
parents: 28043
diff changeset
4504
de2c73ae450f allow data type argument for true and false functions
John W. Eaton <jwe@octave.org>
parents: 28043
diff changeset
4505 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
4506 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
4507 }
de2c73ae450f allow data type argument for true and false functions
John W. Eaton <jwe@octave.org>
parents: 28043
diff changeset
4508
29086
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4509 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
4510
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4511 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
4512 && 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
4513 {
a61e1a0f6024 maint: style check C++ files in libinterp/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 30377
diff changeset
4514 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
4515 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
4516
a61e1a0f6024 maint: style check C++ files in libinterp/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 30377
diff changeset
4517 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
4518 nargin -= 2;
a61e1a0f6024 maint: style check C++ files in libinterp/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 30377
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
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4521 switch (nargin)
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4522 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4523 case 0:
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4524 break;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4525
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4526 case 1:
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
4527 get_dimensions (args(0), fcn, dims);
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4528 break;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4529
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4530 default:
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4531 {
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4532 dims.resize (nargin);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4533
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4534 for (int i = 0; i < nargin; i++)
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
4535 dims(i) = (args(i).isempty () ? 0 : args(i).idx_type_value (true));
5747
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 break;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4538 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4539
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4540 dims.chop_trailing_singletons ();
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4541
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
4542 check_dimensions (dims, fcn);
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4543
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4544 // 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
4545 // NDArray to scalar.
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4546
29086
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4547 if (issparse)
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4548 {
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4549 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
4550 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
4551
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4552 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
4553 }
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4554 else
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4555 retval = boolNDArray (dims, val);
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4556
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4557 return retval;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4558 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4559
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3333
diff changeset
4560 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
4561 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
4562 @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
4563 @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
4564 @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
4565 @deftypefnx {} {@var{val} =} ones ([@var{m} @var{n} @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
4566 @deftypefnx {} {@var{val} =} ones (@dots{}, "@var{like}", @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
4567 @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
4568 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
4569
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4570 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
4571 @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
4572
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4573 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
4574 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
4575
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4576 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
4577 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
4578
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4579 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4580 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
4581 @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
4582
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 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
4584 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
4585
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4586 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
4587 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
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 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4590 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
4591 @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
4592 @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
4593 @end deftypefn */)
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
4594 {
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4595 return fill_matrix (args, 1, "ones");
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
4596 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
4597
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
4598 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4599 %!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
4600 %!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
4601 %!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
4602 %!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
4603
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4604 %!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
4605 %!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
4606 %!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
4607 %!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
4608
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4609 %!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
4610 %!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
4611 %!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
4612 %!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
4613
29086
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4614 %!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
4615 %!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
4616 %!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
4617 %!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
4618 %!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
4619 %!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
4620 %!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
4621
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
4622 %!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
4623
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
4624 ## 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
4625 %!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
4626 %!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
4627 %!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
4628 %!error <sparse ND .* not supported> ones (3, 3, 3, "like", speye (1))
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4629 */
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
4630
21405
120bb822c6f4 Handle empty vectors for size of ones(), zeros(), inf(), etc... (bug #47298)
Carnë Draug <carandraug@octave.org>
parents: 21317
diff changeset
4631 /*
120bb822c6f4 Handle empty vectors for size of ones(), zeros(), inf(), etc... (bug #47298)
Carnë Draug <carandraug@octave.org>
parents: 21317
diff changeset
4632 ## 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
4633 ## 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
4634 ## n to be a 1x0 vector (returns 0x0) but not a 0x1 vector. Octave supports
120bb822c6f4 Handle empty vectors for size of ones(), zeros(), inf(), etc... (bug #47298)
Carnë Draug <carandraug@octave.org>
parents: 21317
diff changeset
4635 ## any vector and therefore must support 0x1, 1x0, and 0x0x1 (but not 0x1x1).
23573
1b4f4ec53b4a use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents: 23572
diff changeset
4636 %!test <*47298>
21405
120bb822c6f4 Handle empty vectors for size of ones(), zeros(), inf(), etc... (bug #47298)
Carnë Draug <carandraug@octave.org>
parents: 21317
diff changeset
4637 %! funcs = {@zeros, @ones, @inf, @nan, @NA, @i, @pi, @e};
120bb822c6f4 Handle empty vectors for size of ones(), zeros(), inf(), etc... (bug #47298)
Carnë Draug <carandraug@octave.org>
parents: 21317
diff changeset
4638 %! for idx = 1:numel (funcs)
120bb822c6f4 Handle empty vectors for size of ones(), zeros(), inf(), etc... (bug #47298)
Carnë Draug <carandraug@octave.org>
parents: 21317
diff changeset
4639 %! func = funcs{idx};
21580
ecce63c99c3f maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents: 21575
diff changeset
4640 %! assert (func (zeros (1, 0)), zeros (0, 0));
ecce63c99c3f maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents: 21575
diff changeset
4641 %! assert (func (zeros (0, 1)), zeros (0, 0));
ecce63c99c3f maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents: 21575
diff changeset
4642 %! assert (func (zeros (0, 1, 1)), zeros (0, 0));
ecce63c99c3f maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents: 21575
diff changeset
4643 %! fail ([func2str(func) " ([])"]);
ecce63c99c3f maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents: 21575
diff changeset
4644 %! fail ([func2str(func) " (zeros (0, 0, 1))"]);
21405
120bb822c6f4 Handle empty vectors for size of ones(), zeros(), inf(), etc... (bug #47298)
Carnë Draug <carandraug@octave.org>
parents: 21317
diff changeset
4645 %! endfor
120bb822c6f4 Handle empty vectors for size of ones(), zeros(), inf(), etc... (bug #47298)
Carnë Draug <carandraug@octave.org>
parents: 21317
diff changeset
4646 */
120bb822c6f4 Handle empty vectors for size of ones(), zeros(), inf(), etc... (bug #47298)
Carnë Draug <carandraug@octave.org>
parents: 21317
diff changeset
4647
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3333
diff changeset
4648 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
4649 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
4650 @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
4651 @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
4652 @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
4653 @deftypefnx {} {@var{val} =} zeros ([@var{m} @var{n} @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
4654 @deftypefnx {} {@var{val} =} zeros (@dots{}, "@var{like}", @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
4655 @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
4656 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
4657
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4658 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
4659 @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
4660
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4661 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
4662 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
4663
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
4664 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
4665 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
4666
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4667 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
4668 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
4669
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4670 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4671 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
4672 @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
4673 @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
4674 @end deftypefn */)
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
4675 {
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4676 return fill_matrix (args, 0, "zeros");
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4677 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4678
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
4679 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4680 %!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
4681 %!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
4682 %!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
4683 %!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
4684
29086
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4685 %!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
4686 %!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
4687 %!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
4688 %!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
4689 %!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
4690 %!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
4691
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4692 %!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
4693 %!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
4694 %!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
4695 %!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
4696
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4697 %!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
4698 %!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
4699 %!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
4700 %!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
4701
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
4702 ## 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
4703 %!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
4704 %!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
4705 %!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
4706 %!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
4707 %!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
4708 %!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
4709 %!error <sparse ND .* not supported> zeros (3, 3, 3, "like", speye (1))
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4710 */
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
4711
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4712 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
4713 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
4714 @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
4715 @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
4716
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4717 @deftypefn {} {} Inf
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4718 @deftypefnx {} {} Inf (@var{n})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4719 @deftypefnx {} {} Inf (@var{n}, @var{m})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4720 @deftypefnx {} {} Inf (@var{n}, @var{m}, @var{k}, @dots{})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4721 @deftypefnx {} {} Inf (@dots{}, @var{class})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4722 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
4723 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
4724
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4725 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
4726 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
4727 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
4728
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4729 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4730 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4731 [ 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
4732 @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
4733 @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
4734 @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
4735
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4736 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
4737
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4738 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
4739 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
4740
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4741 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
4742 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
4743 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
4744
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4745 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
4746 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
4747 @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
4748 @end deftypefn */)
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4749 {
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
4750 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
4751 lo_ieee_float_inf_value (), "Inf");
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4752 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4753
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4754 DEFALIAS (inf, Inf);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4755
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
4756 /*
29086
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4757 %!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
4758 %!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
4759 %!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
4760 %!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
4761
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
4762 %!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
4763 %! 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
4764 %!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
4765 %!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
4766 %!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
4767
29086
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4768 %!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
4769 %!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
4770 %!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
4771 %!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
4772 %! 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
4773 %!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
4774
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4775 %!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
4776
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4777 %!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
4778 %!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
4779 %!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
4780 %!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
4781 %!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
4782 %!error <input .* floating> Inf (2, "like", uint8 (1))
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4783 */
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
4784
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4785 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
4786 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
4787 @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
4788 @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
4789
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
4790 @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
4791 @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
4792 @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
4793 @deftypefnx {} {@var{val} =} NaN (@var{n}, @var{m}, @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
4794 @deftypefnx {} {@var{val} =} NaN (@dots{}, "@var{like}", @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
4795 @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
4796 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
4797 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
4798
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4799 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
4800 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
4801 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
4802 @tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4803 ($\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
4804 @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
4805 @ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4806 (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
4807 @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
4808 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
4809
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4810 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
4811 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
4812 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
4813
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4814 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
4815
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4816 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
4817 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
4818
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4819 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
4820 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
4821 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
4822
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
4823 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
4824 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
4825
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4826 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
4827 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
4828 @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
4829 @end deftypefn */)
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4830 {
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
4831 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
4832 lo_ieee_float_nan_value (), "NaN");
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4833 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4834
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4835 DEFALIAS (nan, NaN);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4836
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
4837 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4838 %!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
4839 %!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
4840 %!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
4841 %!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
4842
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
4843 %!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
4844 %! 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
4845 %!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
4846 %!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
4847 %!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
4848
29086
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4849 %!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
4850 %!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
4851 %!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
4852 %! 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
4853 %!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
4854 %!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
4855
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4856 %!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
4857
28930
2883b3d08b7e maint: Remove unnecessary parentheses bracketing %!error BIST tests.
Rik <rik@octave.org>
parents: 28919
diff changeset
4858 %!error NaN (3, "int8")
2883b3d08b7e maint: Remove unnecessary parentheses bracketing %!error BIST tests.
Rik <rik@octave.org>
parents: 28919
diff changeset
4859 %!error NaN (2, 3, "int8")
2883b3d08b7e maint: Remove unnecessary parentheses bracketing %!error BIST tests.
Rik <rik@octave.org>
parents: 28919
diff changeset
4860 %!error NaN (3, 2, "int8")
2883b3d08b7e maint: Remove unnecessary parentheses bracketing %!error BIST tests.
Rik <rik@octave.org>
parents: 28919
diff changeset
4861 %!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
4862 %!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
4863 %!error <input .* floating> NaN (2, "like", uint8 (1))
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4864 */
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
4865
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4866 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
4867 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
4868 @deftypefn {} {} e
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4869 @deftypefnx {} {} e (@var{n})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4870 @deftypefnx {} {} e (@var{n}, @var{m})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4871 @deftypefnx {} {} e (@var{n}, @var{m}, @var{k}, @dots{})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4872 @deftypefnx {} {} e (@dots{}, @var{class})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4873 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
4874 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
4875
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4876 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
4877 @tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4878 $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
4879 @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
4880 @ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4881 @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
4882 @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
4883
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4884 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
4885
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4886 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
4887 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
4888
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4889 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
4890 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
4891 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
4892
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4893 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
4894 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
4895 @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
4896 @end deftypefn */)
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4897 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4898 #if defined (M_E)
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4899 double e_val = M_E;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4900 #else
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4901 double e_val = exp (1.0);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4902 #endif
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4903
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4904 return fill_matrix (args, e_val, "e");
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4905 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4906
24295
48e7efceb427 libinterp/corefcn/data.cc: template eps() to reduce code duplication
Carnë Draug <carandraug@octave.org>
parents: 24219
diff changeset
4907 template <typename T>
48e7efceb427 libinterp/corefcn/data.cc: template eps() to reduce code duplication
Carnë Draug <carandraug@octave.org>
parents: 24219
diff changeset
4908 T
48e7efceb427 libinterp/corefcn/data.cc: template eps() to reduce code duplication
Carnë Draug <carandraug@octave.org>
parents: 24219
diff changeset
4909 eps (const T& x)
48e7efceb427 libinterp/corefcn/data.cc: template eps() to reduce code duplication
Carnë Draug <carandraug@octave.org>
parents: 24219
diff changeset
4910 {
48e7efceb427 libinterp/corefcn/data.cc: template eps() to reduce code duplication
Carnë Draug <carandraug@octave.org>
parents: 24219
diff changeset
4911 T epsval = x.abs ();
48e7efceb427 libinterp/corefcn/data.cc: template eps() to reduce code duplication
Carnë Draug <carandraug@octave.org>
parents: 24219
diff changeset
4912 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
4913 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
4914 {
48e7efceb427 libinterp/corefcn/data.cc: template eps() to reduce code duplication
Carnë Draug <carandraug@octave.org>
parents: 24219
diff changeset
4915 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
4916 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
4917 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
4918 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
4919 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
4920 else
48e7efceb427 libinterp/corefcn/data.cc: template eps() to reduce code duplication
Carnë Draug <carandraug@octave.org>
parents: 24219
diff changeset
4921 {
48e7efceb427 libinterp/corefcn/data.cc: template eps() to reduce code duplication
Carnë Draug <carandraug@octave.org>
parents: 24219
diff changeset
4922 int exponent;
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
4923 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
4924 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
4925 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
4926 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
4927 }
48e7efceb427 libinterp/corefcn/data.cc: template eps() to reduce code duplication
Carnë Draug <carandraug@octave.org>
parents: 24219
diff changeset
4928 }
48e7efceb427 libinterp/corefcn/data.cc: template eps() to reduce code duplication
Carnë Draug <carandraug@octave.org>
parents: 24219
diff changeset
4929 return epsval;
48e7efceb427 libinterp/corefcn/data.cc: template eps() to reduce code duplication
Carnë Draug <carandraug@octave.org>
parents: 24219
diff changeset
4930 }
48e7efceb427 libinterp/corefcn/data.cc: template eps() to reduce code duplication
Carnë Draug <carandraug@octave.org>
parents: 24219
diff changeset
4931
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4932 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
4933 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
4934 @deftypefn {} {} eps
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4935 @deftypefnx {} {} eps (@var{x})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4936 @deftypefnx {} {} eps (@var{n}, @var{m})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4937 @deftypefnx {} {} eps (@var{n}, @var{m}, @var{k}, @dots{})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4938 @deftypefnx {} {} eps (@dots{}, @var{class})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4939 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
4940 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
4941
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4942 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
4943 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
4944 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
4945 @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
4946 @tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4947 $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
4948 @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
4949 @ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4950 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
4951 @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
4952 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
4953
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4954 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
4955 @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
4956
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4957 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
4958 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
4959
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4960 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
4961 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
4962 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
4963 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
4964 @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
4965 @end deftypefn */)
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4966 {
7795
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4967 octave_value retval;
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4968
20819
f428cbe7576f eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents: 20816
diff changeset
4969 if (args.length () == 1 && ! args(0).is_string ())
7795
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4970 {
24295
48e7efceb427 libinterp/corefcn/data.cc: template eps() to reduce code duplication
Carnë Draug <carandraug@octave.org>
parents: 24219
diff changeset
4971 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
4972 if (arg0.is_single_type ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4973 {
24295
48e7efceb427 libinterp/corefcn/data.cc: template eps() to reduce code duplication
Carnë Draug <carandraug@octave.org>
parents: 24219
diff changeset
4974 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
4975 retval = epsval;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4976 }
24296
3981e3a11150 eps: error if input is not of floating point type
Carnë Draug <carandraug@octave.org>
parents: 24295
diff changeset
4977 else if (arg0.is_double_type ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4978 {
24295
48e7efceb427 libinterp/corefcn/data.cc: template eps() to reduce code duplication
Carnë Draug <carandraug@octave.org>
parents: 24219
diff changeset
4979 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
4980 retval = epsval;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4981 }
7795
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4982 else
24296
3981e3a11150 eps: error if input is not of floating point type
Carnë Draug <carandraug@octave.org>
parents: 24295
diff changeset
4983 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
4984 }
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4985 else
15213
336f42406671 use numeric_limits functions instead of DBL_MIN, DBL_MAX, etc.
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
4986 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
4987 std::numeric_limits<float>::epsilon (), "eps");
7795
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4988
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4989 return retval;
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4990 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4991
7795
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4992 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4993 %!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
4994 %!assert (eps (1), 2^(-52))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4995 %!assert (eps (2), 2^(-51))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4996 %!assert (eps (realmax), 2^971)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4997 %!assert (eps (0), 2^(-1074))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4998 %!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
4999 %!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
5000 %!assert (eps (Inf), NaN)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5001 %!assert (eps (NaN), NaN)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
5002 %!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
5003 %! [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
5004 %!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
5005 %!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
5006 %!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
5007 %!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
5008 %!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
5009 %!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
5010 %!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
5011 %!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
5012 %!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
5013 %!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
5014 %! 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
5015 %!error <X must be of a floating point type> eps (uint8 ([0 1 2]))
7795
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
5016 */
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
5017
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5018 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
5019 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
5020 @deftypefn {} {} pi
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5021 @deftypefnx {} {} pi (@var{n})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5022 @deftypefnx {} {} pi (@var{n}, @var{m})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5023 @deftypefnx {} {} pi (@var{n}, @var{m}, @var{k}, @dots{})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5024 @deftypefnx {} {} pi (@dots{}, @var{class})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5025 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
5026 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
5027 @tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5028 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
5029 @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
5030 @ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5031 diameter.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5032 @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
5033
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5034 Internally, @code{pi} is computed as @samp{4.0 * atan (1.0)}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5035
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5036 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
5037 @tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5038 $\pi$.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5039 @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
5040 @ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5041 pi.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5042 @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
5043
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5044 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
5045 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
5046
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5047 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
5048 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
5049 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
5050
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5051 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
5052 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
5053 @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
5054 @end deftypefn */)
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5055 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5056 #if defined (M_PI)
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5057 double pi_val = M_PI;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5058 #else
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5059 double pi_val = 4.0 * atan (1.0);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5060 #endif
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5061
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5062 return fill_matrix (args, pi_val, "pi");
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5063 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5064
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5065 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
5066 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
5067 @deftypefn {} {} realmax
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5068 @deftypefnx {} {} realmax (@var{n})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5069 @deftypefnx {} {} realmax (@var{n}, @var{m})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5070 @deftypefnx {} {} realmax (@var{n}, @var{m}, @var{k}, @dots{})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5071 @deftypefnx {} {} realmax (@dots{}, @var{class})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5072 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
5073 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
5074
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5075 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
5076 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
5077 @tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5078 $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
5079 @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
5080 @ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5081 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
5082 @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
5083 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
5084
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5085 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
5086 @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
5087
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5088 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
5089 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
5090
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5091 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
5092 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
5093 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
5094
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5095 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
5096 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
5097 @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
5098 @end deftypefn */)
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5099 {
15213
336f42406671 use numeric_limits functions instead of DBL_MIN, DBL_MAX, etc.
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
5100 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
5101 std::numeric_limits<float>::max (), "realmax");
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5102 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5103
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5104 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
5105 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
5106 @deftypefn {} {} realmin
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5107 @deftypefnx {} {} realmin (@var{n})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5108 @deftypefnx {} {} realmin (@var{n}, @var{m})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5109 @deftypefnx {} {} realmin (@var{n}, @var{m}, @var{k}, @dots{})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5110 @deftypefnx {} {} realmin (@dots{}, @var{class})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5111 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
5112 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
5113
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5114 The actual value is system dependent. On machines that support
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5115 IEEE floating point arithmetic, @code{realmin} is approximately
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5116 @tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5117 $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
5118 @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
5119 @ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5120 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
5121 @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
5122 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
5123
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5124 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
5125 @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
5126
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5127 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
5128 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
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 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
5131 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
5132 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
5133
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5134 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
5135 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
5136 @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
5137 @end deftypefn */)
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5138 {
15213
336f42406671 use numeric_limits functions instead of DBL_MIN, DBL_MAX, etc.
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
5139 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
5140 std::numeric_limits<float>::min (), "realmin");
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5141 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5142
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5143 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
5144 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
5145 @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
5146 @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
5147 @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
5148 @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
5149
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5150 @deftypefn {} {} I
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5151 @deftypefnx {} {} I (@var{n})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5152 @deftypefnx {} {} I (@var{n}, @var{m})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5153 @deftypefnx {} {} I (@var{n}, @var{m}, @var{k}, @dots{})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5154 @deftypefnx {} {} I (@dots{}, @var{class})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5155 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
5156 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
5157 @tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5158 $\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
5159 @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
5160 @ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5161 @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
5162 @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
5163
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5164 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
5165 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
5166
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5167 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
5168
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5169 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
5170 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
5171
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5172 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
5173 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
5174 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
5175
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5176 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
5177 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
5178 @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
5179 @end deftypefn */)
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5180 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5181 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
5182 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5183
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5184 DEFALIAS (i, I);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5185 DEFALIAS (J, I);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5186 DEFALIAS (j, I);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5187
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5188 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
5189 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
5190 @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
5191 @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
5192 @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
5193 @deftypefnx {} {@var{val} =} NA (@var{n}, @var{m}, @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
5194 @deftypefnx {} {@var{val} =} NA (@dots{}, "@var{like}", @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
5195 @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
5196 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
5197 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
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 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
5200 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
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 @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
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
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
5211 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
5212 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
5213
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5214 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
5215 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
5216 @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
5217 @end deftypefn */)
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5218 {
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
5219 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
5220 lo_ieee_float_na_value (), "NA");
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5221 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5222
7991
139f47cf17ab Change NA value to support single to double precision conversion
David Bateman <dbateman@free.fr>
parents: 7919
diff changeset
5223 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5224 %!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
5225 %!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
5226 */
7991
139f47cf17ab Change NA value to support single to double precision conversion
David Bateman <dbateman@free.fr>
parents: 7919
diff changeset
5227
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5228 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
5229 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
5230 @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
5231 @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
5232 @deftypefnx {} {@var{val} =} false (@var{n}, @var{m}, @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
5233 @deftypefnx {} {@var{val} =} false (@dots{}, "@var{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
5234 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
5235
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5236 If 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
5237 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
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 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
5240 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
5241
8469b3aad7ac ones, zeros, NaN, NA, false, true: Document syntax with "like" (bug #50854).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29163
diff changeset
5242 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
5243 @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
5244 @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
5245 @end deftypefn */)
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5246 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5247 return fill_matrix (args, false, "false");
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5248 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5249
28115
de2c73ae450f allow data type argument for true and false functions
John W. Eaton <jwe@octave.org>
parents: 28043
diff changeset
5250 /*
de2c73ae450f allow data type argument for true and false functions
John W. Eaton <jwe@octave.org>
parents: 28043
diff changeset
5251 %!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
5252 %!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
5253 %!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
5254 %!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
5255
28115
de2c73ae450f allow data type argument for true and false functions
John W. Eaton <jwe@octave.org>
parents: 28043
diff changeset
5256 %!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
5257 %!error <input .* logical> false (2, 1, "like", sparse (1))
28115
de2c73ae450f allow data type argument for true and false functions
John W. Eaton <jwe@octave.org>
parents: 28043
diff changeset
5258 */
de2c73ae450f allow data type argument for true and false functions
John W. Eaton <jwe@octave.org>
parents: 28043
diff changeset
5259
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5260 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
5261 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
5262 @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
5263 @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
5264 @deftypefnx {} {@var{val} =} true (@var{n}, @var{m}, @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
5265 @deftypefnx {} {@var{val} =} true (@dots{}, "@var{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
5266 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
5267
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5268 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
5269 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
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 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
5272 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
5273
8469b3aad7ac ones, zeros, NaN, NA, false, true: Document syntax with "like" (bug #50854).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29163
diff changeset
5274 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
5275 @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
5276 @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
5277 @end deftypefn */)
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5278 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5279 return fill_matrix (args, true, "true");
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3333
diff changeset
5280 }
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
5281
28115
de2c73ae450f allow data type argument for true and false functions
John W. Eaton <jwe@octave.org>
parents: 28043
diff changeset
5282 /*
de2c73ae450f allow data type argument for true and false functions
John W. Eaton <jwe@octave.org>
parents: 28043
diff changeset
5283 %!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
5284 %!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
5285 %!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
5286 %!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
5287
28115
de2c73ae450f allow data type argument for true and false functions
John W. Eaton <jwe@octave.org>
parents: 28043
diff changeset
5288 %!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
5289 %!error <input .* logical> true (2, 1, "like", double (1))
28115
de2c73ae450f allow data type argument for true and false functions
John W. Eaton <jwe@octave.org>
parents: 28043
diff changeset
5290 */
de2c73ae450f allow data type argument for true and false functions
John W. Eaton <jwe@octave.org>
parents: 28043
diff changeset
5291
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
5292 template <typename MT>
4946
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5293 octave_value
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5294 identity_matrix (int nr, int nc)
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5295 {
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5296 octave_value retval;
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5297
9685
e793865ede63 implement builtin_type
Jaroslav Hajek <highegg@gmail.com>
parents: 9658
diff changeset
5298 typename MT::element_type one (1);
4946
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5299
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5300 if (nr == 1 && nc == 1)
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5301 retval = one;
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5302 else
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5303 {
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5304 dim_vector dims (nr, nc);
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5305
9685
e793865ede63 implement builtin_type
Jaroslav Hajek <highegg@gmail.com>
parents: 9658
diff changeset
5306 typename MT::element_type zero (0);
4946
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5307
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5308 MT m (dims, zero);
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5309
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5310 if (nr > 0 && nc > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5311 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5312 int n = std::min (nr, nc);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5313
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5314 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
5315 m(i, i) = one;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5316 }
4946
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5317
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5318 retval = m;
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5319 }
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5320
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5321 return retval;
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5322 }
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5323
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
5324 #define INSTANTIATE_EYE(T) \
5058
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
5325 template octave_value identity_matrix<T> (int, int)
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
5326
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
5327 INSTANTIATE_EYE (int8NDArray);
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
5328 INSTANTIATE_EYE (uint8NDArray);
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
5329 INSTANTIATE_EYE (int16NDArray);
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
5330 INSTANTIATE_EYE (uint16NDArray);
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
5331 INSTANTIATE_EYE (int32NDArray);
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
5332 INSTANTIATE_EYE (uint32NDArray);
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
5333 INSTANTIATE_EYE (int64NDArray);
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
5334 INSTANTIATE_EYE (uint64NDArray);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7743
diff changeset
5335 INSTANTIATE_EYE (FloatNDArray);
5058
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
5336 INSTANTIATE_EYE (NDArray);
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
5337 INSTANTIATE_EYE (boolNDArray);
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
5338
4945
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
5339 static octave_value
4948
7124436476cb [project @ 2004-08-31 17:57:21 by jwe]
jwe
parents: 4947
diff changeset
5340 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
5341 {
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
5342 octave_value retval;
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
5343
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
5344 // 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
5345 // 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
5346
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5347 switch (dt)
4946
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5348 {
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5349 case oct_data_conv::dt_int8:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5350 retval = identity_matrix<int8NDArray> (nr, nc);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5351 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5352
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5353 case oct_data_conv::dt_uint8:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5354 retval = identity_matrix<uint8NDArray> (nr, nc);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5355 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5356
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5357 case oct_data_conv::dt_int16:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5358 retval = identity_matrix<int16NDArray> (nr, nc);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5359 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5360
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5361 case oct_data_conv::dt_uint16:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5362 retval = identity_matrix<uint16NDArray> (nr, nc);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5363 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5364
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5365 case oct_data_conv::dt_int32:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5366 retval = identity_matrix<int32NDArray> (nr, nc);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5367 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5368
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5369 case oct_data_conv::dt_uint32:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5370 retval = identity_matrix<uint32NDArray> (nr, nc);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5371 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5372
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5373 case oct_data_conv::dt_int64:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5374 retval = identity_matrix<int64NDArray> (nr, nc);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5375 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5376
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5377 case oct_data_conv::dt_uint64:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5378 retval = identity_matrix<uint64NDArray> (nr, nc);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5379 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5380
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5381 case oct_data_conv::dt_single:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5382 retval = FloatDiagMatrix (nr, nc, 1.0f);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5383 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5384
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5385 case oct_data_conv::dt_double:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5386 retval = DiagMatrix (nr, nc, 1.0);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5387 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5388
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5389 case oct_data_conv::dt_logical:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5390 retval = identity_matrix<boolNDArray> (nr, nc);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5391 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5392
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5393 default:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5394 error ("eye: invalid class name");
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5395 break;
4945
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
5396 }
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
5397
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
5398 return retval;
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
5399 }
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
5400
4946
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5401 #undef INT_EYE_MATRIX
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5402
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1940
diff changeset
5403 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
5404 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
5405 @deftypefn {} {} eye (@var{n})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5406 @deftypefnx {} {} eye (@var{m}, @var{n})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5407 @deftypefnx {} {} eye ([@var{m} @var{n}])
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5408 @deftypefnx {} {} eye (@dots{}, @var{class})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5409 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
5410
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5411 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
5412 @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
5413
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5414 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
5415 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
5416 @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
5417 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
5418
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5419 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5420 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5421 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
5422 @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
5423 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
5424 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
5425 @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
5426 @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
5427
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5428 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
5429
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5430 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5431 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5432 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
5433 @equiv{}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5434 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
5435 @equiv{}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5436 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
5437 @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
5438 @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
5439
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5440 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
5441 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
5442
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5443 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5444 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
5445 @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
5446
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5447 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
5448 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
5449 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
5450 @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
5451 @end deftypefn */)
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
5452 {
4948
7124436476cb [project @ 2004-08-31 17:57:21 by jwe]
jwe
parents: 4947
diff changeset
5453 int nargin = args.length ();
4945
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
5454
4948
7124436476cb [project @ 2004-08-31 17:57:21 by jwe]
jwe
parents: 4947
diff changeset
5455 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
5456
4945
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
5457 // Check for type information.
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
5458
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
5459 if (nargin > 0 && args(nargin-1).is_string ())
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
5460 {
4948
7124436476cb [project @ 2004-08-31 17:57:21 by jwe]
jwe
parents: 4947
diff changeset
5461 std::string nm = args(nargin-1).string_value ();
4945
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
5462 nargin--;
4948
7124436476cb [project @ 2004-08-31 17:57:21 by jwe]
jwe
parents: 4947
diff changeset
5463
7124436476cb [project @ 2004-08-31 17:57:21 by jwe]
jwe
parents: 4947
diff changeset
5464 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
5465 }
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
5466
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5467 if (nargin > 2)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5468 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5469
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5470 octave_value retval;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5471
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5472 if (nargin == 0)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5473 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
5474 else if (nargin == 1)
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
5475 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5476 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
5477 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
5478
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5479 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
5480 }
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5481 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5482 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5483 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
5484 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
5485
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5486 retval = identity_matrix (nr, nc, dt);
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
5487 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
5488
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
5489 return retval;
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
5490 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
5491
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5492 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5493 %!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
5494 %!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
5495
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5496 %!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
5497 %!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
5498
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5499 %!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
5500 %!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
5501
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
5502 ## Test input validation
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5503 %!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
5504 %!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
5505 %!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
5506 %!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
5507 */
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5508
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
5509 template <typename MT>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
5510 static octave_value
9658
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5511 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
5512 octave_idx_type n)
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5513 {
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5514 typedef typename MT::column_vector_type CVT;
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5515 typedef typename MT::element_type T;
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5516
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5517 octave_value retval;
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5518
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5519 if (base.is_scalar_type ())
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5520 {
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5521 T bs = octave_value_extract<T> (base);
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5522 if (limit.is_scalar_type ())
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5523 {
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5524 T ls = octave_value_extract<T> (limit);
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5525 retval = linspace (bs, ls, n);
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5526 }
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5527 else
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5528 {
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5529 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
5530 CVT bv (lv.numel (), bs);
9658
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5531 retval = linspace (bv, lv, n);
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5532 }
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5533 }
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5534 else
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5535 {
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5536 CVT bv = octave_value_extract<CVT> (base);
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5537 if (limit.is_scalar_type ())
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5538 {
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5539 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
5540 CVT lv (bv.numel (), ls);
9658
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5541 retval = linspace (bv, lv, n);
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5542 }
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5543 else
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5544 {
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5545 CVT lv = octave_value_extract<CVT> (limit);
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5546 retval = linspace (bv, lv, n);
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5547 }
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5548 }
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5549
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5550 return retval;
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5551 }
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5552
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1940
diff changeset
5553 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
5554 doc: /* -*- texinfo -*-
24504
5188d936c79a doc: Documentation fixes for linspace, logspace, lookup (bug #52785).
Rik <rik@octave.org>
parents: 24440
diff changeset
5555 @deftypefn {} {} linspace (@var{start}, @var{end})
5188d936c79a doc: Documentation fixes for linspace, logspace, lookup (bug #52785).
Rik <rik@octave.org>
parents: 24440
diff changeset
5556 @deftypefnx {} {} linspace (@var{start}, @var{end}, @var{n})
5188d936c79a doc: Documentation fixes for linspace, logspace, lookup (bug #52785).
Rik <rik@octave.org>
parents: 24440
diff changeset
5557 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
5558 and @var{end}.
5188d936c79a doc: Documentation fixes for linspace, logspace, lookup (bug #52785).
Rik <rik@octave.org>
parents: 24440
diff changeset
5559
5188d936c79a doc: Documentation fixes for linspace, logspace, lookup (bug #52785).
Rik <rik@octave.org>
parents: 24440
diff changeset
5560 If the number of elements is greater than one, then the endpoints @var{start}
5188d936c79a doc: Documentation fixes for linspace, logspace, lookup (bug #52785).
Rik <rik@octave.org>
parents: 24440
diff changeset
5561 and @var{end} are always included in the range. If @var{start} is greater than
5188d936c79a doc: Documentation fixes for linspace, logspace, lookup (bug #52785).
Rik <rik@octave.org>
parents: 24440
diff changeset
5562 @var{end}, the elements are stored in decreasing order. If the number of
5188d936c79a doc: Documentation fixes for linspace, logspace, lookup (bug #52785).
Rik <rik@octave.org>
parents: 24440
diff changeset
5563 points is not specified, a value of 100 is used.
5188d936c79a doc: Documentation fixes for linspace, logspace, lookup (bug #52785).
Rik <rik@octave.org>
parents: 24440
diff changeset
5564
5188d936c79a doc: Documentation fixes for linspace, logspace, lookup (bug #52785).
Rik <rik@octave.org>
parents: 24440
diff changeset
5565 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
5566 @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
5567 @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
5568 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
5569 @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
5570
5188d936c79a doc: Documentation fixes for linspace, logspace, lookup (bug #52785).
Rik <rik@octave.org>
parents: 24440
diff changeset
5571 For compatibility with @sc{matlab}, return the second argument (@var{end}) when
5188d936c79a doc: Documentation fixes for linspace, logspace, lookup (bug #52785).
Rik <rik@octave.org>
parents: 24440
diff changeset
5572 only a single value (@var{n} = 1) is requested.
5188d936c79a doc: Documentation fixes for linspace, logspace, lookup (bug #52785).
Rik <rik@octave.org>
parents: 24440
diff changeset
5573 @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
5574 @end deftypefn */)
1100
3b6f6c5217e7 [project @ 1995-02-14 01:45:09 by jwe]
jwe
parents: 1032
diff changeset
5575 {
3b6f6c5217e7 [project @ 1995-02-14 01:45:09 by jwe]
jwe
parents: 1032
diff changeset
5576 int nargin = args.length ();
3b6f6c5217e7 [project @ 1995-02-14 01:45:09 by jwe]
jwe
parents: 1032
diff changeset
5577
1940
1b193e313c56 [project @ 1996-02-13 16:28:47 by jwe]
jwe
parents: 1884
diff changeset
5578 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
5579 print_usage ();
1940
1b193e313c56 [project @ 1996-02-13 16:28:47 by jwe]
jwe
parents: 1884
diff changeset
5580
6133
e0065af38cf4 [project @ 2006-11-02 03:33:50 by jwe]
jwe
parents: 5991
diff changeset
5581 octave_idx_type npoints = 100;
1100
3b6f6c5217e7 [project @ 1995-02-14 01:45:09 by jwe]
jwe
parents: 1032
diff changeset
5582 if (nargin == 3)
16077
39129305b914 provide some undocumented matlab behavior for linspace (bug #38151)
John W. Eaton <jwe@octave.org>
parents: 15623
diff changeset
5583 {
39129305b914 provide some undocumented matlab behavior for linspace (bug #38151)
John W. Eaton <jwe@octave.org>
parents: 15623
diff changeset
5584 // 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
5585 // 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
5586 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
5587
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23585
diff changeset
5588 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
5589 npoints = 1;
20466
16b9ec39ff46 Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents: 20405
diff changeset
5590 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
5591 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
5592 else
20573
32a0bf9906c1 linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents: 20562
diff changeset
5593 // 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
5594 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
5595 }
1100
3b6f6c5217e7 [project @ 1995-02-14 01:45:09 by jwe]
jwe
parents: 1032
diff changeset
5596
20573
32a0bf9906c1 linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents: 20562
diff changeset
5597 octave_value arg_1 = args(0);
32a0bf9906c1 linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents: 20562
diff changeset
5598 octave_value arg_2 = args(1);
32a0bf9906c1 linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents: 20562
diff changeset
5599
32a0bf9906c1 linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents: 20562
diff changeset
5600 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
5601 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
5602 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
5603 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
5604
32a0bf9906c1 linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents: 20562
diff changeset
5605 if (! isvector1 || ! isvector2)
24535
22a2bc91cc7f Add more BIST tests for linspace.
Rik <rik@octave.org>
parents: 24534
diff changeset
5606 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
5607
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5608 octave_value retval;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5609
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5610 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
5611 {
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
5612 if (arg_1.iscomplex () || arg_2.iscomplex ())
20573
32a0bf9906c1 linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents: 20562
diff changeset
5613 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
5614 else
20573
32a0bf9906c1 linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents: 20562
diff changeset
5615 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
5616 }
4732
b484cdca27be [project @ 2004-02-04 04:32:48 by jwe]
jwe
parents: 4685
diff changeset
5617 else
20573
32a0bf9906c1 linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents: 20562
diff changeset
5618 {
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
5619 if (arg_1.iscomplex () || arg_2.iscomplex ())
20573
32a0bf9906c1 linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents: 20562
diff changeset
5620 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
5621 else
32a0bf9906c1 linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents: 20562
diff changeset
5622 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
5623 }
1100
3b6f6c5217e7 [project @ 1995-02-14 01:45:09 by jwe]
jwe
parents: 1032
diff changeset
5624
3b6f6c5217e7 [project @ 1995-02-14 01:45:09 by jwe]
jwe
parents: 1032
diff changeset
5625 return retval;
3b6f6c5217e7 [project @ 1995-02-14 01:45:09 by jwe]
jwe
parents: 1032
diff changeset
5626 }
3b6f6c5217e7 [project @ 1995-02-14 01:45:09 by jwe]
jwe
parents: 1032
diff changeset
5627
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5628 /*
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5629 %!test
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5630 %! 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
5631 %! 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
5632 %! 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
5633 %! 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
5634 %! 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
5635 %! 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
5636 %! 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
5637 %! 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
5638 %! 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
5639
20466
16b9ec39ff46 Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents: 20405
diff changeset
5640 ## Test complex values
16b9ec39ff46 Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents: 20405
diff changeset
5641 %!test
16b9ec39ff46 Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents: 20405
diff changeset
5642 %! 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
5643 %! 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
5644 %! assert (obs, exp);
16b9ec39ff46 Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents: 20405
diff changeset
5645
24535
22a2bc91cc7f Add more BIST tests for linspace.
Rik <rik@octave.org>
parents: 24534
diff changeset
5646 ## 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
5647 %!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
5648 %! [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
5649 %!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
5650 %! [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
5651 %!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
5652 %! [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
5653 %!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
5654 %! [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
5655 %!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
5656 %! [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
5657 %!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
5658 %! [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
5659
20466
16b9ec39ff46 Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents: 20405
diff changeset
5660 ## Test class of output
16b9ec39ff46 Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents: 20405
diff changeset
5661 %!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
5662 %!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
5663 %!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
5664
27435
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5665 ## Test symmetry
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5666 %!test <*56659>
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5667 %! x = linspace (-1, 1, 10);
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5668 %! assert (all (x == -fliplr (x)));
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5669 %! x = linspace (-1, 1, 11);
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5670 %! assert (all (x == -fliplr (x)));
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5671
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5672 %!test <*56659>
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5673 %! x = linspace (-1-1i, 1+1i, 10);
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5674 %! assert (all (x == -fliplr (x)));
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5675 %! x = linspace (-1-1i, 1+1i, 11);
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5676 %! assert (all (x == -fliplr (x)));
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5677
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5678 %!test <*56659>
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5679 %! x = linspace (single (-1), 1, 10);
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5680 %! assert (all (x == -fliplr (x)));
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5681 %! x = linspace (single (-1), 1, 11);
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5682 %! assert (all (x == -fliplr (x)));
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5683
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5684 %!test <*56659>
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5685 %! x = linspace (single (-1-1i), 1+1i, 10);
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5686 %! assert (all (x == -fliplr (x)));
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5687 %! x = linspace (single (-1-1i), 1+1i, 11);
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5688 %! assert (all (x == -fliplr (x)));
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5689
20466
16b9ec39ff46 Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents: 20405
diff changeset
5690 ## 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
5691 %!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
5692 %!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
5693 %!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
5694 %!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
5695 %!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
5696 %!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
5697 %!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
5698 %!assert (linspace (10, 20, 2.1), [10 20])
32a0bf9906c1 linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents: 20562
diff changeset
5699 %!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
5700 %!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
5701 %!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
5702 %!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
5703 %!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
5704 %!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
5705 %!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
5706
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5707 ## 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
5708 ## 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
5709 ## 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
5710 ## 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
5711 ## tests can be re-instated.
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5712 ##%!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
5713 ##%!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
5714 ##%!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
5715 ##%!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
5716 ##%!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
5717 ##%!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
5718
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5719 %!error linspace ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5720 %!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
5721 %!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
5722 %!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
5723 %!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
5724 %!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
5725 */
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5726
20726
25d676f9619c Preface error() messages with name of function when possible.
Rik <rik@octave.org>
parents: 20720
diff changeset
5727 // 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
5728 // 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
5729
5731
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
5730 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
5731 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
5732 @deftypefn {} {} resize (@var{x}, @var{m})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5733 @deftypefnx {} {} resize (@var{x}, @var{m}, @var{n}, @dots{})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5734 @deftypefnx {} {} resize (@var{x}, [@var{m} @var{n} @dots{}])
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5735 Resize @var{x} cutting off elements as necessary.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5736
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5737 In the result, element with certain indices is equal to the corresponding
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5738 element of @var{x} if the indices are within the bounds of @var{x};
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5739 otherwise, the element is set to zero.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5740
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5741 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
5742
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5743 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5744 y = resize (x, dv)
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5745 @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
5746
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5747 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5748 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
5749
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5750 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5751 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5752 y = zeros (dv, class (x));
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5753 sz = min (dv, size (x));
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5754 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
5755 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
5756 endfor
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5757 y(idx@{:@}) = x(idx@{:@});
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5758 @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
5759 @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
5760
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5761 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5762 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
5763
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5764 If only @var{m} is supplied, and it is a scalar, the dimension of the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5765 result is @var{m}-by-@var{m}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5766 If @var{m}, @var{n}, @dots{} are all scalars, then the dimensions of
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5767 the result are @var{m}-by-@var{n}-by-@dots{}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5768 If given a vector as input, then the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5769 dimensions of the result are given by the elements of that vector.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5770
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5771 An object can be resized to more dimensions than it has;
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5772 in such case the missing dimensions are assumed to be 1.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5773 Resizing an object to fewer dimensions is not possible.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5774 @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
5775 @end deftypefn */)
5731
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
5776 {
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
5777 int nargin = args.length ();
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
5778
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5779 if (nargin < 2)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5780 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5781
5731
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
5782 octave_value retval;
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
5783
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
5784 if (nargin == 2)
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
5785 {
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
5786 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
5787 int ndim = vec.numel ();
5731
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
5788 if (ndim == 1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5789 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5790 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
5791 retval = args(0);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5792 retval = retval.resize (dim_vector (m, m), true);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5793 }
5731
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
5794 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5795 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5796 dim_vector dv;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5797 dv.resize (ndim);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5798 for (int i = 0; i < ndim; i++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5799 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
5800 retval = args(0);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5801 retval = retval.resize (dv, true);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5802 }
5731
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
5803 }
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5804 else
5731
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
5805 {
8799
f6dc6eb57045 improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 8780
diff changeset
5806 dim_vector dv;
f6dc6eb57045 improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 8780
diff changeset
5807 dv.resize (nargin - 1);
f6dc6eb57045 improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 8780
diff changeset
5808 for (octave_idx_type i = 1; i < nargin; i++)
f6dc6eb57045 improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 8780
diff changeset
5809 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
5810
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5811 retval = args(0);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5812 retval = retval.resize (dv, true);
5731
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
5813 }
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5814
5731
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
5815 return retval;
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
5816 }
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
5817
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
5818 // FIXME: should use octave_idx_type for dimensions.
5734
a7d2c47371d2 [project @ 2006-04-04 18:29:13 by jwe]
jwe
parents: 5731
diff changeset
5819
4567
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
5820 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
5821 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
5822 @deftypefn {} {} reshape (@var{A}, @var{m}, @var{n}, @dots{})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5823 @deftypefnx {} {} reshape (@var{A}, [@var{m} @var{n} @dots{}])
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5824 @deftypefnx {} {} reshape (@var{A}, @dots{}, [], @dots{})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5825 @deftypefnx {} {} reshape (@var{A}, @var{size})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5826 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
5827 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
5828
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5829 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
5830 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
5831
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5832 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
5833 matrix.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5834
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5835 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5836 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5837 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
5838 @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
5839 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
5840 @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
5841 @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
5842
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5843 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5844 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
5845 (@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
5846 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
5847
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5848 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
5849 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
5850 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
5851 @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
5852 @end deftypefn */)
4567
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
5853 {
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
5854 int nargin = args.length ();
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
5855
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5856 if (nargin < 2)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5857 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5858
4567
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
5859 octave_value retval;
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
5860
10693
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
5861 dim_vector new_dims;
4567
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
5862
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
5863 if (nargin == 2)
10693
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
5864 {
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
5865 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
5866
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20218
diff changeset
5867 if (new_size.numel () < 2)
20893
384ff5aa9437 2015 Code Sprint: Eliminate useless return statements after error ().
Rik <rik@octave.org>
parents: 20884
diff changeset
5868 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
5869
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20218
diff changeset
5870 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
5871
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20218
diff changeset
5872 for (octave_idx_type i = 0; i < new_size.numel (); i++)
10693
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
5873 {
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
5874 if (new_size(i) < 0)
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5875 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
5876
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
5877 new_dims(i) = new_size(i);
10693
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
5878 }
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
5879 }
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5880 else
4567
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
5881 {
10693
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
5882 new_dims = dim_vector::alloc (nargin-1);
5013
1eb9ce5c0152 [project @ 2004-09-21 22:18:07 by jwe]
jwe
parents: 4986
diff changeset
5883 int empty_dim = -1;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
5884
4567
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
5885 for (int i = 1; i < nargin; i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5886 {
23577
80c42f4cca13 maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents: 23576
diff changeset
5887 if (args(i).isempty ())
10693
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
5888 {
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
5889 if (empty_dim > 0)
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5890 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
5891
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
5892 empty_dim = i;
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
5893 new_dims(i-1) = 1;
10693
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
5894 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5895 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5896 {
10693
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
5897 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
5898
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5899 if (new_dims(i-1) < 0)
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5900 error ("reshape: SIZE must be non-negative");
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5901 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5902 }
5013
1eb9ce5c0152 [project @ 2004-09-21 22:18:07 by jwe]
jwe
parents: 4986
diff changeset
5903
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5904 if (empty_dim > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5905 {
10693
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
5906 octave_idx_type nel = new_dims.numel ();
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5907
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5908 if (nel == 0)
10693
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
5909 new_dims(empty_dim-1) = 0;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5910 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5911 {
10693
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
5912 octave_idx_type a_nel = args(0).numel ();
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
5913 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
5914
10693
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
5915 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
5916 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
5917 "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
5918 nel);
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(empty_dim-1) = size_empty_dim;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5921 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5922 }
4567
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
5923 }
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
5924
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5925 retval = args(0).reshape (new_dims);
4567
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
5926
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
5927 return retval;
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
5928 }
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
5929
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5930 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5931 %!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
5932 %!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
5933 %!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
5934 %!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
5935
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5936 %!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
5937 %!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
5938 %!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
5939 %!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
5940
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5941 %!test
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5942 %! s.a = 1;
17915
56d2b6838405 Issue an error if reshape called with just a single dimension.
Rik <rik@octave.org>
parents: 17843
diff changeset
5943 %! 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
5944
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5945 %!error reshape ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5946 %!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
5947 %!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
5948 %!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
5949 %!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
5950 %!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
5951 %!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
5952 */
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5953
10694
d97165928d05 implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents: 10693
diff changeset
5954 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
5955 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5956 @deftypefn {} {@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
5957 @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
5958 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
5959 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
5960
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5961 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
5962
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5963 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
5964 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
5965 @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
5966 @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
5967 @end deftypefn */)
10694
d97165928d05 implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents: 10693
diff changeset
5968 {
11402
a9a3ee461b83 Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents: 11357
diff changeset
5969 int nargin = args.length ();
a9a3ee461b83 Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents: 11357
diff changeset
5970
a9a3ee461b83 Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents: 11357
diff changeset
5971 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
5972 print_usage ();
11402
a9a3ee461b83 Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents: 11357
diff changeset
5973
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5974 int dim = 1;
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5975 if (nargin == 2)
11402
a9a3ee461b83 Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents: 11357
diff changeset
5976 {
a9a3ee461b83 Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents: 11357
diff changeset
5977 dim = args(1).idx_type_value ();
a9a3ee461b83 Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents: 11357
diff changeset
5978
a9a3ee461b83 Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents: 11357
diff changeset
5979 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
5980 error ("vec: DIM must be greater than zero");
11402
a9a3ee461b83 Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents: 11357
diff changeset
5981 }
a9a3ee461b83 Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents: 11357
diff changeset
5982
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5983 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
5984 octave_value arg = args(0);
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5985
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5986 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
5987
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5988 if (dim > 1)
10694
d97165928d05 implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents: 10693
diff changeset
5989 {
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5990 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
5991
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5992 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
5993 new_dims(i) = 1;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5994
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5995 new_dims(dim-1) = retval.numel ();
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5996
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5997 retval = retval.reshape (new_dims);
10694
d97165928d05 implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents: 10693
diff changeset
5998 }
d97165928d05 implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents: 10693
diff changeset
5999
d97165928d05 implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents: 10693
diff changeset
6000 return retval;
d97165928d05 implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents: 10693
diff changeset
6001 }
d97165928d05 implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents: 10693
diff changeset
6002
d97165928d05 implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents: 10693
diff changeset
6003 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6004 %!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
6005 %!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
6006 %!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
6007 %!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
6008 %!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
6009 %!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
6010 %!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
6011 %!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
6012
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6013 %!error vec ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6014 %!error vec (1, 2, 3)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6015 %!error vec ([1, 2; 3, 4], 0)
10694
d97165928d05 implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents: 10693
diff changeset
6016 */
d97165928d05 implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents: 10693
diff changeset
6017
4532
01ee68d18069 [project @ 2003-10-10 00:49:54 by jwe]
jwe
parents: 4516
diff changeset
6018 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
6019 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
6020 @deftypefn {} {} squeeze (@var{x})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6021 Remove singleton dimensions from @var{x} and return the result.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6022
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6023 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
6024 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
6025 @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
6026 @end deftypefn */)
4532
01ee68d18069 [project @ 2003-10-10 00:49:54 by jwe]
jwe
parents: 4516
diff changeset
6027 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6028 if (args.length () != 1)
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
6029 print_usage ();
4532
01ee68d18069 [project @ 2003-10-10 00:49:54 by jwe]
jwe
parents: 4516
diff changeset
6030
21127
df7891224709 maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents: 21121
diff changeset
6031 return ovl (args(0).squeeze ());
4532
01ee68d18069 [project @ 2003-10-10 00:49:54 by jwe]
jwe
parents: 4516
diff changeset
6032 }
01ee68d18069 [project @ 2003-10-10 00:49:54 by jwe]
jwe
parents: 4516
diff changeset
6033
8458
d254a21e0120 reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents: 8433
diff changeset
6034 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
6035 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
6036 @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
6037 Return a full storage matrix from a sparse, diagonal, or permutation matrix,
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6038 or a range.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6039 @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
6040 @end deftypefn */)
8458
d254a21e0120 reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents: 8433
diff changeset
6041 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6042 if (args.length () != 1)
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
6043 print_usage ();
8458
d254a21e0120 reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents: 8433
diff changeset
6044
21127
df7891224709 maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents: 21121
diff changeset
6045 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
6046 }
d254a21e0120 reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents: 8433
diff changeset
6047
6945
6bbf56a9718a [project @ 2007-10-02 20:47:22 by jwe]
jwe
parents: 6887
diff changeset
6048 // Compute various norms of the vector X.
6bbf56a9718a [project @ 2007-10-02 20:47:22 by jwe]
jwe
parents: 6887
diff changeset
6049
6953
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
6050 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
6051 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
6052 @deftypefn {} {} norm (@var{A})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6053 @deftypefnx {} {} norm (@var{A}, @var{p})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6054 @deftypefnx {} {} norm (@var{A}, @var{p}, @var{opt})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6055 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
6056
22827
c3d3a81ad986 doc: Update documentation for norm, normest, normest1, condest.
Rik <rik@octave.org>
parents: 22791
diff changeset
6057 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
6058
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6059 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
6060
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6061 @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
6062 @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
6063 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
6064
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6065 @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
6066 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
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 @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
6069 @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
6070 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
6071
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6072 @item @var{p} = @qcode{"fro"}
25003
2365c2661b3c doc: Spellcheck documentation ahead of 4.4 release.
Rik <rik@octave.org>
parents: 24859
diff changeset
6073 @cindex @nospell{Frobenius} norm
2365c2661b3c doc: Spellcheck documentation ahead of 4.4 release.
Rik <rik@octave.org>
parents: 24859
diff changeset
6074 @nospell{Frobenius} norm of @var{A},
2365c2661b3c doc: Spellcheck documentation ahead of 4.4 release.
Rik <rik@octave.org>
parents: 24859
diff changeset
6075 @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
6076
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6077 @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
6078 @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
6079 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
6080 @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
6081
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6082 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
6083
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6084 @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
6085 @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
6086 @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
6087
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6088 @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
6089 @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
6090
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6091 @item @var{p} = @qcode{"fro"}
25003
2365c2661b3c doc: Spellcheck documentation ahead of 4.4 release.
Rik <rik@octave.org>
parents: 24859
diff changeset
6092 @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
6093
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6094 @item @var{p} = 0
22827
c3d3a81ad986 doc: Update documentation for norm, normest, normest1, condest.
Rik <rik@octave.org>
parents: 22791
diff changeset
6095 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
6096
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6097 @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
6098 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
6099
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6100 @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
6101 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
6102 @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
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{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
6105 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
6106 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
6107 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
6108 @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
6109 @end deftypefn */)
6508
184ab67c3bc1 [project @ 2007-04-07 00:43:09 by jwe]
jwe
parents: 6401
diff changeset
6110 {
184ab67c3bc1 [project @ 2007-04-07 00:43:09 by jwe]
jwe
parents: 6401
diff changeset
6111 int nargin = args.length ();
184ab67c3bc1 [project @ 2007-04-07 00:43:09 by jwe]
jwe
parents: 6401
diff changeset
6112
22789
bedfedcd878e norm: fix error in input argument validation leading to segfault (bug #49634)
Mike Miller <mtmiller@octave.org>
parents: 22749
diff changeset
6113 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
6114 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6115
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6116 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
6117
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6118 if (x_arg.ndims () != 2)
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6119 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
6120
23147
eb5a162c1342 Accept case-insensitive string value for p-value input to norm (bug #50195);
Rik <rik@octave.org>
parents: 23141
diff changeset
6121 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
6122 if (nargin > 1 && args(nargin-1).is_string ())
6508
184ab67c3bc1 [project @ 2007-04-07 00:43:09 by jwe]
jwe
parents: 6401
diff changeset
6123 {
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6124 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
6125 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
6126 if (str == "cols" || str == "columns")
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6127 strflag = sfcols;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6128 else if (str == "rows")
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6129 strflag = sfrows;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6130 else if (str == "fro")
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6131 strflag = sffrob;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6132 else if (str == "inf")
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6133 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
6134 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
6135 strflag = sfneginf;
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6136 else
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6137 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
6138
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6139 // 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
6140 nargin--;
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6141 }
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6142
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6143 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
6144
23577
80c42f4cca13 maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents: 23576
diff changeset
6145 if (p_arg.isempty ())
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6146 p_arg = octave_value (2);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6147 else if (p_arg.is_string ())
6508
184ab67c3bc1 [project @ 2007-04-07 00:43:09 by jwe]
jwe
parents: 6401
diff changeset
6148 {
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6149 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
6150 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
6151 if (strflag != sfcols && strflag != sfrows)
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
6152 error ("norm: invalid combination of options");
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
6153
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
6154 if (str == "cols" || str == "columns" || str == "rows")
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
6155 error ("norm: invalid combination of options");
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
6156
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
6157 if (str == "fro")
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
6158 p_arg = octave_value (2);
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
6159 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
6160 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
6161 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
6162 p_arg = -numeric_limits<double>::Inf ();
6508
184ab67c3bc1 [project @ 2007-04-07 00:43:09 by jwe]
jwe
parents: 6401
diff changeset
6163 else
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
6164 error ("norm: unrecognized option: %s", str.c_str ());
6508
184ab67c3bc1 [project @ 2007-04-07 00:43:09 by jwe]
jwe
parents: 6401
diff changeset
6165 }
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6166 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
6167 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
6168
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6169 octave_value retval;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6170
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6171 switch (strflag)
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6172 {
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6173 case sfmatrix:
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6174 retval = xnorm (x_arg, p_arg);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6175 break;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6176
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6177 case sfcols:
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6178 retval = xcolnorms (x_arg, p_arg);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6179 break;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6180
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6181 case sfrows:
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6182 retval = xrownorms (x_arg, p_arg);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6183 break;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6184
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6185 case sffrob:
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6186 retval = xfrobnorm (x_arg);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6187 break;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6188
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6189 case sfinf:
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
6190 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
6191 break;
23147
eb5a162c1342 Accept case-insensitive string value for p-value input to norm (bug #50195);
Rik <rik@octave.org>
parents: 23141
diff changeset
6192
eb5a162c1342 Accept case-insensitive string value for p-value input to norm (bug #50195);
Rik <rik@octave.org>
parents: 23141
diff changeset
6193 case sfneginf:
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
6194 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
6195 break;
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6196 }
6508
184ab67c3bc1 [project @ 2007-04-07 00:43:09 by jwe]
jwe
parents: 6401
diff changeset
6197
184ab67c3bc1 [project @ 2007-04-07 00:43:09 by jwe]
jwe
parents: 6401
diff changeset
6198 return retval;
184ab67c3bc1 [project @ 2007-04-07 00:43:09 by jwe]
jwe
parents: 6401
diff changeset
6199 }
184ab67c3bc1 [project @ 2007-04-07 00:43:09 by jwe]
jwe
parents: 6401
diff changeset
6200
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
6201 /*
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
6202 %!shared x
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
6203 %! 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
6204 %!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
6205 %!assert (norm (x,1), 20)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6206 %!assert (norm (x,2), 10)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6207 %!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
6208 %!assert (norm (x,Inf), 7)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6209 %!assert (norm (x,-Inf), 1)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6210 %!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
6211 %!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
6212 %!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
6213 %!assert (norm (x), 10)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6214 %!assert (norm ([1e200, 1]), 1e200)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6215 %!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
6216 %!shared m
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
6217 %! m = magic (4);
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6218 %!assert (norm (m,1), 34)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6219 %!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
6220 %!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
6221 %!assert (norm (m,Inf), 34)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6222 %!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
6223 %!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
6224 %! 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
6225 %! 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
6226 %! fhi = 1e+300;
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6227 %!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
6228 %!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
6229
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
6230 %!shared x
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6231 %! 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
6232 %!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
6233 %!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
6234 %!assert (norm (x,2), single (10))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6235 %!assert (norm (x,3), single (8.24257059961711), -4*eps ("single"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6236 %!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
6237 %!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
6238 %!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
6239 %!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
6240 %!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
6241 %!assert (norm (x), single (10))
18676
5bd1ca29c5f0 Clean up questionable code bits identified by clang sanitize.
Rik <rik@octave.org>
parents: 18212
diff changeset
6242 %!assert (norm (single ([1e38, 1])), single (1e38))
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6243 %!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
6244 %!shared m
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6245 %! m = single (magic (4));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6246 %!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
6247 %!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
6248 %!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
6249 %!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
6250 %!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
6251 %!shared m2, flo, fhi
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6252 %! 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
6253 %! flo = single (1e-300);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6254 %! fhi = single (1e+300);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6255 %!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
6256 %!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
6257
23141
bfa4ad642fa0 Disallow p-norm of -Inf for matrices (bug #50194).
Rik <rik@octave.org>
parents: 23127
diff changeset
6258 ## Hamming norm (p == 0)
bfa4ad642fa0 Disallow p-norm of -Inf for matrices (bug #50194).
Rik <rik@octave.org>
parents: 23127
diff changeset
6259 %!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
6260
17115
00985134145e norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents: 16892
diff changeset
6261 %!shared q
00985134145e norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents: 16892
diff changeset
6262 %! q = rand (1e3, 3);
21317
a4faec57f4c8 maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents: 21301
diff changeset
6263 %!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
6264 %!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
6265 %!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
6266 %!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
6267 %!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
6268 %!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
6269 %!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
6270 %!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
6271 %!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
6272
22489
93ea313301f9 test: Add bug ids (<#####>) to BIST tests.
Rik <rik@octave.org>
parents: 22440
diff changeset
6273 %!test <30631>
93ea313301f9 test: Add bug ids (<#####>) to BIST tests.
Rik <rik@octave.org>
parents: 22440
diff changeset
6274 %! ## 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
6275 %! 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
6276 %! 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
6277 %! 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
6278
bedfedcd878e norm: fix error in input argument validation leading to segfault (bug #49634)
Mike Miller <mtmiller@octave.org>
parents: 22749
diff changeset
6279 ## 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
6280 %!error norm ()
bedfedcd878e norm: fix error in input argument validation leading to segfault (bug #49634)
Mike Miller <mtmiller@octave.org>
parents: 22749
diff changeset
6281 %!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
6282 %!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
6283 %!error <unrecognized option> norm (1, "rows", "invalid")
22791
da106618264a norm: fix input validation tests
Mike Miller <mtmiller@octave.org>
parents: 22789
diff changeset
6284 %!error <unrecognized option> norm (1, "invalid", "rows")
da106618264a norm: fix input validation tests
Mike Miller <mtmiller@octave.org>
parents: 22789
diff changeset
6285 %!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
6286 %!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
6287 %!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
6288 */
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
6289
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6290 static octave_value
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6291 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
6292 const octave_value_list& args)
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6293 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6294 if (args.length () != 1)
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6295 print_usage ();
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6296
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
6297 return unary_op (op, args(0));
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6298 }
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6299
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6300 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
6301 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
6302 @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
6303 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
6304
24618
c99163d188df doc: Use @var{} around variables in operator functions such as and, or, uplus.
Rik <rik@octave.org>
parents: 24517
diff changeset
6305 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
6306 @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
6307 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6308 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6309 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
6310 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6311
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6312 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
6313 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
6314 @deftypefn {} {} uplus (@var{x})
24618
c99163d188df doc: Use @var{} around variables in operator functions such as and, or, uplus.
Rik <rik@octave.org>
parents: 24517
diff changeset
6315 This function and @w{@tcode{+ @var{x}}} are equivalent.
29514
ec768b0f7dcd doc: Use Texinfo commands to improve transpose() docstring rendering.
Rik <rik@octave.org>
parents: 29358
diff changeset
6316 @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
6317 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6318 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6319 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
6320 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6321
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6322 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
6323 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
6324 @deftypefn {} {} uminus (@var{x})
24618
c99163d188df doc: Use @var{} around variables in operator functions such as and, or, uplus.
Rik <rik@octave.org>
parents: 24517
diff changeset
6325 This function and @w{@tcode{- @var{x}}} 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
6326 @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
6327 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6328 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6329 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
6330 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6331
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6332 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
6333 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
6334 @deftypefn {} {} transpose (@var{x})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6335 Return the transpose of @var{x}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6336
29514
ec768b0f7dcd doc: Use Texinfo commands to improve transpose() docstring rendering.
Rik <rik@octave.org>
parents: 29358
diff changeset
6337 This function and @tcode{@var{x}.'@:} 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
6338 @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
6339 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6340 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6341 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
6342 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6343
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
6344 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6345 %!assert (2.', 2)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6346 %!assert (2i.', 2i)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6347 %!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
6348 %!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
6349 %!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
6350 %!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
6351
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6352 %!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
6353
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6354 %!assert (single (2).', single (2))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6355 %!assert (single (2i).', single (2i))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6356 %!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
6357 %!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
6358 %!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
6359 %!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
6360
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6361 %!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
6362 */
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
6363
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6364 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
6365 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
6366 @deftypefn {} {} ctranspose (@var{x})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6367 Return the complex conjugate transpose of @var{x}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6368
24618
c99163d188df doc: Use @var{} around variables in operator functions such as and, or, uplus.
Rik <rik@octave.org>
parents: 24517
diff changeset
6369 This function and @tcode{@var{x}'} 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
6370 @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
6371 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6372 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6373 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
6374 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6375
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
6376 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6377 %!assert (2', 2)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6378 %!assert (2i', -2i)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6379 %!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
6380 %!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
6381 %!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
6382 %!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
6383
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6384 %!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
6385
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6386 %!assert (single (2)', single (2))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6387 %!assert (single (2i)', single (-2i))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6388 %!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
6389 %!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
6390 %!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
6391 %!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
6392
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6393 %!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
6394 */
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
6395
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6396 static octave_value
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6397 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
6398 const octave_value_list& args)
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6399 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6400 if (args.length () != 2)
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6401 print_usage ();
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6402
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
6403 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
6404 }
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6405
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6406 static octave_value
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6407 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
6408 octave_value::assign_op aop,
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6409 const octave_value_list& args)
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6410 {
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6411 int nargin = args.length ();
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6412
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
6413 if (nargin < 2)
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6414 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6415
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6416 octave_value retval;
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6417
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
6418 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
6419 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
6420 else
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6421 {
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
6422 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
6423
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
6424 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
6425 retval.assign (aop, args(i));
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6426 }
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6427
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6428 return retval;
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6429 }
9339
c0b104835d0d allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
6430
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6431 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
6432 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
6433 @deftypefn {} {} plus (@var{x}, @var{y})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6434 @deftypefnx {} {} plus (@var{x1}, @var{x2}, @dots{})
24618
c99163d188df doc: Use @var{} around variables in operator functions such as and, or, uplus.
Rik <rik@octave.org>
parents: 24517
diff changeset
6435 This function and @w{@tcode{@var{x} + @var{y}}} 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
6436
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6437 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
6438 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
6439
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6440 @example
24618
c99163d188df doc: Use @var{} around variables in operator functions such as and, or, uplus.
Rik <rik@octave.org>
parents: 24517
diff changeset
6441 (@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
6442 @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
6443
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6444 @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
6445 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6446 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6447 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
6448 octave_value::op_add_eq, args);
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6449 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6450
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
6451 /*
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
6452 %!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
6453 %!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
6454 %!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
6455 %!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
6456
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
6457 ## 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
6458 %!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
6459 %!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
6460 */
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
6461
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6462 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
6463 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
6464 @deftypefn {} {} minus (@var{x}, @var{y})
24618
c99163d188df doc: Use @var{} around variables in operator functions such as and, or, uplus.
Rik <rik@octave.org>
parents: 24517
diff changeset
6465 This function and @w{@tcode{@var{x} - @var{y}}} 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
6466 @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
6467 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6468 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6469 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
6470 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6471
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6472 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
6473 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
6474 @deftypefn {} {} mtimes (@var{x}, @var{y})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6475 @deftypefnx {} {} mtimes (@var{x1}, @var{x2}, @dots{})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6476 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
6477
24618
c99163d188df doc: Use @var{} around variables in operator functions such as and, or, uplus.
Rik <rik@octave.org>
parents: 24517
diff changeset
6478 This function and @w{@tcode{@var{x} * @var{y}}} 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
6479 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
6480 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
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 @example
24618
c99163d188df doc: Use @var{} around variables in operator functions such as and, or, uplus.
Rik <rik@octave.org>
parents: 24517
diff changeset
6483 (@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
6484 @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
6485
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6486 @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
6487 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6488 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6489 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
6490 octave_value::op_mul_eq, args);
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6491 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6492
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6493 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
6494 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
6495 @deftypefn {} {} mrdivide (@var{x}, @var{y})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6496 Return the matrix right division of @var{x} and @var{y}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6497
24618
c99163d188df doc: Use @var{} around variables in operator functions such as and, or, uplus.
Rik <rik@octave.org>
parents: 24517
diff changeset
6498 This function and @w{@tcode{@var{x} / @var{y}}} 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
6499
290eff7148bb mrdivide, mldivide: Document that functions might return minimum norm solutions (bug #60839).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29817
diff changeset
6500 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
6501 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
6502 @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
6503 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6504 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6505 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
6506 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6507
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6508 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
6509 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
6510 @deftypefn {} {} mpower (@var{x}, @var{y})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6511 Return the matrix power operation of @var{x} raised to the @var{y} power.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6512
24618
c99163d188df doc: Use @var{} around variables in operator functions such as and, or, uplus.
Rik <rik@octave.org>
parents: 24517
diff changeset
6513 This function and @w{@tcode{@var{x} ^ @var{y}}} 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
6514 @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
6515 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6516 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6517 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
6518 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6519
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6520 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
6521 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
6522 @deftypefn {} {} mldivide (@var{x}, @var{y})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6523 Return the matrix left division of @var{x} and @var{y}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6524
29117
10a35049bad7 doc: Cleanup Texinfo macros use in documentation.
Rik <rik@octave.org>
parents: 29086
diff changeset
6525 This function and @w{@tcode{@var{x} @backslashchar{} @var{y}}} 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
6526
290eff7148bb mrdivide, mldivide: Document that functions might return minimum norm solutions (bug #60839).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29817
diff changeset
6527 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
6528 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
6529 @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
6530 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6531 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6532 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
6533 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6534
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6535 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
6536 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
6537 @deftypefn {} {} lt (@var{x}, @var{y})
24618
c99163d188df doc: Use @var{} around variables in operator functions such as and, or, uplus.
Rik <rik@octave.org>
parents: 24517
diff changeset
6538 This function is equivalent to @w{@code{@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
6539 @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
6540 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6541 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6542 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
6543 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6544
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6545 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
6546 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
6547 @deftypefn {} {} le (@var{x}, @var{y})
24618
c99163d188df doc: Use @var{} around variables in operator functions such as and, or, uplus.
Rik <rik@octave.org>
parents: 24517
diff changeset
6548 This function is equivalent to @w{@code{@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
6549 @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
6550 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6551 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6552 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
6553 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6554
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6555 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
6556 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
6557 @deftypefn {} {} eq (@var{x}, @var{y})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6558 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
6559
24618
c99163d188df doc: Use @var{} around variables in operator functions such as and, or, uplus.
Rik <rik@octave.org>
parents: 24517
diff changeset
6560 This function is equivalent to @w{@code{@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
6561 @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
6562 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6563 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6564 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
6565 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6566
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6567 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
6568 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
6569 @deftypefn {} {} ge (@var{x}, @var{y})
24618
c99163d188df doc: Use @var{} around variables in operator functions such as and, or, uplus.
Rik <rik@octave.org>
parents: 24517
diff changeset
6570 This function is equivalent to @w{@code{@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
6571 @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
6572 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6573 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6574 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
6575 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6576
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6577 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
6578 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
6579 @deftypefn {} {} gt (@var{x}, @var{y})
24618
c99163d188df doc: Use @var{} around variables in operator functions such as and, or, uplus.
Rik <rik@octave.org>
parents: 24517
diff changeset
6580 This function is equivalent to @w{@code{@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
6581 @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
6582 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6583 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6584 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
6585 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6586
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6587 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
6588 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
6589 @deftypefn {} {} ne (@var{x}, @var{y})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6590 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
6591
24618
c99163d188df doc: Use @var{} around variables in operator functions such as and, or, uplus.
Rik <rik@octave.org>
parents: 24517
diff changeset
6592 This function is equivalent to @w{@code{@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
6593 @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
6594 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6595 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6596 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
6597 }
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 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
6600 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
6601 @deftypefn {} {} times (@var{x}, @var{y})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6602 @deftypefnx {} {} times (@var{x1}, @var{x2}, @dots{})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6603 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
6604
24618
c99163d188df doc: Use @var{} around variables in operator functions such as and, or, uplus.
Rik <rik@octave.org>
parents: 24517
diff changeset
6605 This function and @w{@tcode{@var{x} .* @var{y}}} 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
6606 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
6607 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
6608
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6609 @example
24618
c99163d188df doc: Use @var{} around variables in operator functions such as and, or, uplus.
Rik <rik@octave.org>
parents: 24517
diff changeset
6610 (@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
6611 @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
6612
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6613 @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
6614 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6615 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6616 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
6617 octave_value::op_el_mul_eq, args);
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6618 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6619
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6620 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
6621 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
6622 @deftypefn {} {} rdivide (@var{x}, @var{y})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6623 Return the element-by-element right division of @var{x} and @var{y}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6624
24618
c99163d188df doc: Use @var{} around variables in operator functions such as and, or, uplus.
Rik <rik@octave.org>
parents: 24517
diff changeset
6625 This function and @w{@tcode{@var{x} ./ @var{y}}} 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
6626 @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
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_el_div, 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 (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
6633 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
6634 @deftypefn {} {} power (@var{x}, @var{y})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6635 Return the element-by-element operation of @var{x} raised to the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6636 @var{y} power.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6637
24618
c99163d188df doc: Use @var{} around variables in operator functions such as and, or, uplus.
Rik <rik@octave.org>
parents: 24517
diff changeset
6638 This function and @w{@tcode{@var{x} .^ @var{y}}} 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
6639
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6640 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
6641 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
6642 @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
6643
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6644 @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
6645 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6646 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6647 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
6648 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6649
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6650 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
6651 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
6652 @deftypefn {} {} ldivide (@var{x}, @var{y})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6653 Return the element-by-element left division of @var{x} and @var{y}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6654
29117
10a35049bad7 doc: Cleanup Texinfo macros use in documentation.
Rik <rik@octave.org>
parents: 29086
diff changeset
6655 This function and @w{@tcode{@var{x} .@backslashchar{} @var{y}}} are
24618
c99163d188df doc: Use @var{} around variables in operator functions such as and, or, uplus.
Rik <rik@octave.org>
parents: 24517
diff changeset
6656 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
6657 @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
6658 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6659 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6660 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
6661 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6662
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6663 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
6664 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
6665 @deftypefn {} {@var{z} =} and (@var{x}, @var{y})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6666 @deftypefnx {} {@var{z} =} and (@var{x1}, @var{x2}, @dots{})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6667 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
6668
24618
c99163d188df doc: Use @var{} around variables in operator functions such as and, or, uplus.
Rik <rik@octave.org>
parents: 24517
diff changeset
6669 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
6670 @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
6671 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
6672
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6673 @example
24618
c99163d188df doc: Use @var{} around variables in operator functions such as and, or, uplus.
Rik <rik@octave.org>
parents: 24517
diff changeset
6674 (@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
6675 @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
6676
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6677 @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
6678 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6679 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6680 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
6681 octave_value::op_el_and_eq, args);
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6682 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6683
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6684 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
6685 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
6686 @deftypefn {} {@var{z} =} or (@var{x}, @var{y})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6687 @deftypefnx {} {@var{z} =} or (@var{x1}, @var{x2}, @dots{})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6688 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
6689
24618
c99163d188df doc: Use @var{} around variables in operator functions such as and, or, uplus.
Rik <rik@octave.org>
parents: 24517
diff changeset
6690 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
6691 @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
6692 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
6693
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6694 @example
24618
c99163d188df doc: Use @var{} around variables in operator functions such as and, or, uplus.
Rik <rik@octave.org>
parents: 24517
diff changeset
6695 (@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
6696 @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
6697
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6698 @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
6699 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6700 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6701 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
6702 octave_value::op_el_or_eq, args);
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6703 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6704
19749
c913247c85a8 make colon function work (bug #44290)
John W. Eaton <jwe@octave.org>
parents: 19743
diff changeset
6705 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
6706 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
6707 @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
6708 @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
6709 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
6710 @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
6711
24618
c99163d188df doc: Use @var{} around variables in operator functions such as and, or, uplus.
Rik <rik@octave.org>
parents: 24517
diff changeset
6712 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
6713 @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
6714 @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
6715 @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
6716 @end deftypefn */)
19749
c913247c85a8 make colon function work (bug #44290)
John W. Eaton <jwe@octave.org>
parents: 19743
diff changeset
6717 {
c913247c85a8 make colon function work (bug #44290)
John W. Eaton <jwe@octave.org>
parents: 19743
diff changeset
6718 int nargin = args.length ();
c913247c85a8 make colon function work (bug #44290)
John W. Eaton <jwe@octave.org>
parents: 19743
diff changeset
6719
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6720 if (nargin < 2 || nargin > 3)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6721 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6722
28631
70cdf8de553d move non-member octave_value operator functions to octave namespace
John W. Eaton <jwe@octave.org>
parents: 28115
diff changeset
6723 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
6724 ? 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
6725 : 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
6726 }
c913247c85a8 make colon function work (bug #44290)
John W. Eaton <jwe@octave.org>
parents: 19743
diff changeset
6727
7065
97db94ae2cf0 [project @ 2007-10-25 05:50:55 by jwe]
jwe
parents: 7045
diff changeset
6728 static double tic_toc_timestamp = -1.0;
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6729
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6730 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
6731 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
6732 @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
6733 @deftypefnx {} {@var{id} =} tic ()
25017
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6734 Initialize a wall-clock timer.
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6735
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6736 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
6737 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
6738 set.
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6739
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6740 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
6741 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
6742 @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
6743 timer, rather than the default internal timer.
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6744
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6745 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
6746
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6747 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6748 @group
25017
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6749 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
6750 # many computations later@dots{}
25017
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6751 elapsed_time = toc;
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6752 @end group
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6753 @end example
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6754
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6755 Example 2 : mixed timer id and internal timer
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6756
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6757 @example
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6758 @group
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6759 tic;
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6760 pause (1);
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6761 toc
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6762 @result{} Elapsed time is 1.0089 seconds.
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6763 id = tic;
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6764 pause (2);
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6765 toc (id)
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6766 @result{} Elapsed time is 2.01142 seconds.
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6767 toc
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6768 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
6769 @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
6770 @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
6771
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6772 @noindent
25017
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6773 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
6774
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6775 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
6776 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
6777 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
6778 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
6779 @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
6780 @end deftypefn */)
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6781 {
20819
f428cbe7576f eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents: 20816
diff changeset
6782 if (args.length () != 0)
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6783 warning ("tic: ignoring extra arguments");
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6784
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6785 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
6786 sys::time now;
7065
97db94ae2cf0 [project @ 2007-10-25 05:50:55 by jwe]
jwe
parents: 7045
diff changeset
6787 double tmp = now.double_value ();
97db94ae2cf0 [project @ 2007-10-25 05:50:55 by jwe]
jwe
parents: 7045
diff changeset
6788
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6789 if (nargout > 0)
14635
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
6790 {
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
6791 double ip = 0.0;
23639
b488e958d024 Use modf, pow from C++ std library.
Rik <rik@octave.org>
parents: 23625
diff changeset
6792 double frac = std::modf (tmp, &ip);
14635
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
6793 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
6794 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
6795 retval = octave_uint64 (microsecs);
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
6796 }
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6797 else
7065
97db94ae2cf0 [project @ 2007-10-25 05:50:55 by jwe]
jwe
parents: 7045
diff changeset
6798 tic_toc_timestamp = tmp;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
6799
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6800 return retval;
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6801 }
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6802
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6803 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
6804 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
6805 @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
6806 @deftypefnx {} {} toc (@var{id})
25017
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6807 @deftypefnx {} {@var{elapsed_time} =} toc (@dots{})
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6808 Measure elapsed time on a wall-clock timer.
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6809
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6810 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
6811 since the last call to @code{tic}.
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6812
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6813 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
6814 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
6815
30377
26f2daafa270 doc: Use consistent styling for @ref, @xref, @pxref statements.
Rik <rik@octave.org>
parents: 30329
diff changeset
6816 @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
6817
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6818 @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
6819 @end deftypefn */)
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6820 {
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6821 int nargin = args.length ();
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6822
14635
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
6823 if (nargin > 1)
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
6824 print_usage ();
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6825
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6826 double start_time = tic_toc_timestamp;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6827
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6828 if (nargin == 1)
7065
97db94ae2cf0 [project @ 2007-10-25 05:50:55 by jwe]
jwe
parents: 7045
diff changeset
6829 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6830 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
6831
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6832 uint64_t val = id.value ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6833
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6834 start_time
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6835 = (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
6836 + 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
6837 / CLOCKS_PER_SEC);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6838
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6839 // 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
6840 // 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
6841 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
6842
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6843 if (start_time < 0)
28919
7bc983bc2cbd maint: Prepend name of function to error() messages.
Rik <rik@octave.org>
parents: 28915
diff changeset
6844 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
6845
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
6846 sys::time now;
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6847
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6848 double etime = now.double_value () - start_time;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6849
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6850 octave_value retval;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6851 if (nargout > 0)
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6852 retval = etime;
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6853 else
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6854 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
6855
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6856 return retval;
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6857 }
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6858
14635
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
6859 /*
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
6860 %!shared id
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
6861 %! id = tic ();
14849
f6d3d5b0bd42 test: Use Octave coding conventions for tests for line() and toc().
Rik <octave@nomad.inbox5.com>
parents: 14846
diff changeset
6862 %!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
6863 %!assert (isa (toc (id), "double"))
14635
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
6864 */
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
6865
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6866 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
6867 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
6868 @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
6869 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
6870
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6871 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
6872 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
6873 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
6874 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
6875
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6876 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
6877 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
6878
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6879 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
6880 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
6881 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
6882 @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
6883 @end deftypefn */)
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6884 {
21078
49852ff04747 maint: Remove unnecessary declarations of retval.
Rik <rik@octave.org>
parents: 21062
diff changeset
6885 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
6886 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
6887
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
6888 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
6889
f0c5dd1ea2b9 hide sys/time.h, sys/times.h, and sys/resource.h headers
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
6890 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
6891 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
6892
f0c5dd1ea2b9 hide sys/time.h, sys/times.h, and sys/resource.h headers
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
6893 return ovl (usr + sys, usr, sys);
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6894 }
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6895
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6896 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
6897 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
6898 @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
6899 @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
6900 @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
6901 @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
6902 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
6903
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6904 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
6905
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6906 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
6907
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6908 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6909 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6910 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
6911 @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
6912 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
6913 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
6914 @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
6915 @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
6916
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6917 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
6918 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
6919 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
6920 @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
6921
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6922 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
6923 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
6924 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
6925
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6926 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6927 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6928 [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
6929 @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
6930 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
6931 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
6932 @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
6933 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
6934 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
6935 @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
6936 @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
6937
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6938 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
6939 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
6940
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6941 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
6942 (@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
6943 (@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
6944
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6945 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6946 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6947 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
6948 @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
6949 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
6950 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
6951 @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
6952 @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
6953
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6954 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
6955 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
6956
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6957 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
6958 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
6959 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
6960
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6961 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
6962 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
6963 @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
6964 @end deftypefn */)
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6965 {
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6966 int nargin = args.length ();
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6967
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6968 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
6969 print_usage ();
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6970
20884
f1b2a2dbc0e1 2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents: 20853
diff changeset
6971 sortmode smode = ASCENDING;
f1b2a2dbc0e1 2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents: 20853
diff changeset
6972 bool return_idx = (nargout > 1);
20921
4d3daf7e43f3 eliminate trailing whitespace in source files
John W. Eaton <jwe@octave.org>
parents: 20918
diff changeset
6973 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
6974 octave_value arg = args(0);
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6975
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6976 int dim = 0;
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6977 if (nargin > 1)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6978 {
20884
f1b2a2dbc0e1 2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents: 20853
diff changeset
6979 if (have_sortmode)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
6980 {
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
6981 std::string mode = args(1).string_value ();
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
6982 if (mode == "ascend")
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
6983 smode = ASCENDING;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
6984 else if (mode == "descend")
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
6985 smode = DESCENDING;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
6986 else
23803
90689bdbe048 Use C++11 raw string literals to avoid escaping double quotes.
Rik <rik@octave.org>
parents: 23748
diff changeset
6987 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
6988 }
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6989 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
6990 dim = args(1).nint_value () - 1;
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6991 }
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6992
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6993 if (nargin > 2)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6994 {
20884
f1b2a2dbc0e1 2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents: 20853
diff changeset
6995 if (have_sortmode)
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6996 error ("sort: DIM must be a valid dimension");
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6997
20700
68e3a747ca02 rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents: 20652
diff changeset
6998 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
6999
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7000 if (mode == "ascend")
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
7001 smode = ASCENDING;
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7002 else if (mode == "descend")
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
7003 smode = DESCENDING;
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7004 else
23803
90689bdbe048 Use C++11 raw string literals to avoid escaping double quotes.
Rik <rik@octave.org>
parents: 23748
diff changeset
7005 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
7006 }
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7007
10285
22a7913bbeb5 optimize return values of find and sort
Jaroslav Hajek <highegg@gmail.com>
parents: 10277
diff changeset
7008 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
7009 if (nargin == 1 || have_sortmode)
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7010 {
10285
22a7913bbeb5 optimize return values of find and sort
Jaroslav Hajek <highegg@gmail.com>
parents: 10277
diff changeset
7011 dim = dv.first_non_singleton ();
7433
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 else
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7014 {
10703
5eb420d92307 fix sort and nth_element when trailing singleton dim is specified
Jaroslav Hajek <highegg@gmail.com>
parents: 10695
diff changeset
7015 if (dim < 0)
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7016 error ("sort: DIM must be a valid dimension");
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7017 }
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7018
20884
f1b2a2dbc0e1 2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents: 20853
diff changeset
7019 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
7020
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7021 if (return_idx)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7022 {
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7023 Array<octave_idx_type> sidx;
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7024
20884
f1b2a2dbc0e1 2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents: 20853
diff changeset
7025 // 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
7026 // 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
7027 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
7028 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
7029 }
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7030 else
20884
f1b2a2dbc0e1 2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents: 20853
diff changeset
7031 retval = ovl (arg.sort (dim, smode));
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7032
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7033 return retval;
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7034 }
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7035
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7036 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7037 ## Double
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7038 %!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
7039 %!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
7040 %!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
7041 %!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
7042 %!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
7043 %!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
7044 %!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
7045 %!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
7046 %!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
7047 %!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
7048 %!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
7049 %!assert (sort (1), 1)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7050
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7051 %!test
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7052 %! [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
7053 %! 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
7054 %! 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
7055
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7056 ## Complex
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7057 %!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
7058 %!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
7059 %!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
7060 %!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
7061 %!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
7062 %!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
7063 %!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
7064 %!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
7065 %!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
7066 %!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
7067 %!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
7068 %!assert (sort (1i), 1i)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7069
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7070 %!test
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7071 %! [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
7072 %! 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
7073 %! 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
7074
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7075 ## Single
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7076 %!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
7077 %!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
7078 %! 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
7079 %!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
7080 %! 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
7081 %!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
7082 %! 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
7083 %!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
7084 %! 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
7085 %!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
7086 %! 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
7087 %!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
7088 %! 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
7089 %!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
7090 %! 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
7091 %!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
7092 %! 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
7093 %!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
7094 %! 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
7095 %!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
7096 %! 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
7097 %!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
7098
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
7099 %!test
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7100 %! [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
7101 %! 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
7102 %! 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
7103
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7104 ## Single Complex
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7105 %!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
7106 %!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
7107 %! 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
7108 %!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
7109 %! 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
7110 %!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
7111 %! 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
7112 %!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
7113 %! 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
7114 %!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
7115 %! 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
7116 %!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
7117 %! 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
7118 %!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
7119 %! 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
7120 %!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
7121 %! 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
7122 %!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
7123 %! 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
7124 %!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
7125 %! 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
7126 %!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
7127
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
7128 %!test
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7129 %! [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
7130 %! 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
7131 %! 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
7132
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7133 ## Bool
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7134 %!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
7135 %!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
7136 %!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
7137 %!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
7138 %!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
7139 %! [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
7140 %!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
7141 %! [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
7142 %!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
7143 %! [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
7144 %!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
7145 %! [true, true, false, false])
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7146 %!assert (sort (true), true)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7147
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7148 %!test
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7149 %! [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
7150 %! 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
7151 %! 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
7152
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7153 ## Sparse Double
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7154 %!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
7155 %! 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
7156 %!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
7157 %! 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
7158 %!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
7159 %! 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
7160 %!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
7161 %! 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
7162 %!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
7163 %! 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
7164 %!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
7165 %! 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
7166 %!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
7167 %! 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
7168 %!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
7169 %! sparse ([NaN, Inf, 2, 1, 0, 0, -1]))
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7170
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7171 %!shared a
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7172 %! a = randn (10, 10);
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7173 %! a(a < 0) = 0;
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7174 %!assert (sort (sparse (a)), sparse (sort (a)))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7175 %!assert (sort (sparse (a), 1), sparse (sort (a, 1)))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7176 %!assert (sort (sparse (a), 2), sparse (sort (a, 2)))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7177 %!test
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7178 %! [v, i] = sort (a);
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7179 %! [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
7180 %! assert (vs, sparse (v));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7181 %! assert (is, i);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7182
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7183 ## Sparse Complex
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7184 %!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
7185 %! 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
7186 %!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
7187 %! 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
7188 %!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
7189 %! 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
7190 %!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
7191 %! 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
7192 %!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
7193 %! 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
7194 %!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
7195 %! 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
7196 %!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
7197 %! 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
7198 %!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
7199 %! sparse ([NaN, Inf, 2, -1, 1i, 0, 0]))
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7200
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7201 %!shared a
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
7202 %! a = randn (10, 10);
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7203 %! a(a < 0) = 0;
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7204 %! a = 1i * a;
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7205 %!assert (sort (sparse (a)), sparse (sort (a)))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7206 %!assert (sort (sparse (a), 1), sparse (sort (a, 1)))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7207 %!assert (sort (sparse (a), 2), sparse (sort (a, 2)))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7208 %!test
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7209 %! [v, i] = sort (a);
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7210 %! [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
7211 %! assert (vs, sparse (v));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7212 %! assert (is, i);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7213
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7214 ## Sparse Bool
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7215 %!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
7216 %! 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
7217 %!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
7218 %! 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
7219 %!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
7220 %! 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
7221 %!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
7222 %! 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
7223 %!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
7224 %! 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
7225 %!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
7226 %! 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
7227 %!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
7228 %! 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
7229 %!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
7230 %! sparse ([true, true, false, false]))
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7231
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7232 %!test
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7233 %! [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
7234 %! 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
7235 %! 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
7236
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7237 ## Cell string array
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7238 %!shared a, b, c
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7239 %! a = {"Alice", "Cecile", "Eric", "Barry", "David"};
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7240 %! b = {"Alice", "Barry", "Cecile", "David", "Eric"};
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7241 %! 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
7242 %!assert (sort (a), b)
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7243 %!assert (sort (a, 1), a)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7244 %!assert (sort (a, 2), b)
10707
69c5f5ec55d7 fix invalid sort tests
Jaroslav Hajek <highegg@gmail.com>
parents: 10703
diff changeset
7245 %!assert (sort (a, 3), a)
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7246 %!assert (sort (a, "ascend"), b)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7247 %!assert (sort (a, 2, "ascend"), b)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7248 %!assert (sort (a, "descend"), c)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7249 %!assert (sort (a, 2, "descend"), c)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7250
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7251 %!test
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7252 %! [v, i] = sort (a);
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7253 %! 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
7254
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7255 %!error sort ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7256 %!error sort (1, 2, 3, 4)
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7257 */
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7258
8812
7d48766c21a5 use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents: 8799
diff changeset
7259 // Sort the rows of the matrix @var{a} according to the order
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 15428
diff changeset
7260 // specified by @var{mode}, which can either be 'ascend' or 'descend'
8812
7d48766c21a5 use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents: 8799
diff changeset
7261 // and return the index vector corresponding to the sort order.
7d48766c21a5 use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents: 8799
diff changeset
7262 //
7d48766c21a5 use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents: 8799
diff changeset
7263 // This function does not yet support sparse matrices.
7d48766c21a5 use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents: 8799
diff changeset
7264
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7265 // FIXME: Is this function used anymore? 12/14/2015
8733
3ef774603887 rename all uses of sortrows_idx to sort_rows_idx
John W. Eaton <jwe@octave.org>
parents: 8721
diff changeset
7266 DEFUN (__sort_rows_idx__, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7267 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
7268 @deftypefn {} {} __sort_rows_idx__ (@var{a}, @var{mode})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7269 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
7270 @end deftypefn */)
8721
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
7271 {
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
7272 int nargin = args.length ();
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
7273
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7274 if (nargin < 1 || nargin > 2)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7275 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7276
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7277 if (nargin == 2 && ! args(1).is_string ())
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7278 error ("__sort_rows_idx__: second argument must be a string");
8721
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
7279
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
7280 sortmode smode = ASCENDING;
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
7281 if (nargin > 1)
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
7282 {
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
7283 std::string mode = args(1).string_value ();
8721
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
7284 if (mode == "ascend")
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
7285 smode = ASCENDING;
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
7286 else if (mode == "descend")
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
7287 smode = DESCENDING;
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
7288 else
23803
90689bdbe048 Use C++11 raw string literals to avoid escaping double quotes.
Rik <rik@octave.org>
parents: 23748
diff changeset
7289 error (R"(__sort_rows_idx__: MODE must be either "ascend" or "descend")");
8721
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
7290 }
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
7291
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
7292 octave_value arg = args(0);
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
7293
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
7294 if (arg.issparse ())
8733
3ef774603887 rename all uses of sortrows_idx to sort_rows_idx
John W. Eaton <jwe@octave.org>
parents: 8721
diff changeset
7295 error ("__sort_rows_idx__: sparse matrices not yet supported");
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7296
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7297 if (arg.ndims () != 2)
21014
b9d4c3615e89 maint: Capitalize D for dimension in messages and comments.
Rik <rik@octave.org>
parents: 20980
diff changeset
7298 error ("__sort_rows_idx__: needs a 2-D object");
8721
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
7299
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7300 Array<octave_idx_type> idx = arg.sort_rows_idx (smode);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7301
21127
df7891224709 maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents: 21121
diff changeset
7302 // This cannot be ovl(), relies on special overloaded octave_value call.
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7303 return octave_value (idx, true, true);
8721
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
7304 }
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
7305
9765
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7306 static sortmode
20720
7c21b151b8b4 build: Fix warning messages from compiler.
Rik <rik@octave.org>
parents: 20711
diff changeset
7307 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
7308 {
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
7309 // 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
7310 // about possibly using sortmode uninitialized.
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
7311 // 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
7312 sortmode smode = UNSORTED;
9765
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7313
20711
7b608fadc663 Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents: 20704
diff changeset
7314 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
7315
25484
b7db401e1a99 Use "ascend"/"descend" for issorted direction (bug #54147).
Rik <rik@octave.org>
parents: 25473
diff changeset
7316 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
7317 smode = ASCENDING;
25484
b7db401e1a99 Use "ascend"/"descend" for issorted direction (bug #54147).
Rik <rik@octave.org>
parents: 25473
diff changeset
7318 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
7319 smode = DESCENDING;
ba2b07c13913 use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents: 20574
diff changeset
7320 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
7321 smode = UNSORTED;
9765
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7322 else
25484
b7db401e1a99 Use "ascend"/"descend" for issorted direction (bug #54147).
Rik <rik@octave.org>
parents: 25473
diff changeset
7323 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
7324
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7325 return smode;
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7326 }
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7327
8721
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
7328 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
7329 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
7330 @deftypefn {} {@var{tf} =} issorted (@var{a})
841a10208c38 doc: Use TF for output variable in documentation for isXXX functions in libinterp/ directory.
Rik <rik@octave.org>
parents: 30402
diff changeset
7331 @deftypefnx {} {@var{tf} =} issorted (@var{a}, @var{mode})
841a10208c38 doc: Use TF for output variable in documentation for isXXX functions in libinterp/ directory.
Rik <rik@octave.org>
parents: 30402
diff changeset
7332 @deftypefnx {} {@var{tf} =} issorted (@var{a}, "rows", @var{mode})
27034
df32e0cf0992 doc: Fix names of options in issorted (bug #56087).
Rik <rik@octave.org>
parents: 26376
diff changeset
7333 Return true if the array is sorted according to @var{mode}, which may be either
df32e0cf0992 doc: Fix names of options in issorted (bug #56087).
Rik <rik@octave.org>
parents: 26376
diff changeset
7334 @qcode{"ascend"}, @qcode{"descend"}, or @qcode{"either"}.
df32e0cf0992 doc: Fix names of options in issorted (bug #56087).
Rik <rik@octave.org>
parents: 26376
diff changeset
7335
df32e0cf0992 doc: Fix names of options in issorted (bug #56087).
Rik <rik@octave.org>
parents: 26376
diff changeset
7336 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
7337 manner as @code{sort}.
df32e0cf0992 doc: Fix names of options in issorted (bug #56087).
Rik <rik@octave.org>
parents: 26376
diff changeset
7338
df32e0cf0992 doc: Fix names of options in issorted (bug #56087).
Rik <rik@octave.org>
parents: 26376
diff changeset
7339 If the optional argument @qcode{"rows"} is supplied, check whether the array is
df32e0cf0992 doc: Fix names of options in issorted (bug #56087).
Rik <rik@octave.org>
parents: 26376
diff changeset
7340 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
7341
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7342 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
7343 @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
7344 @end deftypefn */)
8721
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
7345 {
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
7346 int nargin = args.length ();
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
7347
9765
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7348 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
7349 print_usage ();
9765
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7350
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7351 bool by_rows = false;
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7352
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7353 sortmode smode = ASCENDING;
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7354
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7355 if (nargin > 1)
8721
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
7356 {
9765
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7357 if (nargin == 3)
20720
7c21b151b8b4 build: Fix warning messages from compiler.
Rik <rik@octave.org>
parents: 20711
diff changeset
7358 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
7359
20700
68e3a747ca02 rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents: 20652
diff changeset
7360 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
7361 if (tmp == "rows")
ba2b07c13913 use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents: 20574
diff changeset
7362 by_rows = true;
9765
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7363 else
20720
7c21b151b8b4 build: Fix warning messages from compiler.
Rik <rik@octave.org>
parents: 20711
diff changeset
7364 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
7365 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
7366
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7367 octave_value retval;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7368
9765
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7369 octave_value arg = args(0);
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7370
25850
153495e05477 issorted: return true on an empty array (bug #54599)
Mike Miller <mtmiller@octave.org>
parents: 25646
diff changeset
7371 if (arg.isempty ())
153495e05477 issorted: return true on an empty array (bug #54599)
Mike Miller <mtmiller@octave.org>
parents: 25646
diff changeset
7372 retval = true;
153495e05477 issorted: return true on an empty array (bug #54599)
Mike Miller <mtmiller@octave.org>
parents: 25646
diff changeset
7373 else if (by_rows)
9765
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7374 {
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
7375 if (arg.issparse ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
7376 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
7377
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7378 if (arg.ndims () != 2)
21014
b9d4c3615e89 maint: Capitalize D for dimension in messages and comments.
Rik <rik@octave.org>
parents: 20980
diff changeset
7379 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
7380
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7381 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
7382 }
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7383 else
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7384 {
23592
80e3bfb7bd5a maint: Deprecate is_vector and replace with isvector.
Rik <rik@octave.org>
parents: 23588
diff changeset
7385 if (! arg.dims ().isvector ())
8721
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
7386 error ("issorted: needs a vector");
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7387
23588
0549061d35b9 maint: Deprecate is_sorted and replace with issorted.
Rik <rik@octave.org>
parents: 23587
diff changeset
7388 retval = args(0).issorted (smode) != UNSORTED;
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
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
7391 return retval;
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
7392 }
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
7393
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 %!shared sm, um, sv, uv
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7396 %! sm = [1, 2; 3, 4];
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7397 %! um = [3, 1; 2, 4];
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7398 %! sv = [1, 2, 3, 4];
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7399 %! uv = [2, 1, 4, 3];
20809
9e9892519a7c Add more BIST tests for issorted.
Rik <rik@octave.org>
parents: 20806
diff changeset
7400
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7401 %!assert (issorted (sm, "rows"))
20809
9e9892519a7c Add more BIST tests for issorted.
Rik <rik@octave.org>
parents: 20806
diff changeset
7402 %!assert (! issorted (um, "rows"))
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7403 %!assert (issorted (sv))
20809
9e9892519a7c Add more BIST tests for issorted.
Rik <rik@octave.org>
parents: 20806
diff changeset
7404 %!assert (! issorted (uv))
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7405 %!assert (issorted (sv'))
20809
9e9892519a7c Add more BIST tests for issorted.
Rik <rik@octave.org>
parents: 20806
diff changeset
7406 %!assert (! issorted (uv'))
25484
b7db401e1a99 Use "ascend"/"descend" for issorted direction (bug #54147).
Rik <rik@octave.org>
parents: 25473
diff changeset
7407 %!assert (issorted (sm, "rows", "ascend"))
b7db401e1a99 Use "ascend"/"descend" for issorted direction (bug #54147).
Rik <rik@octave.org>
parents: 25473
diff changeset
7408 %!assert (! issorted (um, "rows", "ascend"))
b7db401e1a99 Use "ascend"/"descend" for issorted direction (bug #54147).
Rik <rik@octave.org>
parents: 25473
diff changeset
7409 %!assert (issorted (sv, "ascend"))
b7db401e1a99 Use "ascend"/"descend" for issorted direction (bug #54147).
Rik <rik@octave.org>
parents: 25473
diff changeset
7410 %!assert (! issorted (uv, "ascend"))
b7db401e1a99 Use "ascend"/"descend" for issorted direction (bug #54147).
Rik <rik@octave.org>
parents: 25473
diff changeset
7411 %!assert (issorted (sv', "ascend"))
b7db401e1a99 Use "ascend"/"descend" for issorted direction (bug #54147).
Rik <rik@octave.org>
parents: 25473
diff changeset
7412 %!assert (! issorted (uv', "ascend"))
b7db401e1a99 Use "ascend"/"descend" for issorted direction (bug #54147).
Rik <rik@octave.org>
parents: 25473
diff changeset
7413 %!assert (! issorted (sm, "rows", "descend"))
b7db401e1a99 Use "ascend"/"descend" for issorted direction (bug #54147).
Rik <rik@octave.org>
parents: 25473
diff changeset
7414 %!assert (issorted (flipud (sm), "rows", "descend"))
b7db401e1a99 Use "ascend"/"descend" for issorted direction (bug #54147).
Rik <rik@octave.org>
parents: 25473
diff changeset
7415 %!assert (! issorted (sv, "descend"))
b7db401e1a99 Use "ascend"/"descend" for issorted direction (bug #54147).
Rik <rik@octave.org>
parents: 25473
diff changeset
7416 %!assert (issorted (fliplr (sv), "descend"))
b7db401e1a99 Use "ascend"/"descend" for issorted direction (bug #54147).
Rik <rik@octave.org>
parents: 25473
diff changeset
7417 %!assert (! issorted (sv', "descend"))
b7db401e1a99 Use "ascend"/"descend" for issorted direction (bug #54147).
Rik <rik@octave.org>
parents: 25473
diff changeset
7418 %!assert (issorted (fliplr (sv)', "descend"))
20809
9e9892519a7c Add more BIST tests for issorted.
Rik <rik@octave.org>
parents: 20806
diff changeset
7419 %!assert (! issorted (um, "rows", "either"))
9e9892519a7c Add more BIST tests for issorted.
Rik <rik@octave.org>
parents: 20806
diff changeset
7420 %!assert (! issorted (uv, "either"))
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7421 %!assert (issorted (sm, "rows", "either"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7422 %!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
7423 %!assert (issorted (sv, "either"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7424 %!assert (issorted (fliplr (sv), "either"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7425 %!assert (issorted (sv', "either"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7426 %!assert (issorted (fliplr (sv)', "either"))
20809
9e9892519a7c Add more BIST tests for issorted.
Rik <rik@octave.org>
parents: 20806
diff changeset
7427
25850
153495e05477 issorted: return true on an empty array (bug #54599)
Mike Miller <mtmiller@octave.org>
parents: 25646
diff changeset
7428 %!assert (issorted ([]))
153495e05477 issorted: return true on an empty array (bug #54599)
Mike Miller <mtmiller@octave.org>
parents: 25646
diff changeset
7429 %!assert (issorted ([], "rows"))
153495e05477 issorted: return true on an empty array (bug #54599)
Mike Miller <mtmiller@octave.org>
parents: 25646
diff changeset
7430 %!assert (issorted ([], "ascend"))
153495e05477 issorted: return true on an empty array (bug #54599)
Mike Miller <mtmiller@octave.org>
parents: 25646
diff changeset
7431 %!assert (issorted ([], "rows", "ascend"))
153495e05477 issorted: return true on an empty array (bug #54599)
Mike Miller <mtmiller@octave.org>
parents: 25646
diff changeset
7432 %!assert (issorted ([], "descend"))
153495e05477 issorted: return true on an empty array (bug #54599)
Mike Miller <mtmiller@octave.org>
parents: 25646
diff changeset
7433 %!assert (issorted ([], "rows", "descend"))
153495e05477 issorted: return true on an empty array (bug #54599)
Mike Miller <mtmiller@octave.org>
parents: 25646
diff changeset
7434 %!assert (issorted ({}))
153495e05477 issorted: return true on an empty array (bug #54599)
Mike Miller <mtmiller@octave.org>
parents: 25646
diff changeset
7435 %!assert (issorted ({}, "rows"))
153495e05477 issorted: return true on an empty array (bug #54599)
Mike Miller <mtmiller@octave.org>
parents: 25646
diff changeset
7436 %!assert (issorted ({}, "ascend"))
153495e05477 issorted: return true on an empty array (bug #54599)
Mike Miller <mtmiller@octave.org>
parents: 25646
diff changeset
7437 %!assert (issorted ({}, "rows", "ascend"))
153495e05477 issorted: return true on an empty array (bug #54599)
Mike Miller <mtmiller@octave.org>
parents: 25646
diff changeset
7438 %!assert (issorted ({}, "descend"))
153495e05477 issorted: return true on an empty array (bug #54599)
Mike Miller <mtmiller@octave.org>
parents: 25646
diff changeset
7439 %!assert (issorted ({}, "rows", "descend"))
153495e05477 issorted: return true on an empty array (bug #54599)
Mike Miller <mtmiller@octave.org>
parents: 25646
diff changeset
7440 %!assert (issorted (""))
153495e05477 issorted: return true on an empty array (bug #54599)
Mike Miller <mtmiller@octave.org>
parents: 25646
diff changeset
7441 %!assert (issorted ("", "rows"))
153495e05477 issorted: return true on an empty array (bug #54599)
Mike Miller <mtmiller@octave.org>
parents: 25646
diff changeset
7442 %!assert (issorted ("", "ascend"))
153495e05477 issorted: return true on an empty array (bug #54599)
Mike Miller <mtmiller@octave.org>
parents: 25646
diff changeset
7443 %!assert (issorted ("", "rows", "ascend"))
153495e05477 issorted: return true on an empty array (bug #54599)
Mike Miller <mtmiller@octave.org>
parents: 25646
diff changeset
7444 %!assert (issorted ("", "descend"))
153495e05477 issorted: return true on an empty array (bug #54599)
Mike Miller <mtmiller@octave.org>
parents: 25646
diff changeset
7445 %!assert (issorted ("", "rows", "descend"))
20809
9e9892519a7c Add more BIST tests for issorted.
Rik <rik@octave.org>
parents: 20806
diff changeset
7446
9e9892519a7c Add more BIST tests for issorted.
Rik <rik@octave.org>
parents: 20806
diff changeset
7447 ## 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
7448 %!error issorted ()
f1b2a2dbc0e1 2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents: 20853
diff changeset
7449 %!error issorted (1,2,3,4)
20809
9e9892519a7c Add more BIST tests for issorted.
Rik <rik@octave.org>
parents: 20806
diff changeset
7450 %!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
7451 %!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
7452 %!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
7453 %!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
7454 %!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
7455 */
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7456
9725
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7457 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
7458 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
7459 @deftypefn {} {} nth_element (@var{x}, @var{n})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7460 @deftypefnx {} {} nth_element (@var{x}, @var{n}, @var{dim})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7461 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
7462 @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
7463
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7464 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
7465
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7466 @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
7467 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
7468
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7469 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
7470 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
7471 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
7472
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7473 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
7474 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
7475 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
7476 @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
7477 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
7478 @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
7479 @end deftypefn */)
9725
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7480 {
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7481 int nargin = args.length ();
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7482
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7483 if (nargin < 2 || nargin > 3)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7484 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7485
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7486 int dim = -1;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7487 if (nargin == 3)
9725
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7488 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7489 dim = args(2).int_value (true) - 1;
9725
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7490 if (dim < 0)
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7491 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
7492 }
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7493
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7494 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
7495 if (dim < 0)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7496 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
7497
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7498 octave_value retval;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7499
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7500 try
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7501 {
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
7502 idx_vector n = args(1).index_vector ();
9725
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7503
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7504 switch (argx.builtin_type ())
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7505 {
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7506 case btyp_double:
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7507 retval = argx.array_value ().nth_element (n, dim);
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7508 break;
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7509 case btyp_float:
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7510 retval = argx.float_array_value ().nth_element (n, dim);
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7511 break;
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7512 case btyp_complex:
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7513 retval = argx.complex_array_value ().nth_element (n, dim);
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7514 break;
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7515 case btyp_float_complex:
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7516 retval = argx.float_complex_array_value ().nth_element (n, dim);
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7517 break;
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
7518
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
7519 #define MAKE_INT_BRANCH(X) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
7520 case btyp_ ## X: \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
7521 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
7522 break;
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7523
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7524 MAKE_INT_BRANCH (int8);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7525 MAKE_INT_BRANCH (int16);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7526 MAKE_INT_BRANCH (int32);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7527 MAKE_INT_BRANCH (int64);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7528 MAKE_INT_BRANCH (uint8);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7529 MAKE_INT_BRANCH (uint16);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7530 MAKE_INT_BRANCH (uint32);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7531 MAKE_INT_BRANCH (uint64);
21540
ffb4770ba079 Make median preserve discrete types (bug #47515).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21458
diff changeset
7532 MAKE_INT_BRANCH (bool);
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
7533
9725
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7534 #undef MAKE_INT_BRANCH
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
7535
9725
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7536 default:
23575
e95738a119da maint: Deprecate is_cellstr and replace with iscellstr.
Rik <rik@octave.org>
parents: 23573
diff changeset
7537 if (argx.iscellstr ())
9725
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7538 retval = argx.cellstr_value ().nth_element (n, dim);
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7539 else
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21078
diff changeset
7540 err_wrong_type_arg ("nth_element", argx);
9725
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7541 }
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7542 }
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
7543 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
7544 {
8f67ad8b3103 maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents: 29117
diff changeset
7545 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
7546 }
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 return retval;
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
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
7551 /*
3e93a2a66cdf nth_element: allow sequence of indices to be passed as a vector (bug #51329)
Brad Kennedy <bk@co60.ca>
parents: 23693
diff changeset
7552 %!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
7553 %!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
7554 %!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
7555 %!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
7556
3e93a2a66cdf nth_element: allow sequence of indices to be passed as a vector (bug #51329)
Brad Kennedy <bk@co60.ca>
parents: 23693
diff changeset
7557 %!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
7558
3e93a2a66cdf nth_element: allow sequence of indices to be passed as a vector (bug #51329)
Brad Kennedy <bk@co60.ca>
parents: 23693
diff changeset
7559 %!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
7560 %!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
7561 %!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
7562 %!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
7563 %!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
7564 */
3e93a2a66cdf nth_element: allow sequence of indices to be passed as a vector (bug #51329)
Brad Kennedy <bk@co60.ca>
parents: 23693
diff changeset
7565
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
7566 template <typename NDT>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
7567 static NDT
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
7568 do_accumarray_sum (const idx_vector& idx, const NDT& vals,
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7569 octave_idx_type n = -1)
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7570 {
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7571 typedef typename NDT::element_type T;
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7572 if (n < 0)
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7573 n = idx.extent (0);
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7574 else if (idx.extent (n) > n)
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7575 error ("accumarray: index out of range");
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7576
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
7577 NDT retval (dim_vector (n, 1), T ());
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7578
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7579 if (vals.numel () == 1)
9858
47c5af1868df move idx_add methods to MArrayN
Jaroslav Hajek <highegg@gmail.com>
parents: 9856
diff changeset
7580 retval.idx_add (idx, vals (0));
47c5af1868df move idx_add methods to MArrayN
Jaroslav Hajek <highegg@gmail.com>
parents: 9856
diff changeset
7581 else if (vals.numel () == idx.length (n))
47c5af1868df move idx_add methods to MArrayN
Jaroslav Hajek <highegg@gmail.com>
parents: 9856
diff changeset
7582 retval.idx_add (idx, vals);
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7583 else
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7584 error ("accumarray: dimensions mismatch");
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7585
9858
47c5af1868df move idx_add methods to MArrayN
Jaroslav Hajek <highegg@gmail.com>
parents: 9856
diff changeset
7586 return retval;
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7587 }
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7588
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7589 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
7590 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
7591 @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
7592 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
7593 @end deftypefn */)
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7594 {
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7595 int nargin = args.length ();
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7596
22789
bedfedcd878e norm: fix error in input argument validation leading to segfault (bug #49634)
Mike Miller <mtmiller@octave.org>
parents: 22749
diff changeset
7597 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
7598 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7599
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23585
diff changeset
7600 if (! args(0).isnumeric ())
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7601 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
7602
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7603 octave_value retval;
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7604
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7605 try
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7606 {
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
7607 idx_vector idx = args(0).index_vector ();
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7608 octave_idx_type n = -1;
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7609 if (nargin == 3)
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7610 n = args(2).idx_type_value (true);
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7611
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7612 octave_value vals = args(1);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7613
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7614 if (vals.is_range ())
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7615 {
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
7616 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
7617 if (r.increment () == 0)
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7618 vals = r.base ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7619 }
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7620
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7621 if (vals.is_single_type ())
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7622 {
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
7623 if (vals.iscomplex ())
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7624 retval = do_accumarray_sum (idx,
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7625 vals.float_complex_array_value (),
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7626 n);
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7627 else
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7628 retval = do_accumarray_sum (idx, vals.float_array_value (), n);
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7629 }
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23585
diff changeset
7630 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
7631 {
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
7632 if (vals.iscomplex ())
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7633 retval = do_accumarray_sum (idx,
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7634 vals.complex_array_value (),
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7635 n);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7636 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7637 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
7638 }
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7639 else
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21078
diff changeset
7640 err_wrong_type_arg ("accumarray", vals);
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7641 }
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
7642 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
7643 {
8f67ad8b3103 maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents: 29117
diff changeset
7644 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
7645 }
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7646
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
7647 return retval;
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7648 }
8721
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
7649
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
7650 template <typename NDT>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
7651 static NDT
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
7652 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
7653 octave_idx_type n, bool ismin,
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7654 const typename NDT::element_type& zero_val)
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7655 {
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7656 typedef typename NDT::element_type T;
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7657 if (n < 0)
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7658 n = idx.extent (0);
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7659 else if (idx.extent (n) > n)
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7660 error ("accumarray: index out of range");
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7661
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7662 NDT retval (dim_vector (n, 1), zero_val);
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7663
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7664 // 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
7665 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
7666 = ismin ? (&MArray<T>::idx_min) : (&MArray<T>::idx_max);
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7667
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7668 octave_idx_type l = idx.length (n);
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7669 if (vals.numel () == 1)
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7670 (retval.*op) (idx, NDT (dim_vector (l, 1), vals(0)));
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7671 else if (vals.numel () == l)
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7672 (retval.*op) (idx, vals);
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7673 else
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7674 error ("accumarray: dimensions mismatch");
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7675
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7676 return retval;
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7677 }
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7678
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7679 static octave_value_list
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7680 do_accumarray_minmax_fun (const octave_value_list& args,
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7681 bool ismin)
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7682 {
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7683 int nargin = args.length ();
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7684
22789
bedfedcd878e norm: fix error in input argument validation leading to segfault (bug #49634)
Mike Miller <mtmiller@octave.org>
parents: 22749
diff changeset
7685 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
7686 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7687
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23585
diff changeset
7688 if (! args(0).isnumeric ())
20811
5979314bb15a Fix BIST tests for rows.
Rik <rik@octave.org>
parents: 20810
diff changeset
7689 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
7690
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7691 octave_value retval;
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7692
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7693 try
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7694 {
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
7695 idx_vector idx = args(0).index_vector ();
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7696 octave_idx_type n = -1;
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7697 if (nargin == 4)
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7698 n = args(3).idx_type_value (true);
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7699
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7700 octave_value vals = args(1);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7701 octave_value zero = args(2);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7702
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7703 switch (vals.builtin_type ())
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7704 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7705 case btyp_double:
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7706 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
7707 zero.double_value ());
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7708 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7709
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7710 case btyp_float:
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7711 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
7712 ismin, zero.float_value ());
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7713 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7714
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7715 case btyp_complex:
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7716 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
7717 n, ismin, zero.complex_value ());
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7718 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7719
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7720 case btyp_float_complex:
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7721 retval = do_accumarray_minmax (idx,
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7722 vals.float_complex_array_value (),
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7723 n, ismin,
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7724 zero.float_complex_value ());
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7725 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7726
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
7727 #define MAKE_INT_BRANCH(X) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
7728 case btyp_ ## X: \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
7729 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
7730 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
7731 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7732
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7733 MAKE_INT_BRANCH (int8);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7734 MAKE_INT_BRANCH (int16);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7735 MAKE_INT_BRANCH (int32);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7736 MAKE_INT_BRANCH (int64);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7737 MAKE_INT_BRANCH (uint8);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7738 MAKE_INT_BRANCH (uint16);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7739 MAKE_INT_BRANCH (uint32);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7740 MAKE_INT_BRANCH (uint64);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7741
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7742 #undef MAKE_INT_BRANCH
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7743
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7744 case btyp_bool:
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7745 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
7746 zero.bool_value ());
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7747 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7748
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7749 default:
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21078
diff changeset
7750 err_wrong_type_arg ("accumarray", vals);
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7751 }
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7752 }
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
7753 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
7754 {
8f67ad8b3103 maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents: 29117
diff changeset
7755 error ("do_accumarray_minmax_fun: 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
7756 }
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7757
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
7758 return retval;
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7759 }
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7760
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7761 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
7762 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
7763 @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
7764 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
7765 @end deftypefn */)
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7766 {
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7767 return do_accumarray_minmax_fun (args, true);
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7768 }
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7769
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7770 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
7771 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
7772 @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
7773 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
7774 @end deftypefn */)
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7775 {
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7776 return do_accumarray_minmax_fun (args, false);
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7777 }
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7778
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
7779 template <typename NDT>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
7780 static NDT
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
7781 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
7782 int dim = -1, octave_idx_type n = -1)
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7783 {
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7784 typedef typename NDT::element_type T;
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7785 if (n < 0)
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7786 n = idx.extent (0);
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7787 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
7788 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
7789
18100
6a71e5030df5 Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents: 17915
diff changeset
7790 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
7791 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
7792
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7793 if (dim < 0)
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7794 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
7795 else if (dim >= rdv.ndims ())
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7796 rdv.resize (dim+1, 1);
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7797
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7798 rdv(dim) = n;
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7799
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
7800 NDT retval (rdv, T ());
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7801
14113
dac62c415e8b Do more error checking on accumarray and accumdim input.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14100
diff changeset
7802 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
7803 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
7804
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7805 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
7806
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7807 return retval;
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7808 }
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7809
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7810 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
7811 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
7812 @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
7813 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
7814 @end deftypefn */)
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7815 {
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7816 int nargin = args.length ();
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7817
22789
bedfedcd878e norm: fix error in input argument validation leading to segfault (bug #49634)
Mike Miller <mtmiller@octave.org>
parents: 22749
diff changeset
7818 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
7819 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7820
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23585
diff changeset
7821 if (! args(0).isnumeric ())
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7822 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
7823
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7824 octave_value retval;
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7825
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7826 try
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7827 {
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
7828 idx_vector idx = args(0).index_vector ();
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7829 int dim = -1;
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7830 if (nargin >= 3)
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7831 dim = args(2).int_value () - 1;
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7832
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7833 octave_idx_type n = -1;
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7834 if (nargin == 4)
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7835 n = args(3).idx_type_value (true);
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7836
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7837 octave_value vals = args(1);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7838
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7839 if (vals.is_single_type ())
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7840 {
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
7841 if (vals.iscomplex ())
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7842 retval = do_accumdim_sum (idx,
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7843 vals.float_complex_array_value (),
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7844 dim, n);
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7845 else
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7846 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
7847 dim, n);
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7848 }
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23585
diff changeset
7849 else if (vals.isnumeric () || vals.islogical ())
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7850 {
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
7851 if (vals.iscomplex ())
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7852 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
7853 dim, n);
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7854 else
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7855 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
7856 }
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7857 else
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21078
diff changeset
7858 err_wrong_type_arg ("accumdim", vals);
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7859 }
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
7860 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
7861 {
8f67ad8b3103 maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents: 29117
diff changeset
7862 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
7863 }
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7864
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
7865 return retval;
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7866 }
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7867
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
7868 template <typename NDT>
9473
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7869 static NDT
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7870 do_merge (const Array<bool>& mask,
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7871 const NDT& tval, const NDT& fval)
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7872 {
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7873 typedef typename NDT::element_type T;
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7874 dim_vector dv = mask.dims ();
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7875 NDT retval (dv);
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7876
18100
6a71e5030df5 Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents: 17915
diff changeset
7877 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
7878 bool fscl = fval.numel () == 1;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
7879
21055
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7880 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
7881 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
7882
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7883 T *rv = retval.fortran_vec ();
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7884 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
7885
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7886 const T *tv = tval.data ();
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7887 const T *fv = fval.data ();
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7888 const bool *mv = mask.data ();
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7889
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7890 if (tscl)
9473
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7891 {
21055
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7892 if (fscl)
9473
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7893 {
21055
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7894 T ts = tv[0];
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7895 T fs = fv[0];
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7896 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
7897 rv[i] = (mv[i] ? ts : fs);
9473
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7898 }
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7899 else
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7900 {
21055
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7901 T ts = tv[0];
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7902 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
7903 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
7904 }
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7905 }
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7906 else
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7907 {
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7908 if (fscl)
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7909 {
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7910 T fs = fv[0];
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7911 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
7912 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
7913 }
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7914 else
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7915 {
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7916 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
7917 rv[i] = (mv[i] ? tv[i] : fv[i]);
9473
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7918 }
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7919 }
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7920
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7921 return retval;
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7922 }
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7923
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
7924 #define MAKE_INT_BRANCH(INTX) \
9473
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7925 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
7926 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
7927 retval = do_merge (mask, \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
7928 tval.INTX ## _array_value (), \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
7929 fval.INTX ## _array_value ()); \
9473
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7930 }
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7931
9505
a321a1c227c8 make ifelse an alias or merge
Jaroslav Hajek <highegg@gmail.com>
parents: 9475
diff changeset
7932 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
7933 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
7934 @deftypefn {} {} merge (@var{mask}, @var{tval}, @var{fval})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7935 @deftypefnx {} {} ifelse (@var{mask}, @var{tval}, @var{fval})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7936 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
7937 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
7938
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7939 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
7940 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
7941 @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
7942 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
7943 @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
7944
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7945 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
7946 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
7947 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
7948
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7949 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7950 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7951 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
7952 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
7953 @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
7954 @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
7955
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7956 @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
7957 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
7958 @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
7959 @end deftypefn */)
9473
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7960 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7961 if (args.length () != 3)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7962 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7963
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23585
diff changeset
7964 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
7965 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
7966
9473
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7967 octave_value retval;
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7968
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7969 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
7970
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7971 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
7972 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
7973 else
9473
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7974 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7975 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
7976
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7977 octave_value tval = args(1);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7978 octave_value fval = args(2);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7979
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7980 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
7981 {
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
7982 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
7983 retval = do_merge (mask,
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7984 tval.complex_array_value (),
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7985 fval.complex_array_value ());
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7986 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7987 retval = do_merge (mask,
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7988 tval.array_value (),
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7989 fval.array_value ());
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7990 }
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7991 else if (tval.is_single_type () && fval.is_single_type ())
9473
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7992 {
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
7993 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
7994 retval = do_merge (mask,
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7995 tval.float_complex_array_value (),
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7996 fval.float_complex_array_value ());
9473
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7997 else
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7998 retval = do_merge (mask,
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7999 tval.float_array_value (),
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8000 fval.float_array_value ());
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8001 }
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8002 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
8003 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8004 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
8005 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
8006 tval.char_array_value (),
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8007 fval.char_array_value ()),
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8008 sq_string ? '\'' : '"');
9473
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
8009 }
23576
00e518162fda maint: Deprecate is_cell and replace with iscell.
Rik <rik@octave.org>
parents: 23575
diff changeset
8010 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
8011 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8012 retval = do_merge (mask,
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8013 tval.cell_value (),
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8014 fval.cell_value ());
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8015 }
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8016
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
8017 MAKE_INT_BRANCH (int8)
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
8018 MAKE_INT_BRANCH (int16)
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
8019 MAKE_INT_BRANCH (int32)
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
8020 MAKE_INT_BRANCH (int64)
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
8021 MAKE_INT_BRANCH (uint8)
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
8022 MAKE_INT_BRANCH (uint16)
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
8023 MAKE_INT_BRANCH (uint32)
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
8024 MAKE_INT_BRANCH (uint64)
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8025
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8026 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8027 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
8028 tval.class_name ().c_str (),
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8029 fval.class_name ().c_str ());
9473
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
8030 }
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
8031
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
8032 return retval;
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
8033 }
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
8034
9505
a321a1c227c8 make ifelse an alias or merge
Jaroslav Hajek <highegg@gmail.com>
parents: 9475
diff changeset
8035 DEFALIAS (ifelse, merge);
a321a1c227c8 make ifelse an alias or merge
Jaroslav Hajek <highegg@gmail.com>
parents: 9475
diff changeset
8036
9473
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
8037 #undef MAKE_INT_BRANCH
8721
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
8038
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
8039 template <typename SparseT>
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8040 static SparseT
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8041 do_sparse_diff (const SparseT& array, octave_idx_type order,
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8042 int dim)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8043 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8044 SparseT retval = array;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8045 if (dim == 1)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8046 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8047 octave_idx_type k = retval.columns ();
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8048 while (order > 0 && k > 0)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8049 {
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
8050 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
8051 retval = SparseT (retval.index (col1, sl1))
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
8052 - SparseT (retval.index (col2, sl2));
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8053 assert (retval.columns () == k-1);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8054 order--;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8055 k--;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8056 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8057 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8058 else
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8059 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8060 octave_idx_type k = retval.rows ();
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8061 while (order > 0 && k > 0)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8062 {
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
8063 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
8064 retval = SparseT (retval.index (sl1, col1))
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
8065 - SparseT (retval.index (sl2, col2));
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8066 assert (retval.rows () == k-1);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8067 order--;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8068 k--;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8069 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8070 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8071
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8072 return retval;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8073 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8074
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8075 static octave_value
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8076 do_diff (const octave_value& array, octave_idx_type order,
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8077 int dim = -1)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8078 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8079 octave_value retval;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8080
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8081 const dim_vector& dv = array.dims ();
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8082 if (dim == -1)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8083 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8084 dim = array.dims ().first_non_singleton ();
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8085
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21730
diff changeset
8086 // Bother Matlab. This behavior is really wicked.
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8087 if (dv(dim) <= order)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8088 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8089 if (dv(dim) == 1)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8090 retval = array.resize (dim_vector (0, 0));
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8091 else
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8092 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8093 retval = array;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8094 while (order > 0)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8095 {
21660
53728df3e4c9 maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents: 21602
diff changeset
8096 if (dim == dv.ndims ())
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8097 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8098 retval = do_diff (array, order, dim - 1);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8099 order = 0;
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 else if (dv(dim) == 1)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8102 dim++;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8103 else
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8104 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8105 retval = do_diff (array, dv(dim) - 1, dim);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8106 order -= dv(dim) - 1;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8107 dim++;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8108 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8109 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8110 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8111
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8112 return retval;
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
23580
2230f9e10fb3 maint: Deprecate is_integer_type and replace with isinteger.
Rik <rik@octave.org>
parents: 23579
diff changeset
8116 if (array.isinteger ())
9513
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 if (array.is_int8_type ())
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8119 retval = array.int8_array_value ().diff (order, dim);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8120 else if (array.is_int16_type ())
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8121 retval = array.int16_array_value ().diff (order, dim);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8122 else if (array.is_int32_type ())
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8123 retval = array.int32_array_value ().diff (order, dim);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8124 else if (array.is_int64_type ())
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8125 retval = array.int64_array_value ().diff (order, dim);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8126 else if (array.is_uint8_type ())
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8127 retval = array.uint8_array_value ().diff (order, dim);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8128 else if (array.is_uint16_type ())
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8129 retval = array.uint16_array_value ().diff (order, dim);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8130 else if (array.is_uint32_type ())
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8131 retval = array.uint32_array_value ().diff (order, dim);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8132 else if (array.is_uint64_type ())
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8133 retval = array.uint64_array_value ().diff (order, dim);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8134 else
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8135 panic_impossible ();
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8136 }
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
8137 else if (array.issparse ())
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8138 {
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
8139 if (array.iscomplex ())
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
8140 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
8141 order, dim);
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8142 else
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8143 retval = do_sparse_diff (array.sparse_matrix_value (), order, dim);
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 (array.is_single_type ())
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8146 {
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
8147 if (array.iscomplex ())
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8148 retval = array.float_complex_array_value ().diff (order, dim);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8149 else
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8150 retval = array.float_array_value ().diff (order, dim);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8151 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8152 else
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8153 {
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
8154 if (array.iscomplex ())
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8155 retval = array.complex_array_value ().diff (order, dim);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8156 else
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8157 retval = array.array_value ().diff (order, dim);
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
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8160 return retval;
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
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8163 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
8164 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
8165 @deftypefn {} {} diff (@var{x})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
8166 @deftypefnx {} {} diff (@var{x}, @var{k})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
8167 @deftypefnx {} {} diff (@var{x}, @var{k}, @var{dim})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
8168 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
8169 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
8170 @tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
8171 $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
8172 @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
8173 @ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
8174 @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
8175 @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
8176
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
8177 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
8178 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
8179
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
8180 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
8181 @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
8182 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
8183 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
8184 @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
8185 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
8186
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
8187 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
8188 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
8189 @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
8190 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
8191 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
8192 @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
8193 @end deftypefn */)
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8194 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8195 int nargin = args.length ();
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8196
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8197 if (nargin < 1 || nargin > 3)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8198 print_usage ();
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8199
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23585
diff changeset
8200 if (! (args(0).isnumeric () || args(0).islogical ()))
10880
92c3e8068f28 allow diff(logical)
Jaroslav Hajek <highegg@gmail.com>
parents: 10846
diff changeset
8201 error ("diff: X must be numeric or logical");
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8202
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
8203 int dim = -1;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
8204 octave_idx_type order = 1;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
8205 if (nargin > 1)
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8206 {
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
8207 if (args(1).is_scalar_type ())
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
8208 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
8209 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
8210 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
8211 if (order < 0)
20726
25d676f9619c Preface error() messages with name of function when possible.
Rik <rik@octave.org>
parents: 20720
diff changeset
8212 error ("diff: order K must be non-negative");
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8213 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8214
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
8215 if (nargin > 2)
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
8216 {
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
8217 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
8218 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
8219 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
8220
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
8221 dim -= 1;
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
8222 }
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
8223
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8224 return do_diff (args(0), order, dim);
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8225 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8226
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8227 /*
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8228 %!assert (diff ([1, 2, 3, 4]), [1, 1, 1])
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8229 %!assert (diff ([1, 3, 7, 19], 2), [2, 8])
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8230 %!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
8231 %!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
8232 %!assert (isempty (diff (1)))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
8233
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
8234 %!error diff ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
8235 %!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
8236 %!error diff ("foo")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
8237 %!error diff ([1, 2; 3, 4], -1)
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8238 */
10799
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8239
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
8240 template <typename T>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
8241 static Array<T>
10799
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8242 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
8243 {
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8244 Array<T> retval;
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8245
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8246 assert (rep.ndims () == 2 && rep.rows () == 2);
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8247
18100
6a71e5030df5 Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents: 17915
diff changeset
8248 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
8249 octave_idx_type l = 0;
10799
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8250 for (octave_idx_type i = 0; i < n; i++)
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8251 {
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8252 octave_idx_type k = rep(1, i);
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8253 if (k < 0)
20893
384ff5aa9437 2015 Code Sprint: Eliminate useless return statements after error ().
Rik <rik@octave.org>
parents: 20884
diff changeset
8254 error ("repelems: second row must contain non-negative numbers");
10799
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8255
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8256 l += k;
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8257 }
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8258
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8259 retval.clear (1, l);
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8260 T *dest = retval.fortran_vec ();
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8261 l = 0;
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8262 for (octave_idx_type i = 0; i < n; i++)
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8263 {
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8264 octave_idx_type k = rep(1, i);
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8265 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
8266 dest += k;
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8267 }
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8268
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8269 return retval;
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8270 }
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8271
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8272 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
8273 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
8274 @deftypefn {} {} repelems (@var{x}, @var{r})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
8275 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
8276
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
8277 @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
8278 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
8279 @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
8280 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
8281 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
8282 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
8283 returned.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
8284
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
8285 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
8286
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
8287 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
8288 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
8289 y = [];
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
8290 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
8291 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
8292 endfor
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
8293 @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
8294 @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
8295 @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
8296 @end deftypefn */)
10799
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8297 {
20850
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8298 if (args.length () != 2)
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8299 print_usage ();
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8300
10799
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8301 octave_value retval;
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8302
20850
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8303 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
8304
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8305 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
8306 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
8307
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8308 octave_value x = args(0);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8309
27666
3e8faed1b7d8 Remove wrapper template class NoAlias<T> (bug #56752)
Carlo de Falco <carlo.defalco@polimi.it>
parents: 27568
diff changeset
8310 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
8311
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8312 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
8313 {
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8314 octave_idx_type rx = rm(i);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8315 if (static_cast<double> (rx) != rm(i))
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8316 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
8317
27666
3e8faed1b7d8 Remove wrapper template class NoAlias<T> (bug #56752)
Carlo de Falco <carlo.defalco@polimi.it>
parents: 27568
diff changeset
8318 r.xelem (i) = rx;
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8319 }
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8320
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8321 switch (x.builtin_type ())
10799
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8322 {
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
8323 #define BTYP_BRANCH(X, EX) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
8324 case btyp_ ## X: \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
8325 retval = do_repelems (x.EX ## _value (), r); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
8326 break;
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8327
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8328 BTYP_BRANCH (double, array);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8329 BTYP_BRANCH (float, float_array);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8330 BTYP_BRANCH (complex, complex_array);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8331 BTYP_BRANCH (float_complex, float_complex_array);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8332 BTYP_BRANCH (bool, bool_array);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8333 BTYP_BRANCH (char, char_array);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8334
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8335 BTYP_BRANCH (int8, int8_array);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8336 BTYP_BRANCH (int16, int16_array);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8337 BTYP_BRANCH (int32, int32_array);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8338 BTYP_BRANCH (int64, int64_array);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8339 BTYP_BRANCH (uint8, uint8_array);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8340 BTYP_BRANCH (uint16, uint16_array);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8341 BTYP_BRANCH (uint32, uint32_array);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8342 BTYP_BRANCH (uint64, uint64_array);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8343
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8344 BTYP_BRANCH (cell, cell);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8345 //BTYP_BRANCH (struct, map);//FIXME
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
8346
10799
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8347 #undef BTYP_BRANCH
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8348
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8349 default:
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21078
diff changeset
8350 err_wrong_type_arg ("repelems", x);
10799
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8351 }
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8352
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8353 return retval;
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8354 }
15050
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
8355
15252
fa0118cb67d9 move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents: 15213
diff changeset
8356 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
8357 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
8358 @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
8359 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
8360 @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
8361
28769
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8362 @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
8363 @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
8364 {
20819
f428cbe7576f eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents: 20816
diff changeset
8365 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
8366 print_usage ();
20850
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8367
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23585
diff changeset
8368 if (! args(0).isnumeric ())
20850
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8369 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
8370
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
8371 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
8372 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
8373
15050
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
8374 octave_value_list retval;
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8375
23580
2230f9e10fb3 maint: Deprecate is_integer_type and replace with isinteger.
Rik <rik@octave.org>
parents: 23579
diff changeset
8376 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
8377 {
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
8378 #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
8379 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
8380 { \
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
8381 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
8382 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
8383 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
8384 char *out; \
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
8385 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
8386 { \
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
8387 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
8388 ::free (out); \
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
8389 } \
15111
5dd599df36de generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15094
diff changeset
8390 }
20850
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8391
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8392 MAKE_INT_BRANCH(int8)
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8393 else MAKE_INT_BRANCH(int16)
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8394 else MAKE_INT_BRANCH(int32)
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8395 else MAKE_INT_BRANCH(int64)
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8396 else MAKE_INT_BRANCH(uint8)
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8397 else MAKE_INT_BRANCH(uint16)
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8398 else MAKE_INT_BRANCH(uint32)
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8399 else MAKE_INT_BRANCH(uint64)
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
8400
20850
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8401 #undef MAKE_INT_BRANCH
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8402
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8403 else
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8404 panic_impossible ();
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8405 }
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8406 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
8407 {
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8408 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
8409 std::size_t inlen;
20850
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8410 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
8411 const char *inc;
23447
db1fdf4384dd maint: Use convention "static_cast<void *>" for casting of pointers.
Rik <rik@octave.org>
parents: 23289
diff changeset
8412 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
8413 char *out;
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
8414 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
8415 {
20850
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8416 retval(0) = octave_value (out);
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8417 ::free (out);
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
8418 }
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
8419 }
20850
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8420 else // double_type
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8421 {
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8422 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
8423 std::size_t inlen;
20850
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8424 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
8425 const char *inc;
23447
db1fdf4384dd maint: Use convention "static_cast<void *>" for casting of pointers.
Rik <rik@octave.org>
parents: 23289
diff changeset
8426 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
8427 char *out;
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
8428 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
8429 {
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8430 retval(0) = octave_value (out);
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8431 ::free (out);
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8432 }
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8433 }
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8434
15052
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
8435 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
8436 }
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
8437
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
8438 /*
21458
348e335c49dd Fix failing BIST tests on big-endian systems
Mike Miller <mtmiller@octave.org>
parents: 21405
diff changeset
8439 %!test
348e335c49dd Fix failing BIST tests on big-endian systems
Mike Miller <mtmiller@octave.org>
parents: 21405
diff changeset
8440 %! ## FIXME: better test for endianness?
348e335c49dd Fix failing BIST tests on big-endian systems
Mike Miller <mtmiller@octave.org>
parents: 21405
diff changeset
8441 %! if (bitunpack (uint16 (1))(1) == 1)
348e335c49dd Fix failing BIST tests on big-endian systems
Mike Miller <mtmiller@octave.org>
parents: 21405
diff changeset
8442 %! expected = "2w9JQA==";
348e335c49dd Fix failing BIST tests on big-endian systems
Mike Miller <mtmiller@octave.org>
parents: 21405
diff changeset
8443 %! else
348e335c49dd Fix failing BIST tests on big-endian systems
Mike Miller <mtmiller@octave.org>
parents: 21405
diff changeset
8444 %! expected = "QEkP2w==";
348e335c49dd Fix failing BIST tests on big-endian systems
Mike Miller <mtmiller@octave.org>
parents: 21405
diff changeset
8445 %! endif
348e335c49dd Fix failing BIST tests on big-endian systems
Mike Miller <mtmiller@octave.org>
parents: 21405
diff changeset
8446 %! assert (base64_encode (single (pi)), expected);
348e335c49dd Fix failing BIST tests on big-endian systems
Mike Miller <mtmiller@octave.org>
parents: 21405
diff changeset
8447
15111
5dd599df36de generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15094
diff changeset
8448 %!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
8449 %!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
8450 %!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
8451 %!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
8452 %!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
8453
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
8454 %!error base64_encode ()
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
8455 %!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
8456 %!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
8457 %!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
8458 %!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
8459 */
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
8460
15252
fa0118cb67d9 move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents: 15213
diff changeset
8461 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
8462 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
8463 @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
8464 @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
8465 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
8466 @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
8467
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
8468 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
8469 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
8470 @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
8471 @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
8472 {
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
8473 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
8474
15050
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
8475 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
8476 print_usage ();
20850
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 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
8479
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
8480 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
8481
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8482 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
8483 {
15252
fa0118cb67d9 move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents: 15213
diff changeset
8484 dim_vector dims;
15052
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
8485
27277
db687716fed6 style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents: 27081
diff changeset
8486 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
8487 = 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
8488
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8489 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
8490 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
8491 dims(i) = size(i);
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8492
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8493 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
8494 }
15052
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
8495
21127
df7891224709 maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents: 21121
diff changeset
8496 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
8497 }
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
8498
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
8499 /*
15052
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
8500 %!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
8501 %!
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
8502 %!test
15052
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
8503 %! in = randn (10);
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
8504 %! 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
8505 %! 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
8506 %! assert (outv, in(:).');
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
8507 %! assert (outm, in);
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
8508
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
8509 %!error base64_decode ()
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
8510 %!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
8511 %!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
8512 %!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
8513 %!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
8514 %!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
8515 */
28769
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8516
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8517 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
8518 doc: /* -*- texinfo -*-
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8519 @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
8520 @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
8521 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
8522 @var{s}.
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8523
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8524 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
8525 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
8526 @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
8527 @end deftypefn */)
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8528 {
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8529 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
8530
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8531 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
8532 print_usage ();
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8533
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8534 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
8535
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
8536 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
8537
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8538 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
8539 {
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8540 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
8541
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8542 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
8543 = 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
8544
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8545 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
8546 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
8547 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
8548
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8549 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
8550 }
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8551
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8552 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
8553 }
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8554
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8555 /*
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8556 %!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
8557
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8558 %!test
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8559 %! 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
8560 %! 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
8561 %! 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
8562 %! 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
8563 %! 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
8564
28888
06c8e0877864 maint: Backed out changeset 09c071328135.
Rik <rik@octave.org>
parents: 28887
diff changeset
8565 %!error __base64_decode_bytes__ ()
06c8e0877864 maint: Backed out changeset 09c071328135.
Rik <rik@octave.org>
parents: 28887
diff changeset
8566 %!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
8567 %!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
8568 %!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
8569 */
29958
32c3a5805893 move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29955
diff changeset
8570
32c3a5805893 move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29955
diff changeset
8571 OCTAVE_NAMESPACE_END