annotate libinterp/corefcn/data.cc @ 32060:1203a2d81a42

Add BIST tests for Matlab compatibility for functions which accept negative dimensions. * data.cc (Fones, Finf, Feps, Feye): Add BIST test for negative dimensions. * rand.cc (Frand): Add BIST test for negative dimensions. * ov-cell.cc (Fcell): Add BIST test for negative dimensions.
author Rik <rik@octave.org>
date Wed, 26 Apr 2023 16:26:32 -0700
parents 39700c1ea93e
children 1de97b475564
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ////////////////////////////////////////////////////////////////////////
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 //
31706
597f3ee61a48 update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 31611
diff changeset
3 // Copyright (C) 1994-2023 The Octave Project Developers
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
4 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 // See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 // distribution or <https://octave.org/copyright/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
7 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
8 // This file is part of Octave.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
9 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
10 // Octave is free software: you can redistribute it and/or modify it
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
11 // under the terms of the GNU General Public License as published by
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
12 // the Free Software Foundation, either version 3 of the License, or
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
13 // (at your option) any later version.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
14 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
15 // Octave is distributed in the hope that it will be useful, but
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
18 // GNU General Public License for more details.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
19 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
20 // You should have received a copy of the GNU General Public License
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
21 // along with Octave; see the file COPYING. If not, see
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
22 // <https://www.gnu.org/licenses/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ////////////////////////////////////////////////////////////////////////
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
25
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21723
diff changeset
26 #if defined (HAVE_CONFIG_H)
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21200
diff changeset
27 # include "config.h"
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
28 #endif
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
29
23625
b0a2367823f5 Use hypot, hypotf from C++ std library.
Rik <rik@octave.org>
parents: 23599
diff changeset
30 #include <cmath>
23455
73ff72d3d603 maint: Eliminate <cfloat.h> header from libinterp files
Rik <rik@octave.org>
parents: 23450
diff changeset
31 #include <cstddef>
73ff72d3d603 maint: Eliminate <cfloat.h> header from libinterp files
Rik <rik@octave.org>
parents: 23450
diff changeset
32 #include <cstdint>
10303
e4899d6320b6 data.cc: use CLOCKS_PER_SEC instead of HZ
John W. Eaton <jwe@octave.org>
parents: 10302
diff changeset
33 #include <ctime>
2184
dbbbb3559ee8 [project @ 1996-05-14 02:18:22 by jwe]
jwe
parents: 2086
diff changeset
34
23455
73ff72d3d603 maint: Eliminate <cfloat.h> header from libinterp files
Rik <rik@octave.org>
parents: 23450
diff changeset
35 #include <algorithm>
73ff72d3d603 maint: Eliminate <cfloat.h> header from libinterp files
Rik <rik@octave.org>
parents: 23450
diff changeset
36 #include <limits>
1728
42b4f904f1af [project @ 1996-01-09 11:36:01 by jwe]
jwe
parents: 1572
diff changeset
37 #include <string>
42b4f904f1af [project @ 1996-01-09 11:36:01 by jwe]
jwe
parents: 1572
diff changeset
38
2184
dbbbb3559ee8 [project @ 1996-05-14 02:18:22 by jwe]
jwe
parents: 2086
diff changeset
39 #include "lo-ieee.h"
23455
73ff72d3d603 maint: Eliminate <cfloat.h> header from libinterp files
Rik <rik@octave.org>
parents: 23450
diff changeset
40 #include "mx-base.h"
15252
fa0118cb67d9 move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents: 15213
diff changeset
41 #include "oct-base64.h"
23455
73ff72d3d603 maint: Eliminate <cfloat.h> header from libinterp files
Rik <rik@octave.org>
parents: 23450
diff changeset
42 #include "oct-binmap.h"
10240
fa7b5751730c use gnulib time, sys_time, and sys_times modules
John W. Eaton <jwe@octave.org>
parents: 10185
diff changeset
43 #include "oct-time.h"
4153
6b96ce9f5743 [project @ 2002-11-06 20:38:49 by jwe]
jwe
parents: 4114
diff changeset
44 #include "quit.h"
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
45
6953
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
46 #include "Cell.h"
23462
314d980bee93 maint: Add '#include "XXX.h"' to XXX.cc files.
Rik <rik@octave.org>
parents: 23455
diff changeset
47 #include "data.h"
1352
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1315
diff changeset
48 #include "defun.h"
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1315
diff changeset
49 #include "error.h"
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21078
diff changeset
50 #include "errwarn.h"
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23592
diff changeset
51 #include "interpreter-private.h"
31730
610a85b0ff62 use interpreter::feval instead of global feval function
John W. Eaton <jwe@octave.org>
parents: 31707
diff changeset
52 #include "interpreter.h"
6953
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
53 #include "oct-map.h"
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
54 #include "ov-class.h"
5476
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
55 #include "ov-complex.h"
23462
314d980bee93 maint: Add '#include "XXX.h"' to XXX.cc files.
Rik <rik@octave.org>
parents: 23455
diff changeset
56 #include "ov-cx-mat.h"
314d980bee93 maint: Add '#include "XXX.h"' to XXX.cc files.
Rik <rik@octave.org>
parents: 23455
diff changeset
57 #include "ov-cx-sparse.h"
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7743
diff changeset
58 #include "ov-float.h"
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7743
diff changeset
59 #include "ov-flt-complex.h"
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7743
diff changeset
60 #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
61 #include "ov.h"
314d980bee93 maint: Add '#include "XXX.h"' to XXX.cc files.
Rik <rik@octave.org>
parents: 23455
diff changeset
62 #include "ovl.h"
314d980bee93 maint: Add '#include "XXX.h"' to XXX.cc files.
Rik <rik@octave.org>
parents: 23455
diff changeset
63 #include "pager.h"
6953
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
64 #include "pt-mat.h"
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
65 #include "utils.h"
6953
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
66 #include "variables.h"
8303
b11c31849b44 improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents: 8286
diff changeset
67 #include "xnorm.h"
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
68
31605
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 31603
diff changeset
69 OCTAVE_BEGIN_NAMESPACE(octave)
29958
32c3a5805893 move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29955
diff changeset
70
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1940
diff changeset
71 DEFUN (all, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
72 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
73 @deftypefn {} {@var{tf} =} all (@var{x})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
74 @deftypefnx {} {@var{tf} =} all (@var{x}, @var{dim})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
75 For a vector argument, return true (logical 1) if all elements of the vector
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
76 are nonzero.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
77
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
78 For a matrix argument, return a row vector of logical ones and zeros with each
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
79 element indicating whether all of the elements of the corresponding column of
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
80 the matrix are nonzero. For example:
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
81
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
82 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
83 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
84 all ([2, 3; 1, 0])
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
85 @result{} [ 1, 0 ]
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
86 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
87 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
88
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
89 If the optional argument @var{dim} is supplied, work along dimension @var{dim}.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
90 @seealso{any}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
91 @end deftypefn */)
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
92 {
20943
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
93 int nargin = args.length ();
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
94
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
95 if (nargin < 1 || nargin > 2)
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
96 print_usage ();
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
97
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
98 int dim = (nargin == 1 ? -1
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
99 : args(1).xint_value ("all: DIM must be an integer")-1);
20943
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
100
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
101 if (dim < -1)
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
102 error ("all: invalid dimension argument = %d", dim + 1);
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
103
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
104 return ovl (args(0).all (dim));
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
105 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
106
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
107 /*
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
108 %!test
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
109 %! x = ones (3);
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
110 %! x(1,1) = 0;
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
111 %! assert (all (all (rand (3) + 1) == [1, 1, 1]) == 1);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
112 %! assert (all (all (x) == [0, 1, 1]) == 1);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
113 %! assert (all (x, 1) == [0, 1, 1]);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
114 %! assert (all (x, 2) == [0; 1; 1]);
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
115
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
116 %!test
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
117 %! x = ones (3, "single");
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
118 %! x(1,1) = 0;
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
119 %! assert (all (all (single (rand (3) + 1)) == [1, 1, 1]) == 1);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
120 %! assert (all (all (x) == [0, 1, 1]) == 1);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
121 %! assert (all (x, 1) == [0, 1, 1]);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
122 %! assert (all (x, 2) == [0; 1; 1]);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
123
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
124 %!error all ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
125 %!error all (1, 2, 3)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
126 */
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
127
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1940
diff changeset
128 DEFUN (any, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
129 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
130 @deftypefn {} {@var{tf} =} any (@var{x})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
131 @deftypefnx {} {@var{tf} =} any (@var{x}, @var{dim})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
132 For a vector argument, return true (logical 1) if any element of the vector
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
133 is nonzero.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
134
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
135 For a matrix argument, return a row vector of logical ones and zeros with each
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
136 element indicating whether any of the elements of the corresponding column of
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
137 the matrix are nonzero. For example:
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
138
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
139 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
140 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
141 any (eye (2, 4))
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
142 @result{} [ 1, 1, 0, 0 ]
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
143 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
144 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
145
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
146 If the optional argument @var{dim} is supplied, work along dimension @var{dim}.
31375
96f751f8392c doc: grammar check documentation ahead of 8.1 release.
Rik <rik@octave.org>
parents: 31369
diff changeset
147 For example:
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
148
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
149 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
150 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
151 any (eye (2, 4), 2)
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
152 @result{} [ 1; 1 ]
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
153 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
154 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
155 @seealso{all}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
156 @end deftypefn */)
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
157 {
20943
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
158 int nargin = args.length ();
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
159
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
160 if (nargin < 1 || nargin > 2)
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
161 print_usage ();
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
162
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
163 int dim = (nargin == 1 ? -1
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
164 : args(1).xint_value ("any: DIM must be an integer")-1);
20943
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
165
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
166 if (dim < -1)
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
167 error ("any: invalid dimension argument = %d", dim + 1);
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
168
42319d289714 maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents: 20940
diff changeset
169 return ovl (args(0).any (dim));
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
170 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
171
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
172 /*
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
173 %!test
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
174 %! x = zeros (3);
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
175 %! x(3,3) = 1;
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
176 %! assert (all (any (x) == [0, 0, 1]) == 1);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
177 %! assert (all (any (ones (3)) == [1, 1, 1]) == 1);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
178 %! assert (any (x, 1) == [0, 0, 1]);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
179 %! assert (any (x, 2) == [0; 0; 1]);
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
180
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
181 %!test
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
182 %! x = zeros (3, "single");
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
183 %! x(3,3) = 1;
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
184 %! assert (all (any (x) == [0, 0, 1]) == 1);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
185 %! assert (all (any (ones (3, "single")) == [1, 1, 1]) == 1);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
186 %! assert (any (x, 1) == [0, 0, 1]);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
187 %! assert (any (x, 2) == [0; 0; 1]);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
188
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
189 %!error any ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
190 %!error any (1, 2, 3)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
191 */
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
192
649
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
193 // These mapping functions may also be useful in other places, eh?
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
194
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1940
diff changeset
195 DEFUN (atan2, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
196 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
197 @deftypefn {} {@var{angle} =} atan2 (@var{y}, @var{x})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
198 Compute atan (@var{y} / @var{x}) for corresponding elements of @var{y} and
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
199 @var{x}.
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
200
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
201 @var{y} and @var{x} must match in size and orientation. The signs of elements
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
202 of @var{y} and @var{x} are used to determine the quadrants of each resulting
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
203 value.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
204
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
205 This function is equivalent to @code{arg (complex (@var{x}, @var{y}))}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
206 @seealso{tan, tand, tanh, atanh}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
207 @end deftypefn */)
649
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
208 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
209 if (args.length () != 2)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
210 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
211
4233
ccfdb55c8156 [project @ 2002-12-20 22:43:54 by jwe]
jwe
parents: 4176
diff changeset
212 octave_value retval;
649
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
213
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23585
diff changeset
214 if (! args(0).isnumeric ())
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21078
diff changeset
215 err_wrong_type_arg ("atan2", args(0));
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
216
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23585
diff changeset
217 if (! args(1).isnumeric ())
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21078
diff changeset
218 err_wrong_type_arg ("atan2", args(1));
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
219
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
220 if (args(0).iscomplex () || args(1).iscomplex ())
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
221 error ("atan2: not defined for complex numbers");
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
222
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
223 if (args(0).is_single_type () || args(1).is_single_type ())
649
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
224 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
225 if (args(0).is_scalar_type () && args(1).is_scalar_type ())
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
226 retval = atan2f (args(0).float_value (), args(1).float_value ());
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
227 else
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents: 10405
diff changeset
228 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
229 FloatNDArray a0 = args(0).float_array_value ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
230 FloatNDArray a1 = args(1).float_array_value ();
24088
0160a3199b2d avoid warnings from GCC about ABI change with exception specifications
John W. Eaton <jwe@octave.org>
parents: 23803
diff changeset
231 retval = binmap<float> (a0, a1, std::atan2, "atan2");
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
232 }
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
233 }
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
234 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
235 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
236 if (args(0).is_scalar_type () && args(1).is_scalar_type ())
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
237 retval = atan2 (args(0).scalar_value (), args(1).scalar_value ());
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
238 else if (args(0).issparse ())
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
239 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
240 SparseMatrix m0 = args(0).sparse_matrix_value ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
241 SparseMatrix m1 = args(1).sparse_matrix_value ();
24088
0160a3199b2d avoid warnings from GCC about ABI change with exception specifications
John W. Eaton <jwe@octave.org>
parents: 23803
diff changeset
242 retval = binmap<double> (m0, m1, std::atan2, "atan2");
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents: 10405
diff changeset
243 }
7494
bd2bd04e68ca Treat integer types for mod/rem correctly
David Bateman <dbateman@free.fr>
parents: 7433
diff changeset
244 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
245 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
246 NDArray a0 = args(0).array_value ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
247 NDArray a1 = args(1).array_value ();
24088
0160a3199b2d avoid warnings from GCC about ABI change with exception specifications
John W. Eaton <jwe@octave.org>
parents: 23803
diff changeset
248 retval = binmap<double> (a0, a1, std::atan2, "atan2");
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
249 }
649
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
250 }
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
251
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
252 return retval;
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
253 }
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
254
7506
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
255 /*
7741
72c0489653ac fix tests
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
256 %!assert (size (atan2 (zeros (0, 2), zeros (0, 2))), [0, 2])
72c0489653ac fix tests
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
257 %!assert (size (atan2 (rand (2, 3, 4), zeros (2, 3, 4))), [2, 3, 4])
72c0489653ac fix tests
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
258 %!assert (size (atan2 (rand (2, 3, 4), 1)), [2, 3, 4])
72c0489653ac fix tests
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
259 %!assert (size (atan2 (1, rand (2, 3, 4))), [2, 3, 4])
72c0489653ac fix tests
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
260 %!assert (size (atan2 (1, 2)), [1, 1])
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
261
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
262 %!test
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
263 %! rt2 = sqrt (2);
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
264 %! rt3 = sqrt (3);
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
265 %! v = [0, pi/6, pi/4, pi/3, -pi/3, -pi/4, -pi/6, 0];
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
266 %! y = [0, rt3, 1, rt3, -rt3, -1, -rt3, 0];
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
267 %! x = [1, 3, 1, 1, 1, 1, 3, 1];
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
268 %! assert (atan2 (y, x), v, sqrt (eps));
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
269
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
270 %!test
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
271 %! rt2 = sqrt (2);
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
272 %! rt3 = sqrt (3);
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
273 %! v = single ([0, pi/6, pi/4, pi/3, -pi/3, -pi/4, -pi/6, 0]);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
274 %! y = single ([0, rt3, 1, rt3, -rt3, -1, -rt3, 0]);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
275 %! x = single ([1, 3, 1, 1, 1, 1, 3, 1]);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
276 %! assert (atan2 (y, x), v, sqrt (eps ("single")));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
277
18789
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
278 ## Test sparse implementations
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
279 %!shared xs
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
280 %! xs = sparse (0:3);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
281 %!test
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
282 %! y = atan2 (1, xs);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
283 %! assert (issparse (y), false);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
284 %! assert (nnz (y), 4);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
285 %! assert (y, atan2 (1, 0:3));
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
286 %!test
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
287 %! y = atan2 (0, xs);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
288 %! assert (issparse (y), false);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
289 %! assert (nnz (y), 0);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
290 %! assert (y, zeros (1,4));
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
291 %!test
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
292 %! y = atan2 (xs, 1);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
293 %! assert (issparse (y));
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
294 %! assert (nnz (y), 3);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
295 %! assert (y, sparse (atan2 (0:3, 1)));
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
296 %!test
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
297 %! y = atan2 (xs, 0);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
298 %! assert (issparse (y));
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
299 %! assert (nnz (y), 3);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
300 %! assert (y, sparse (atan2 (0:3, 0)));
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
301 %!test
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
302 %! y = atan2 (xs, sparse (ones (1, 4)));
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
303 %! assert (issparse (y));
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
304 %! assert (nnz (y), 3);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
305 %! assert (y, sparse (atan2 (0:3, ones (1,4))));
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
306 %!test
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
307 %! y = atan2 (xs, sparse (zeros (1,4)));
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
308 %! assert (issparse (y));
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
309 %! assert (nnz (y), 3);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
310 %! assert (y, sparse (atan2 (0:3, zeros (1,4))));
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
311
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
312 %!error atan2 ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
313 %!error atan2 (1, 2, 3)
7506
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
314 */
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
315
10538
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
316 static octave_value
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
317 do_hypot (const octave_value& x, const octave_value& y)
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
318 {
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
319 octave_value retval;
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
320
18100
6a71e5030df5 Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents: 17915
diff changeset
321 octave_value arg0 = x;
6a71e5030df5 Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents: 17915
diff changeset
322 octave_value arg1 = y;
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23585
diff changeset
323 if (! arg0.isnumeric ())
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21078
diff changeset
324 err_wrong_type_arg ("hypot", arg0);
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23585
diff changeset
325 if (! arg1.isnumeric ())
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21078
diff changeset
326 err_wrong_type_arg ("hypot", arg1);
21118
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
327
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
328 if (arg0.iscomplex ())
21118
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
329 arg0 = arg0.abs ();
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
330 if (arg1.iscomplex ())
21118
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
331 arg1 = arg1.abs ();
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
332
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
333 if (arg0.is_single_type () || arg1.is_single_type ())
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
334 {
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
335 if (arg0.is_scalar_type () && arg1.is_scalar_type ())
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
336 retval = hypotf (arg0.float_value (), arg1.float_value ());
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
337 else
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
338 {
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
339 FloatNDArray a0 = arg0.float_array_value ();
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
340 FloatNDArray a1 = arg1.float_array_value ();
24088
0160a3199b2d avoid warnings from GCC about ABI change with exception specifications
John W. Eaton <jwe@octave.org>
parents: 23803
diff changeset
341 retval = binmap<float> (a0, a1, std::hypot, "hypot");
21118
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
342 }
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
343 }
10538
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
344 else
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
345 {
21118
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
346 if (arg0.is_scalar_type () && arg1.is_scalar_type ())
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
347 retval = hypot (arg0.scalar_value (), arg1.scalar_value ());
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
348 else if (arg0.issparse () || arg1.issparse ())
10538
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
349 {
21118
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
350 SparseMatrix m0 = arg0.sparse_matrix_value ();
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
351 SparseMatrix m1 = arg1.sparse_matrix_value ();
23625
b0a2367823f5 Use hypot, hypotf from C++ std library.
Rik <rik@octave.org>
parents: 23599
diff changeset
352 retval = binmap<double> (m0, m1, std::hypot, "hypot");
10538
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
353 }
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
354 else
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
355 {
21118
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
356 NDArray a0 = arg0.array_value ();
3ac9f47fb04b Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents: 21100
diff changeset
357 NDArray a1 = arg1.array_value ();
23625
b0a2367823f5 Use hypot, hypotf from C++ std library.
Rik <rik@octave.org>
parents: 23599
diff changeset
358 retval = binmap<double> (a0, a1, std::hypot, "hypot");
10538
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
359 }
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
360 }
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
361
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
362 return retval;
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
363 }
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
364
7631
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
365 DEFUN (hypot, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
366 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
367 @deftypefn {} {@var{h} =} hypot (@var{x}, @var{y})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
368 @deftypefnx {} {@var{h} =} hypot (@var{x}, @var{y}, @var{z}, @dots{})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
369 Compute the element-by-element square root of the sum of the squares of
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
370 @var{x} and @var{y}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
371
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
372 This is equivalent to
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
373 @code{sqrt (@var{x}.^2 + @var{y}.^2)}, but is calculated in a manner that
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
374 avoids overflows for large values of @var{x} or @var{y}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
375
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
376 @code{hypot} can also be called with more than 2 arguments; in this case,
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
377 the arguments are accumulated from left to right:
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
378
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
379 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
380 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
381 hypot (hypot (@var{x}, @var{y}), @var{z})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
382 hypot (hypot (hypot (@var{x}, @var{y}), @var{z}), @var{w}), etc.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
383 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
384 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
385 @end deftypefn */)
7631
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
386 {
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
387 int nargin = args.length ();
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
388
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
389 if (nargin < 2)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
390 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
391
7631
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
392 octave_value retval;
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
393
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents: 10405
diff changeset
394 if (nargin == 2)
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
395 retval = do_hypot (args(0), args(1));
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
396 else
10538
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
397 {
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
398 retval = args(0);
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
399
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
400 for (int i = 1; i < nargin; i++)
10538
26673015caec extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents: 10533
diff changeset
401 retval = do_hypot (retval, args(i));
7631
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
402 }
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
403
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
404 return retval;
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
405 }
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
406
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
407 /*
7741
72c0489653ac fix tests
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
408 %!assert (size (hypot (zeros (0, 2), zeros (0, 2))), [0, 2])
72c0489653ac fix tests
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
409 %!assert (size (hypot (rand (2, 3, 4), zeros (2, 3, 4))), [2, 3, 4])
72c0489653ac fix tests
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
410 %!assert (size (hypot (rand (2, 3, 4), 1)), [2, 3, 4])
72c0489653ac fix tests
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
411 %!assert (size (hypot (1, rand (2, 3, 4))), [2, 3, 4])
72c0489653ac fix tests
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
412 %!assert (size (hypot (1, 2)), [1, 1])
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
413 %!assert (hypot (1:10, 1:10), sqrt (2) * [1:10], 16*eps)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
414 %!assert (hypot (single (1:10), single (1:10)), single (sqrt (2) * [1:10]))
18789
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
415
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
416 ## Test sparse implementations
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
417 %!shared xs
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
418 %! xs = sparse (0:3);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
419 %!test
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
420 %! y = hypot (1, xs);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
421 %! assert (nnz (y), 4);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
422 %! assert (y, sparse (hypot (1, 0:3)));
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
423 %!test
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
424 %! y = hypot (0, xs);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
425 %! assert (nnz (y), 3);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
426 %! assert (y, xs);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
427 %!test
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
428 %! y = hypot (xs, 1);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
429 %! assert (nnz (y), 4);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
430 %! assert (y, sparse (hypot (0:3, 1)));
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
431 %!test
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
432 %! y = hypot (xs, 0);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
433 %! assert (nnz (y), 3);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
434 %! assert (y, xs);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
435 %!test
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
436 %! y = hypot (sparse ([0 0]), sparse ([0 1]));
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
437 %! assert (nnz (y), 1);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
438 %! assert (y, sparse ([0 1]));
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
439 %!test
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
440 %! y = hypot (sparse ([0 1]), sparse ([0 0]));
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
441 %! assert (nnz (y), 1);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
442 %! assert (y, sparse ([0 1]));
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
443
7631
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
444 */
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
445
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
446 template <typename T, typename ET>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
447 void
9813
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
448 map_2_xlog2 (const Array<T>& x, Array<T>& f, Array<ET>& e)
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
449 {
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
450 f = Array<T>(x.dims ());
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
451 e = Array<ET>(x.dims ());
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
452 for (octave_idx_type i = 0; i < x.numel (); i++)
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
453 {
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
454 int exp;
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
455 f.xelem (i) = math::log2 (x(i), exp);
9813
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
456 e.xelem (i) = exp;
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
457 }
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
458 }
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
459
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
460 DEFUN (log2, args, nargout,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
461 doc: /* -*- texinfo -*-
29817
ba571657651a Improve documentation for log2 function (bug #60817).
Rik <rik@octave.org>
parents: 29654
diff changeset
462 @deftypefn {} {@var{y} =} log2 (@var{x})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
463 @deftypefnx {} {[@var{f}, @var{e}] =} log2 (@var{x})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
464 Compute the base-2 logarithm of each element of @var{x}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
465
29817
ba571657651a Improve documentation for log2 function (bug #60817).
Rik <rik@octave.org>
parents: 29654
diff changeset
466 If called with one output, compute the base-2 logarithm such that
ba571657651a Improve documentation for log2 function (bug #60817).
Rik <rik@octave.org>
parents: 29654
diff changeset
467 @tex
ba571657651a Improve documentation for log2 function (bug #60817).
Rik <rik@octave.org>
parents: 29654
diff changeset
468 $2^y = x$.
ba571657651a Improve documentation for log2 function (bug #60817).
Rik <rik@octave.org>
parents: 29654
diff changeset
469 @end tex
ba571657651a Improve documentation for log2 function (bug #60817).
Rik <rik@octave.org>
parents: 29654
diff changeset
470 @ifnottex
ba571657651a Improve documentation for log2 function (bug #60817).
Rik <rik@octave.org>
parents: 29654
diff changeset
471 @code{2^@var{y} = @var{x}}.
ba571657651a Improve documentation for log2 function (bug #60817).
Rik <rik@octave.org>
parents: 29654
diff changeset
472 @end ifnottex
ba571657651a Improve documentation for log2 function (bug #60817).
Rik <rik@octave.org>
parents: 29654
diff changeset
473
ba571657651a Improve documentation for log2 function (bug #60817).
Rik <rik@octave.org>
parents: 29654
diff changeset
474 If called with two output arguments, split @var{x} into binary mantissa
ba571657651a Improve documentation for log2 function (bug #60817).
Rik <rik@octave.org>
parents: 29654
diff changeset
475 (@var{f}) and exponent (@var{e}) such that
ba571657651a Improve documentation for log2 function (bug #60817).
Rik <rik@octave.org>
parents: 29654
diff changeset
476 @tex
ba571657651a Improve documentation for log2 function (bug #60817).
Rik <rik@octave.org>
parents: 29654
diff changeset
477 $x = f \cdot 2^e$
ba571657651a Improve documentation for log2 function (bug #60817).
Rik <rik@octave.org>
parents: 29654
diff changeset
478 @end tex
ba571657651a Improve documentation for log2 function (bug #60817).
Rik <rik@octave.org>
parents: 29654
diff changeset
479 @ifnottex
ba571657651a Improve documentation for log2 function (bug #60817).
Rik <rik@octave.org>
parents: 29654
diff changeset
480 @code{@var{x} = @var{f} * 2^@var{e}}
ba571657651a Improve documentation for log2 function (bug #60817).
Rik <rik@octave.org>
parents: 29654
diff changeset
481 @end ifnottex
ba571657651a Improve documentation for log2 function (bug #60817).
Rik <rik@octave.org>
parents: 29654
diff changeset
482 where
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
483 @tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
484 ${1 \over 2} \le \left| f \right| < 1$
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
485 @end tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
486 @ifnottex
29817
ba571657651a Improve documentation for log2 function (bug #60817).
Rik <rik@octave.org>
parents: 29654
diff changeset
487 @w{@code{1/2 <= abs (@var{f}) < 1}}
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
488 @end ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
489 and @var{e} is an integer. If
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
490 @tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
491 $x = 0$, $f = e = 0$.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
492 @end tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
493 @ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
494 @w{@code{x = 0}}, @w{@code{f = e = 0}}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
495 @end ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
496 @seealso{pow2, log, log10, exp}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
497 @end deftypefn */)
9813
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
498 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
499 if (args.length () != 1)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
500 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
501
9813
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
502 octave_value_list retval;
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
503
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
504 if (nargout < 2)
20884
f1b2a2dbc0e1 2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents: 20853
diff changeset
505 retval = ovl (args(0).log2 ());
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
506 else if (args(0).is_single_type ())
9813
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
507 {
23582
0cc2011d800e maint: Deprecate is_real_type and replace with isreal.
Rik <rik@octave.org>
parents: 23581
diff changeset
508 if (args(0).isreal ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
509 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
510 FloatNDArray f;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
511 FloatNDArray x = args(0).float_array_value ();
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
512 // FIXME: should E be an int value?
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
513 FloatMatrix e;
9813
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
514 map_2_xlog2 (x, f, e);
20884
f1b2a2dbc0e1 2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents: 20853
diff changeset
515 retval = ovl (f, e);
9813
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
516 }
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
517 else if (args(0).iscomplex ())
9813
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
518 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
519 FloatComplexNDArray f;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
520 FloatComplexNDArray x = args(0).float_complex_array_value ();
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
521 // FIXME: should E be an int value?
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
522 FloatNDArray e;
9813
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
523 map_2_xlog2 (x, f, e);
20884
f1b2a2dbc0e1 2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents: 20853
diff changeset
524 retval = ovl (f, e);
9813
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
525 }
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
526 }
23582
0cc2011d800e maint: Deprecate is_real_type and replace with isreal.
Rik <rik@octave.org>
parents: 23581
diff changeset
527 else if (args(0).isreal ())
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
528 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
529 NDArray f;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
530 NDArray x = args(0).array_value ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
531 // FIXME: should E be an int value?
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
532 Matrix e;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
533 map_2_xlog2 (x, f, e);
20884
f1b2a2dbc0e1 2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents: 20853
diff changeset
534 retval = ovl (f, e);
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
535 }
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
536 else if (args(0).iscomplex ())
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
537 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
538 ComplexNDArray f;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
539 ComplexNDArray x = args(0).complex_array_value ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
540 // FIXME: should E be an int value?
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
541 NDArray e;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
542 map_2_xlog2 (x, f, e);
20884
f1b2a2dbc0e1 2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents: 20853
diff changeset
543 retval = ovl (f, e);
9813
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
544 }
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
545 else
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21078
diff changeset
546 err_wrong_type_arg ("log2", args(0));
9813
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
547
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
548 return retval;
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
549 }
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
550
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
551 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
552 %!assert (log2 ([1/4, 1/2, 1, 2, 4]), [-2, -1, 0, 1, 2])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
553 %!assert (log2 (Inf), Inf)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
554 %!assert (isnan (log2 (NaN)))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
555 %!assert (log2 (4*i), 2 + log2 (1*i))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
556 %!assert (log2 (complex (0,Inf)), Inf + log2 (i))
9813
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
557
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
558 %!test
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
559 %! [f, e] = log2 ([0,-1; 2,-4; Inf,-Inf]);
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
560 %! assert (f, [0,-0.5; 0.5,-0.5; Inf,-Inf]);
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
561 %! assert (e(1:2,:), [0,1;2,3]);
9813
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
562
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
563 %!test
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
564 %! [f, e] = log2 (complex (zeros (3, 2), [0,-1; 2,-4; Inf,-Inf]));
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
565 %! assert (f, complex (zeros (3, 2), [0,-0.5; 0.5,-0.5; Inf,-Inf]));
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
566 %! assert (e(1:2,:), [0,1; 2,3]);
18851
9d185537e5d1 * data.cc: New test for log2 (bug #42583).
John W. Eaton <jwe@octave.org>
parents: 18809
diff changeset
567
23573
1b4f4ec53b4a use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents: 23572
diff changeset
568 %!assert <*42583> (all (log2 (pow2 (-1074:1023)) == -1074:1023))
9813
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
569 */
8fa32b527d9a improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents: 9812
diff changeset
570
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
571 DEFUN (rem, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
572 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
573 @deftypefn {} {@var{r} =} rem (@var{x}, @var{y})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
574 Return the remainder of the division @code{@var{x} / @var{y}}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
575
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
576 The remainder is computed using the expression
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
577
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
578 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
579 x - y .* fix (x ./ y)
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
580 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
581
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
582 An error message is printed if the dimensions of the arguments do not agree,
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
583 or if either argument is complex.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
584
26292
d00577d95369 doc: Add warning note about integers exceeding flintmax to mod, rem (bug #55238).
Rik <rik@octave.org>
parents: 26199
diff changeset
585 Programming Notes: When calculating with floating point numbers (double,
d00577d95369 doc: Add warning note about integers exceeding flintmax to mod, rem (bug #55238).
Rik <rik@octave.org>
parents: 26199
diff changeset
586 single), values within a few eps of an integer will be rounded to that
d00577d95369 doc: Add warning note about integers exceeding flintmax to mod, rem (bug #55238).
Rik <rik@octave.org>
parents: 26199
diff changeset
587 integer before computation for compatibility with @sc{matlab}. Any floating
d00577d95369 doc: Add warning note about integers exceeding flintmax to mod, rem (bug #55238).
Rik <rik@octave.org>
parents: 26199
diff changeset
588 point integers greater than @code{flintmax} (2^53 for double) will not compute
d00577d95369 doc: Add warning note about integers exceeding flintmax to mod, rem (bug #55238).
Rik <rik@octave.org>
parents: 26199
diff changeset
589 correctly. For larger integer values convert the input to @code{uint64} before
d00577d95369 doc: Add warning note about integers exceeding flintmax to mod, rem (bug #55238).
Rik <rik@octave.org>
parents: 26199
diff changeset
590 calling this function.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
591
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
592 By convention,
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
593
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
594 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
595 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
596 rem (@var{x}, 0) = NaN if @var{x} is a floating point variable
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
597 rem (@var{x}, 0) = 0 if @var{x} is an integer variable
26292
d00577d95369 doc: Add warning note about integers exceeding flintmax to mod, rem (bug #55238).
Rik <rik@octave.org>
parents: 26199
diff changeset
598 rem (@var{x}, @var{y}) returns a value with the signbit from @var{x}
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
599 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
600 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
601
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
602 For the opposite conventions see the @code{mod} function. In general,
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
603 @code{rem} is best when computing the remainder after division of two
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
604 @emph{positive} numbers. For negative numbers, or when the values are
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
605 periodic, @code{mod} is a better choice.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
606 @seealso{mod}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
607 @end deftypefn */)
4311
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
608 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
609 if (args.length () != 2)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
610 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
611
4311
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
612 octave_value retval;
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
613
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23585
diff changeset
614 if (! args(0).isnumeric ())
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21078
diff changeset
615 err_wrong_type_arg ("rem", args(0));
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
616
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23585
diff changeset
617 if (! args(1).isnumeric ())
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21078
diff changeset
618 err_wrong_type_arg ("rem", args(1));
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
619
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
620 if (args(0).iscomplex () || args(1).iscomplex ())
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
621 error ("rem: not defined for complex numbers");
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
622
23580
2230f9e10fb3 maint: Deprecate is_integer_type and replace with isinteger.
Rik <rik@octave.org>
parents: 23579
diff changeset
623 if (args(0).isinteger () || args(1).isinteger ())
4311
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
624 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
625 builtin_type_t btyp0 = args(0).builtin_type ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
626 builtin_type_t btyp1 = args(1).builtin_type ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
627 if (btyp0 == btyp_double || btyp0 == btyp_float)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
628 btyp0 = btyp1;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
629 if (btyp1 == btyp_double || btyp1 == btyp_float)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
630 btyp1 = btyp0;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
631
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
632 if (btyp0 != btyp1)
26107
05dfcb24ef12 Supply missing arguments to variable length *printf functions (bug #55046).
Rik <rik@octave.org>
parents: 26046
diff changeset
633 error ("rem: cannot combine %s and %s",
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
634 args(0).class_name ().c_str (),
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
635 args(1).class_name ().c_str ());
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
636
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
637 switch (btyp0)
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
638 {
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
639 #define MAKE_INT_BRANCH(X) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
640 case btyp_ ## X: \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
641 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
642 X##NDArray a0 = args(0).X##_array_value (); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
643 X##NDArray a1 = args(1).X##_array_value (); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
644 retval = binmap<octave_##X,octave_##X,octave_##X> (a0, a1, rem, "rem"); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
645 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
646 break
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
647
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
648 MAKE_INT_BRANCH (int8);
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
649 MAKE_INT_BRANCH (int16);
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
650 MAKE_INT_BRANCH (int32);
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
651 MAKE_INT_BRANCH (int64);
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
652 MAKE_INT_BRANCH (uint8);
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
653 MAKE_INT_BRANCH (uint16);
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
654 MAKE_INT_BRANCH (uint32);
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
655 MAKE_INT_BRANCH (uint64);
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
656
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
657 #undef MAKE_INT_BRANCH
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
658
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
659 default:
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
660 panic_impossible ();
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
661 }
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
662 }
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
663 else if (args(0).is_single_type () || args(1).is_single_type ())
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
664 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
665 if (args(0).is_scalar_type () && args(1).is_scalar_type ())
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
666 retval = math::rem (args(0).float_value (), args(1).float_value ());
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
667 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
668 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
669 FloatNDArray a0 = args(0).float_array_value ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
670 FloatNDArray a1 = args(1).float_array_value ();
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
671 retval = binmap<float> (a0, a1, math::rem<float>, "rem");
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
672 }
4311
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
673 }
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
674 else
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
675 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
676 if (args(0).is_scalar_type () && args(1).is_scalar_type ())
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
677 retval = math::rem (args(0).scalar_value (), args(1).scalar_value ());
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
678 else if (args(0).issparse () || args(1).issparse ())
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
679 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
680 SparseMatrix m0 = args(0).sparse_matrix_value ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
681 SparseMatrix m1 = args(1).sparse_matrix_value ();
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
682 retval = binmap<double> (m0, m1, math::rem<double>, "rem");
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
683 }
10435
6a271334750c implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents: 10405
diff changeset
684 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
685 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
686 NDArray a0 = args(0).array_value ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
687 NDArray a1 = args(1).array_value ();
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
688 retval = binmap<double> (a0, a1, math::rem<double>, "rem");
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
689 }
4311
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
690 }
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
691
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
692 return retval;
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
693 }
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
694
7506
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
695 /*
19118
9c5a17d5fc19 Deprecate fmod function.
Rik <rik@octave.org>
parents: 19079
diff changeset
696 %!assert (size (rem (zeros (0, 2), zeros (0, 2))), [0, 2])
9c5a17d5fc19 Deprecate fmod function.
Rik <rik@octave.org>
parents: 19079
diff changeset
697 %!assert (size (rem (rand (2, 3, 4), zeros (2, 3, 4))), [2, 3, 4])
9c5a17d5fc19 Deprecate fmod function.
Rik <rik@octave.org>
parents: 19079
diff changeset
698 %!assert (size (rem (rand (2, 3, 4), 1)), [2, 3, 4])
9c5a17d5fc19 Deprecate fmod function.
Rik <rik@octave.org>
parents: 19079
diff changeset
699 %!assert (size (rem (1, rand (2, 3, 4))), [2, 3, 4])
9c5a17d5fc19 Deprecate fmod function.
Rik <rik@octave.org>
parents: 19079
diff changeset
700 %!assert (size (rem (1, 2)), [1, 1])
18789
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
701
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
702 %!assert (rem ([1, 2, 3; -1, -2, -3], 2), [1, 0, 1; -1, 0, -1])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
703 %!assert (rem ([1, 2, 3; -1, -2, -3], 2 * ones (2, 3)),[1, 0, 1; -1, 0, -1])
21317
a4faec57f4c8 maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents: 21301
diff changeset
704 %!assert (rem ([0, 1, 2], [0, 0, 1]), [NaN, NaN, 0])
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
705 %!assert (rem (uint8 ([1, 2, 3; -1, -2, -3]), uint8 (2)),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
706 %! uint8 ([1, 0, 1; -1, 0, -1]))
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
707 %!assert (uint8 (rem ([1, 2, 3; -1, -2, -3], 2 * ones (2, 3))),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
708 %! uint8 ([1, 0, 1; -1, 0, -1]))
21317
a4faec57f4c8 maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents: 21301
diff changeset
709 %!assert (rem (uint8 ([0, 1, 2]), [0, 0, 1]), uint8 ([0, 0, 0]))
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
710
18789
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
711 ## Test sparse implementations
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
712 %!shared xs
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
713 %! xs = sparse (0:3);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
714 %!test
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
715 %! y = rem (11, xs);
20374
0cefba1a1030 Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents: 20232
diff changeset
716 %! assert (isnan (y(1)));
18789
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
717 %! assert (y, sparse (rem (11, 0:3)));
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
718 %!test
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
719 %! y = rem (0, xs);
20374
0cefba1a1030 Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents: 20232
diff changeset
720 %! assert (nnz (y), 1);
0cefba1a1030 Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents: 20232
diff changeset
721 %! assert (y, sparse ([NaN 0 0 0]));
18789
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
722 %!test
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
723 %! y = rem (xs, 2);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
724 %! assert (nnz (y), 2);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
725 %! assert (y, sparse (rem (0:3, 2)));
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
726 %!test
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
727 %! y = rem (xs, 1);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
728 %! assert (nnz (y), 0);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
729 %! assert (y, sparse (rem (0:3, 1)));
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
730 %!test
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
731 %! y = rem (sparse ([11 11 11 11]), xs);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
732 %! assert (nnz (y), 3);
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
733 %! assert (y, sparse (rem (11, 0:3)));
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
734 %!test
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
735 %! y = rem (sparse ([0 0 0 0]), xs);
20374
0cefba1a1030 Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents: 20232
diff changeset
736 %! assert (nnz (y), 1);
0cefba1a1030 Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents: 20232
diff changeset
737 %! assert (y, sparse ([NaN 0 0 0]));
0cefba1a1030 Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents: 20232
diff changeset
738
23573
1b4f4ec53b4a use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents: 23572
diff changeset
739 %!assert <*45587> (signbit (rem (-0, 1)))
1b4f4ec53b4a use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents: 23572
diff changeset
740 %!assert <*45587> (! signbit (rem (0, 1)))
1b4f4ec53b4a use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents: 23572
diff changeset
741
1b4f4ec53b4a use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents: 23572
diff changeset
742 %!assert <*42627> (rem (0.94, 0.01), 0.0)
18789
dccbc8bff5cb Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents: 18775
diff changeset
743
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
744 %!error rem (uint (8), int8 (5))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
745 %!error rem (uint8 ([1, 2]), uint8 ([3, 4, 5]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
746 %!error rem ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
747 %!error rem (1, 2, 3)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
748 %!error rem ([1, 2], [3, 4, 5])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
749 %!error rem (i, 1)
7506
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
750 */
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
751
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
752 DEFUN (mod, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
753 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
754 @deftypefn {} {@var{m} =} mod (@var{x}, @var{y})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
755 Compute the modulo of @var{x} and @var{y}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
756
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
757 Conceptually this is given by
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
758
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
759 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
760 x - y .* floor (x ./ y)
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
761 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
762
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
763 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
764 and is written such that the correct modulus is returned for integer types.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
765 This function handles negative values correctly. That is,
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
766 @w{@code{mod (-1, 3)}} is 2, not -1, as @w{@code{rem (-1, 3)}} returns.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
767
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
768 An error results if the dimensions of the arguments do not agree, or if
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
769 either of the arguments is complex.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
770
26292
d00577d95369 doc: Add warning note about integers exceeding flintmax to mod, rem (bug #55238).
Rik <rik@octave.org>
parents: 26199
diff changeset
771 Programming Notes: When calculating with floating point numbers (double,
d00577d95369 doc: Add warning note about integers exceeding flintmax to mod, rem (bug #55238).
Rik <rik@octave.org>
parents: 26199
diff changeset
772 single), values within a few eps of an integer will be rounded to that
d00577d95369 doc: Add warning note about integers exceeding flintmax to mod, rem (bug #55238).
Rik <rik@octave.org>
parents: 26199
diff changeset
773 integer before computation for compatibility with @sc{matlab}. Any floating
d00577d95369 doc: Add warning note about integers exceeding flintmax to mod, rem (bug #55238).
Rik <rik@octave.org>
parents: 26199
diff changeset
774 point integers greater than @code{flintmax} (2^53 for double) will not compute
d00577d95369 doc: Add warning note about integers exceeding flintmax to mod, rem (bug #55238).
Rik <rik@octave.org>
parents: 26199
diff changeset
775 correctly. For larger integer values convert the input to @code{uint64} before
d00577d95369 doc: Add warning note about integers exceeding flintmax to mod, rem (bug #55238).
Rik <rik@octave.org>
parents: 26199
diff changeset
776 calling this function.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
777
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
778 By convention,
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
779
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
780 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
781 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
782 mod (@var{x}, 0) = @var{x}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
783 mod (@var{x}, @var{y}) returns a value with the signbit from @var{y}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
784 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
785 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
786
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
787 For the opposite conventions see the @code{rem} function. In general,
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
788 @code{mod} is a better choice than @code{rem} when any of the inputs are
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
789 negative numbers or when the values are periodic.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
790 @seealso{rem}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
791 @end deftypefn */)
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
792 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
793 if (args.length () != 2)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
794 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
795
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
796 octave_value retval;
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
797
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23585
diff changeset
798 if (! args(0).isnumeric ())
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21078
diff changeset
799 err_wrong_type_arg ("mod", args(0));
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
800
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23585
diff changeset
801 if (! args(1).isnumeric ())
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21078
diff changeset
802 err_wrong_type_arg ("mod", args(1));
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
803
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
804 if (args(0).iscomplex () || args(1).iscomplex ())
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
805 error ("mod: not defined for complex numbers");
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
806
23580
2230f9e10fb3 maint: Deprecate is_integer_type and replace with isinteger.
Rik <rik@octave.org>
parents: 23579
diff changeset
807 if (args(0).isinteger () || args(1).isinteger ())
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
808 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
809 builtin_type_t btyp0 = args(0).builtin_type ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
810 builtin_type_t btyp1 = args(1).builtin_type ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
811 if (btyp0 == btyp_double || btyp0 == btyp_float)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
812 btyp0 = btyp1;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
813 if (btyp1 == btyp_double || btyp1 == btyp_float)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
814 btyp1 = btyp0;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
815
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
816 if (btyp0 != btyp1)
26107
05dfcb24ef12 Supply missing arguments to variable length *printf functions (bug #55046).
Rik <rik@octave.org>
parents: 26046
diff changeset
817 error ("mod: cannot combine %s and %s",
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
818 args(0).class_name ().c_str (),
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
819 args(1).class_name ().c_str ());
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
820
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
821 switch (btyp0)
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
822 {
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
823 #define MAKE_INT_BRANCH(X) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
824 case btyp_ ## X: \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
825 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
826 X##NDArray a0 = args(0).X##_array_value (); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
827 X##NDArray a1 = args(1).X##_array_value (); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
828 retval = binmap<octave_##X,octave_##X,octave_##X> (a0, a1, mod, "mod"); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
829 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
830 break
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
831
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
832 MAKE_INT_BRANCH (int8);
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
833 MAKE_INT_BRANCH (int16);
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
834 MAKE_INT_BRANCH (int32);
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
835 MAKE_INT_BRANCH (int64);
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
836 MAKE_INT_BRANCH (uint8);
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
837 MAKE_INT_BRANCH (uint16);
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
838 MAKE_INT_BRANCH (uint32);
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
839 MAKE_INT_BRANCH (uint64);
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
840
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
841 #undef MAKE_INT_BRANCH
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
842
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
843 default:
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
844 panic_impossible ();
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
845 }
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
846 }
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
847 else if (args(0).is_single_type () || args(1).is_single_type ())
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
848 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
849 if (args(0).is_scalar_type () && args(1).is_scalar_type ())
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
850 retval = math::mod (args(0).float_value (), args(1).float_value ());
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
851 else
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
852 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
853 FloatNDArray a0 = args(0).float_array_value ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
854 FloatNDArray a1 = args(1).float_array_value ();
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
855 retval = binmap<float> (a0, a1, math::mod<float>, "mod");
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
856 }
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
857 }
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
858 else
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
859 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
860 if (args(0).is_scalar_type () && args(1).is_scalar_type ())
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
861 retval = math::mod (args(0).scalar_value (), args(1).scalar_value ());
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
862 else if (args(0).issparse () || args(1).issparse ())
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
863 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
864 SparseMatrix m0 = args(0).sparse_matrix_value ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
865 SparseMatrix m1 = args(1).sparse_matrix_value ();
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
866 retval = binmap<double> (m0, m1, math::mod<double>, "mod");
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
867 }
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
868 else
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
869 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
870 NDArray a0 = args(0).array_value ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
871 NDArray a1 = args(1).array_value ();
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
872 retval = binmap<double> (a0, a1, math::mod<double>, "mod");
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
873 }
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
874 }
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
875
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
876 return retval;
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
877 }
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
878
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
879 /*
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
880 ## empty input test
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
881 %!assert (isempty (mod ([], [])))
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
882
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
883 ## x mod y, y != 0 tests
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
884 %!assert (mod (5, 3), 2)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
885 %!assert (mod (-5, 3), 1)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
886 %!assert (mod (0, 3), 0)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
887 %!assert (mod ([-5, 5, 0], [3, 3, 3]), [1, 2, 0])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
888 %!assert (mod ([-5; 5; 0], [3; 3; 3]), [1; 2; 0])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
889 %!assert (mod ([-5, 5; 0, 3], [3, 3 ; 3, 1]), [1, 2 ; 0, 0])
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
890
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
891 ## x mod 0 tests
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
892 %!assert (mod (5, 0), 5)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
893 %!assert (mod (-5, 0), -5)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
894 %!assert (mod ([-5, 5, 0], [3, 0, 3]), [1, 5, 0])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
895 %!assert (mod ([-5; 5; 0], [3; 0; 3]), [1; 5; 0])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
896 %!assert (mod ([-5, 5; 0, 3], [3, 0 ; 3, 1]), [1, 5 ; 0, 0])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
897 %!assert (mod ([-5, 5; 0, 3], [0, 0 ; 0, 0]), [-5, 5; 0, 3])
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
898
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
899 ## mixed scalar/matrix tests
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
900 %!assert (mod ([-5, 5; 0, 3], 0), [-5, 5; 0, 3])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
901 %!assert (mod ([-5, 5; 0, 3], 3), [1, 2; 0, 0])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
902 %!assert (mod (-5, [0,0; 0,0]), [-5, -5; -5, -5])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
903 %!assert (mod (-5, [3,0; 3,1]), [1, -5; 1, 0])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
904 %!assert (mod (-5, [3,2; 3,1]), [1, 1; 1, 0])
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
905
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
906 ## integer types
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
907 %!assert (mod (uint8 (5), uint8 (4)), uint8 (1))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
908 %!assert (mod (uint8 ([1:5]), uint8 (4)), uint8 ([1,2,3,0,1]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
909 %!assert (mod (uint8 ([1:5]), uint8 (0)), uint8 ([1:5]))
28930
2883b3d08b7e maint: Remove unnecessary parentheses bracketing %!error BIST tests.
Rik <rik@octave.org>
parents: 28919
diff changeset
910 %!error mod (uint8 (5), int8 (4))
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
911
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
912 ## mixed integer/real types
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
913 %!assert (mod (uint8 (5), 4), uint8 (1))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
914 %!assert (mod (5, uint8 (4)), uint8 (1))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
915 %!assert (mod (uint8 ([1:5]), 4), uint8 ([1,2,3,0,1]))
11357
903c1a3df301 Add additional tests for mod with non-integer real values.
Rik <octave@nomad.inbox5.com>
parents: 11242
diff changeset
916
903c1a3df301 Add additional tests for mod with non-integer real values.
Rik <octave@nomad.inbox5.com>
parents: 11242
diff changeset
917 ## non-integer real numbers
903c1a3df301 Add additional tests for mod with non-integer real values.
Rik <octave@nomad.inbox5.com>
parents: 11242
diff changeset
918 %!assert (mod (2.1, 0.1), 0)
903c1a3df301 Add additional tests for mod with non-integer real values.
Rik <octave@nomad.inbox5.com>
parents: 11242
diff changeset
919 %!assert (mod (2.1, 0.2), 0.1, eps)
18869
23681c9ea7ba better guess if rem or mod could be zero (bug #42627)
Olaf Till <i7tiol@t-online.de>
parents: 18851
diff changeset
920
23573
1b4f4ec53b4a use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents: 23572
diff changeset
921 %!assert <*45587> (signbit (mod (-0, 0)))
1b4f4ec53b4a use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents: 23572
diff changeset
922 %!assert <*45587> (! signbit (mod (0, -0)))
1b4f4ec53b4a use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents: 23572
diff changeset
923
1b4f4ec53b4a use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents: 23572
diff changeset
924 %!assert <*42627> (mod (0.94, 0.01), 0.0)
25858
1f52a96c8c21 Fix mod operation for signed integer types (bug #54602).
Gene Harvey <gharveymn@gmail.com>
parents: 25578
diff changeset
925
1f52a96c8c21 Fix mod operation for signed integer types (bug #54602).
Gene Harvey <gharveymn@gmail.com>
parents: 25578
diff changeset
926 %!assert <*54602> (mod (int8 (125), int8 (-25)), int8 (0))
1f52a96c8c21 Fix mod operation for signed integer types (bug #54602).
Gene Harvey <gharveymn@gmail.com>
parents: 25578
diff changeset
927 %!assert <*54602> (mod (int8 (-125), int8 (-25)), int8 (0))
25860
60fd3c44769f Fix BIST test in cset 1f52a96c8c21.
Rik <rik@octave.org>
parents: 25858
diff changeset
928 %!assert <*54602> (mod (int8 (-125), int8 (0)), int8 (-125))
25858
1f52a96c8c21 Fix mod operation for signed integer types (bug #54602).
Gene Harvey <gharveymn@gmail.com>
parents: 25578
diff changeset
929 %!assert <*54602> (mod (int8 (0), int8 (-25)), int8 (0))
1f52a96c8c21 Fix mod operation for signed integer types (bug #54602).
Gene Harvey <gharveymn@gmail.com>
parents: 25578
diff changeset
930
10436
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
931 */
00219bdd2d17 implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents: 10435
diff changeset
932
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
933 #define DATA_REDUCTION(FCN) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
934 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
935 int nargin = args.length (); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
936 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
937 if (nargin < 1 || nargin > 2) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
938 print_usage (); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
939 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
940 octave_value retval; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
941 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
942 octave_value arg = args(0); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
943 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
944 int dim = (nargin == 1 ? -1 : args(1).int_value (true) - 1); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
945 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
946 if (dim < -1) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
947 error (#FCN ": invalid dimension argument = %d", dim + 1); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
948 \
23582
0cc2011d800e maint: Deprecate is_real_type and replace with isreal.
Rik <rik@octave.org>
parents: 23581
diff changeset
949 if (arg.isreal ()) \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
950 { \
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
951 if (arg.issparse ()) \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
952 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
953 SparseMatrix tmp = arg.sparse_matrix_value (); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
954 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
955 retval = tmp.FCN (dim); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
956 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
957 else if (arg.is_single_type ()) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
958 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
959 FloatNDArray tmp = arg.float_array_value (); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
960 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
961 retval = tmp.FCN (dim); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
962 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
963 else \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
964 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
965 NDArray tmp = arg.array_value (); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
966 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
967 retval = tmp.FCN (dim); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
968 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
969 } \
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
970 else if (arg.iscomplex ()) \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
971 { \
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
972 if (arg.issparse ()) \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
973 { \
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
974 SparseComplexMatrix tmp = arg.sparse_complex_matrix_value (); \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
975 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
976 retval = tmp.FCN (dim); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
977 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
978 else if (arg.is_single_type ()) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
979 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
980 FloatComplexNDArray tmp \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
981 = arg.float_complex_array_value (); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
982 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
983 retval = tmp.FCN (dim); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
984 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
985 else \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
986 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
987 ComplexNDArray tmp = arg.complex_array_value (); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
988 \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
989 retval = tmp.FCN (dim); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
990 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
991 } \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
992 else \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
993 err_wrong_type_arg (#FCN, arg); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
994 \
3723
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
995 return retval
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
996
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1940
diff changeset
997 DEFUN (cumprod, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
998 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
999 @deftypefn {} {@var{y} =} cumprod (@var{x})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
1000 @deftypefnx {} {@var{y} =} cumprod (@var{x}, @var{dim})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1001 Cumulative product of elements along dimension @var{dim}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1002
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1003 If @var{dim} is omitted, it defaults to the first non-singleton dimension.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1004 For example:
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1005
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1006 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1007 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1008 cumprod ([1, 2; 3, 4; 5, 6])
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1009 @result{} 1 2
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1010 3 8
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1011 15 48
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1012 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1013 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1014 @seealso{prod, cumsum}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1015 @end deftypefn */)
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1016 {
3723
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
1017 DATA_REDUCTION (cumprod);
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1018 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1019
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1020 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1021 %!assert (cumprod ([1, 2, 3]), [1, 2, 6])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1022 %!assert (cumprod ([-1; -2; -3]), [-1; 2; -6])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1023 %!assert (cumprod ([i, 2+i, -3+2i, 4]), [i, -1+2i, -1-8i, -4-32i])
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1024 %!assert (cumprod ([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i]),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1025 %! [1, 2, 3; i, 4i, 9i; -1+i, -8+8i, -27+27i])
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1026
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1027 %!assert (cumprod (single ([1, 2, 3])), single ([1, 2, 6]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1028 %!assert (cumprod (single ([-1; -2; -3])), single ([-1; 2; -6]))
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1029 %!assert (cumprod (single ([i, 2+i, -3+2i, 4])),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1030 %! single ([i, -1+2i, -1-8i, -4-32i]))
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1031 %!assert (cumprod (single ([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i])),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1032 %! single ([1, 2, 3; i, 4i, 9i; -1+i, -8+8i, -27+27i]))
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1033
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1034 %!assert (cumprod ([2, 3; 4, 5], 1), [2, 3; 8, 15])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1035 %!assert (cumprod ([2, 3; 4, 5], 2), [2, 6; 4, 20])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1036
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1037 %!assert (cumprod (single ([2, 3; 4, 5]), 1), single ([2, 3; 8, 15]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1038 %!assert (cumprod (single ([2, 3; 4, 5]), 2), single ([2, 6; 4, 20]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1039
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1040 %!error cumprod ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1041 */
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1042
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1940
diff changeset
1043 DEFUN (cumsum, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1044 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
1045 @deftypefn {} {@var{y} =} cumsum (@var{x})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
1046 @deftypefnx {} {@var{y} =} cumsum (@var{x}, @var{dim})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
1047 @deftypefnx {} {@var{y} =} cumsum (@dots{}, "native")
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
1048 @deftypefnx {} {@var{y} =} cumsum (@dots{}, "double")
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1049 Cumulative sum of elements along dimension @var{dim}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1050
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1051 If @var{dim} is omitted, it defaults to the first non-singleton dimension.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1052 For example:
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1053
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1054 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1055 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1056 cumsum ([1, 2; 3, 4; 5, 6])
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1057 @result{} 1 2
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1058 4 6
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1059 9 12
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1060 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1061 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1062
28960
e5a1087f15d5 doc: Use @xref, @pxref rather than "see @code{}" in TexInfo in libinterp/
Rik <rik@octave.org>
parents: 28930
diff changeset
1063 For an explanation of the optional parameters @qcode{"native"} and
e5a1087f15d5 doc: Use @xref, @pxref rather than "see @code{}" in TexInfo in libinterp/
Rik <rik@octave.org>
parents: 28930
diff changeset
1064 @qcode{"double"}, @pxref{XREFsum,,@code{sum}}.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1065 @seealso{sum, cumprod}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1066 @end deftypefn */)
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1067 {
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1068 int nargin = args.length ();
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1069
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1070 bool isnative = false;
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1071 bool isdouble = false;
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1072
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1073 if (nargin > 1 && args(nargin - 1).is_string ())
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1074 {
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1075 std::string str = args(nargin - 1).string_value ();
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1076
19743
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
1077 if (str == "native")
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
1078 isnative = true;
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
1079 else if (str == "double")
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
1080 isdouble = true;
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
1081 else
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
1082 error ("cumsum: unrecognized string argument");
21055
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
1083
21062
d9c1884d1aaa maint: Eliminate space between variable and decrement '--' operator.
Rik <rik@octave.org>
parents: 21055
diff changeset
1084 nargin--;
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1085 }
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1086
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1087 if (nargin < 1 || nargin > 2)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1088 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1089
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1090 int dim = -1;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1091 if (nargin == 2)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1092 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1093 dim = args(1).int_value () - 1;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1094 if (dim < 0)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1095 error ("cumsum: invalid dimension argument = %d", dim + 1);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1096 }
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1097
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
1098 octave_value retval;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
1099 octave_value arg = args(0);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
1100
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1101 switch (arg.builtin_type ())
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1102 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1103 case btyp_double:
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
1104 if (arg.issparse ())
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1105 retval = arg.sparse_matrix_value ().cumsum (dim);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1106 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1107 retval = arg.array_value ().cumsum (dim);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1108 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1109 case btyp_complex:
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
1110 if (arg.issparse ())
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1111 retval = arg.sparse_complex_matrix_value ().cumsum (dim);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1112 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1113 retval = arg.complex_array_value ().cumsum (dim);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1114 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1115 case btyp_float:
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1116 if (isdouble)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1117 retval = arg.array_value ().cumsum (dim);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1118 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1119 retval = arg.float_array_value ().cumsum (dim);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1120 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1121 case btyp_float_complex:
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1122 if (isdouble)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1123 retval = arg.complex_array_value ().cumsum (dim);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1124 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1125 retval = arg.float_complex_array_value ().cumsum (dim);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1126 break;
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1127
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
1128 #define MAKE_INT_BRANCH(X) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
1129 case btyp_ ## X: \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
1130 if (isnative) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
1131 retval = arg.X ## _array_value ().cumsum (dim); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
1132 else \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
1133 retval = arg.array_value ().cumsum (dim); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
1134 break;
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1135
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1136 MAKE_INT_BRANCH (int8);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1137 MAKE_INT_BRANCH (int16);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1138 MAKE_INT_BRANCH (int32);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1139 MAKE_INT_BRANCH (int64);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1140 MAKE_INT_BRANCH (uint8);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1141 MAKE_INT_BRANCH (uint16);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1142 MAKE_INT_BRANCH (uint32);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1143 MAKE_INT_BRANCH (uint64);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1144
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1145 #undef MAKE_INT_BRANCH
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1146
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1147 case btyp_bool:
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
1148 if (arg.issparse ())
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1149 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1150 SparseMatrix cs = arg.sparse_matrix_value ().cumsum (dim);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1151 if (isnative)
26357
bba4b338757d data.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents: 26292
diff changeset
1152 retval = (cs != 0.0);
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1153 else
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1154 retval = cs;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1155 }
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1156 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1157 {
22773
7f70e420e342 deprecate boolNDArray::sum and boolNDArray::cumsum
John W. Eaton <jwe@octave.org>
parents: 22763
diff changeset
1158 NDArray cs = arg.array_value ().cumsum (dim);
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1159 if (isnative)
26357
bba4b338757d data.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents: 26292
diff changeset
1160 retval = (cs != 0.0);
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1161 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1162 retval = cs;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1163 }
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1164 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1165
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1166 default:
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21078
diff changeset
1167 err_wrong_type_arg ("cumsum", arg);
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1168 }
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1169
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
1170 return retval;
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1171 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1172
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1173 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1174 %!assert (cumsum ([1, 2, 3]), [1, 3, 6])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1175 %!assert (cumsum ([-1; -2; -3]), [-1; -3; -6])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1176 %!assert (cumsum ([i, 2+i, -3+2i, 4]), [i, 2+2i, -1+4i, 3+4i])
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1177 %!assert (cumsum ([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i]),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1178 %! [1, 2, 3; 1+i, 2+2i, 3+3i; 2+2i, 4+4i, 6+6i])
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1179
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1180 %!assert (cumsum (single ([1, 2, 3])), single ([1, 3, 6]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1181 %!assert (cumsum (single ([-1; -2; -3])), single ([-1; -3; -6]))
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1182 %!assert (cumsum (single ([i, 2+i, -3+2i, 4])),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1183 %! single ([i, 2+2i, -1+4i, 3+4i]))
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1184 %!assert (cumsum (single ([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i])),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1185 %! single ([1, 2, 3; 1+i, 2+2i, 3+3i; 2+2i, 4+4i, 6+6i]))
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1186
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1187 %!assert (cumsum ([1, 2; 3, 4], 1), [1, 2; 4, 6])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1188 %!assert (cumsum ([1, 2; 3, 4], 2), [1, 3; 3, 7])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1189
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1190 %!assert (cumsum (single ([1, 2; 3, 4]), 1), single ([1, 2; 4, 6]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1191 %!assert (cumsum (single ([1, 2; 3, 4]), 2), single ([1, 3; 3, 7]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1192
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1193 %!error cumsum ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1194 */
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1195
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1940
diff changeset
1196 DEFUN (diag, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1197 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1198 @deftypefn {} {@var{M} =} diag (@var{v})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1199 @deftypefnx {} {@var{M} =} diag (@var{v}, @var{k})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1200 @deftypefnx {} {@var{M} =} diag (@var{v}, @var{m}, @var{n})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1201 @deftypefnx {} {@var{v} =} diag (@var{M})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1202 @deftypefnx {} {@var{v} =} diag (@var{M}, @var{k})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1203 Return a diagonal matrix with vector @var{v} on diagonal @var{k}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1204
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1205 The second argument is optional. If it is positive, the vector is placed on
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1206 the @var{k}-th superdiagonal. If it is negative, it is placed on the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1207 @var{-k}-th subdiagonal. The default value of @var{k} is 0, and the vector
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1208 is placed on the main diagonal. For example:
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1209
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1210 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1211 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1212 diag ([1, 2, 3], 1)
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1213 @result{} 0 1 0 0
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1214 0 0 2 0
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1215 0 0 0 3
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1216 0 0 0 0
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1217 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1218 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1219
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1220 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1221 The 3-input form returns a diagonal matrix with vector @var{v} on the main
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1222 diagonal and the resulting matrix being of size @var{m} rows x @var{n}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1223 columns.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1224
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1225 Given a matrix argument, instead of a vector, @code{diag} extracts the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1226 @var{k}-th diagonal of the matrix.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1227 @end deftypefn */)
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1228 {
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1229 int nargin = args.length ();
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1230
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1231 if (nargin < 1 || nargin > 3)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1232 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1233
4233
ccfdb55c8156 [project @ 2002-12-20 22:43:54 by jwe]
jwe
parents: 4176
diff changeset
1234 octave_value retval;
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1235
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1236 if (nargin == 1)
14843
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1237 retval = args(0).diag ();
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1238 else if (nargin == 2)
7620
36594d5bbe13 Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents: 7618
diff changeset
1239 {
21041
63374982750b Usage of corresponding value extractor for octave_idx_type. Improves support
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 21014
diff changeset
1240 octave_idx_type k = args(1).xidx_type_value ("diag: invalid argument K");
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20700
diff changeset
1241
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20700
diff changeset
1242 retval = args(0).diag (k);
7620
36594d5bbe13 Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents: 7618
diff changeset
1243 }
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1244 else
12570
1a93988610a3 Reverse changset cc8ccdfec424. Restore 3-input form of diag().
Rik <octave@nomad.inbox5.com>
parents: 12567
diff changeset
1245 {
1a93988610a3 Reverse changset cc8ccdfec424. Restore 3-input form of diag().
Rik <octave@nomad.inbox5.com>
parents: 12567
diff changeset
1246 octave_value arg0 = args(0);
14557
e8e86ae3abbc make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents: 14521
diff changeset
1247
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1248 if (arg0.ndims () != 2 || (arg0.rows () != 1 && arg0.columns () != 1))
12570
1a93988610a3 Reverse changset cc8ccdfec424. Restore 3-input form of diag().
Rik <octave@nomad.inbox5.com>
parents: 12567
diff changeset
1249 error ("diag: V must be a vector");
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1250
27325
983dab0902f7 More explicit error messages for invalid 2nd and 3rd inputs to diag().
Rik <rik@octave.org>
parents: 27324
diff changeset
1251 octave_idx_type m = args(1).xidx_type_value ("diag: invalid dimension M");
983dab0902f7 More explicit error messages for invalid 2nd and 3rd inputs to diag().
Rik <rik@octave.org>
parents: 27324
diff changeset
1252 octave_idx_type n = args(2).xidx_type_value ("diag: invalid dimension N");
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1253
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1254 retval = arg0.diag (m, n);
12570
1a93988610a3 Reverse changset cc8ccdfec424. Restore 3-input form of diag().
Rik <octave@nomad.inbox5.com>
parents: 12567
diff changeset
1255 }
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1256
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1257 return retval;
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1258 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1259
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
1260 /*
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
1261
14843
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1262 %!assert (full (diag ([1; 2; 3])), [1, 0, 0; 0, 2, 0; 0, 0, 3])
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1263 %!assert (diag ([1; 2; 3], 1), [0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0])
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1264 %!assert (diag ([1; 2; 3], 2),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1265 %! [0 0 1 0 0; 0 0 0 2 0; 0 0 0 0 3; 0 0 0 0 0; 0 0 0 0 0])
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1266 %!assert (diag ([1; 2; 3],-1),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1267 %! [0 0 0 0; 1 0 0 0; 0 2 0 0; 0 0 3 0])
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1268 %!assert (diag ([1; 2; 3],-2),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1269 %! [0 0 0 0 0; 0 0 0 0 0; 1 0 0 0 0; 0 2 0 0 0; 0 0 3 0 0])
14843
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1270
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1271 %!assert (diag ([1, 0, 0; 0, 2, 0; 0, 0, 3]), [1; 2; 3])
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1272 %!assert (diag ([0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0], 1),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1273 %! [1; 2; 3])
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1274 %!assert (diag ([0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0], -1),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1275 %! [1; 2; 3])
14843
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1276 %!assert (diag (ones (1, 0), 2), zeros (2))
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1277 %!assert (diag (1:3, 4, 2), [1, 0; 0, 2; 0, 0; 0, 0])
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1278
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1279 %!assert (full (diag (single ([1; 2; 3]))),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1280 %! single ([1, 0, 0; 0, 2, 0; 0, 0, 3]))
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1281 %!assert (diag (single ([1; 2; 3]), 1),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1282 %! single ([0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0]))
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1283 %!assert (diag (single ([1; 2; 3]), 2),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1284 %! single ([0 0 1 0 0; 0 0 0 2 0; 0 0 0 0 3; 0 0 0 0 0; 0 0 0 0 0]))
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1285 %!assert (diag (single ([1; 2; 3]),-1),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1286 %! single ([0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0]))
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1287 %!assert (diag (single ([1; 2; 3]),-2),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1288 %! single ([0 0 0 0 0; 0 0 0 0 0; 1 0 0 0 0; 0 2 0 0 0; 0 0 3 0 0]))
14843
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1289
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1290 %!assert (diag (single ([1, 0, 0; 0, 2, 0; 0, 0, 3])), single ([1; 2; 3]))
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1291 %!assert (diag (single ([0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0]), 1),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1292 %! single ([1; 2; 3]))
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1293 %!assert (diag (single ([0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0]), -1),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1294 %! single ([1; 2; 3]))
14843
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1295
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1296 %!assert (diag (int8 ([1; 2; 3])), int8 ([1, 0, 0; 0, 2, 0; 0, 0, 3]))
30402
1ef9fca2db06 maint: strip trailing spaces from codebase.
Rik <rik@octave.org>
parents: 30391
diff changeset
1297 %!assert (diag (int8 ([1; 2; 3]), 1),
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1298 %! int8 ([0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0]))
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1299 %!assert (diag (int8 ([1; 2; 3]), 2),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1300 %! int8 ([0 0 1 0 0; 0 0 0 2 0; 0 0 0 0 3; 0 0 0 0 0; 0 0 0 0 0]))
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1301 %!assert (diag (int8 ([1; 2; 3]),-1),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1302 %! int8 ([0 0 0 0; 1 0 0 0; 0 2 0 0; 0 0 3 0]))
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1303 %!assert (diag (int8 ([1; 2; 3]),-2),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1304 %! int8 ([0 0 0 0 0; 0 0 0 0 0; 1 0 0 0 0; 0 2 0 0 0; 0 0 3 0 0]))
14843
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1305
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1306 %!assert (diag (int8 ([1, 0, 0; 0, 2, 0; 0, 0, 3])), int8 ([1; 2; 3]))
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1307 %!assert (diag (int8 ([0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0]), 1),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1308 %! int8 ([1; 2; 3]))
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1309 %!assert (diag (int8 ([0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0]), -1),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1310 %! int8 ([1; 2; 3]))
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
1311
27325
983dab0902f7 More explicit error messages for invalid 2nd and 3rd inputs to diag().
Rik <rik@octave.org>
parents: 27324
diff changeset
1312 %!assert (diag (1, 3, 3), diag ([1, 0, 0]))
983dab0902f7 More explicit error messages for invalid 2nd and 3rd inputs to diag().
Rik <rik@octave.org>
parents: 27324
diff changeset
1313 %!assert (diag (i, 3, 3), diag ([i, 0, 0]))
983dab0902f7 More explicit error messages for invalid 2nd and 3rd inputs to diag().
Rik <rik@octave.org>
parents: 27324
diff changeset
1314 %!assert (diag (single (1), 3, 3), diag ([single(1), 0, 0]))
983dab0902f7 More explicit error messages for invalid 2nd and 3rd inputs to diag().
Rik <rik@octave.org>
parents: 27324
diff changeset
1315 %!assert (diag (single (i), 3, 3), diag ([single(i), 0, 0]))
983dab0902f7 More explicit error messages for invalid 2nd and 3rd inputs to diag().
Rik <rik@octave.org>
parents: 27324
diff changeset
1316 %!assert (diag ([1, 2], 3, 3), diag ([1, 2, 0]))
983dab0902f7 More explicit error messages for invalid 2nd and 3rd inputs to diag().
Rik <rik@octave.org>
parents: 27324
diff changeset
1317 %!assert (diag ([1, 2]*i, 3, 3), diag ([1, 2, 0]*i))
983dab0902f7 More explicit error messages for invalid 2nd and 3rd inputs to diag().
Rik <rik@octave.org>
parents: 27324
diff changeset
1318 %!assert (diag (single ([1, 2]), 3, 3), diag (single ([1, 2, 0])))
983dab0902f7 More explicit error messages for invalid 2nd and 3rd inputs to diag().
Rik <rik@octave.org>
parents: 27324
diff changeset
1319 %!assert (diag (single ([1, 2]*i), 3, 3), diag (single ([1, 2, 0]*i)))
983dab0902f7 More explicit error messages for invalid 2nd and 3rd inputs to diag().
Rik <rik@octave.org>
parents: 27324
diff changeset
1320
23573
1b4f4ec53b4a use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents: 23572
diff changeset
1321 %!assert <*37411> (diag (diag ([5, 2, 3])(:,1)), diag([5 0 0 ]))
1b4f4ec53b4a use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents: 23572
diff changeset
1322 %!assert <*37411> (diag (diag ([5, 2, 3])(:,1), 2), [0 0 5 0 0; zeros(4, 5)])
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1323 %!assert <*37411> (diag (diag ([5, 2, 3])(:,1), -2),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1324 %! [[0 0 5 0 0]', zeros(5, 4)])
15428
fd5c0159b588 Fix diag handling of diagvectors (bug #37411)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14567
diff changeset
1325
14490
3959f3f81e33 Initialise memory in non-square diag call (bug #35946)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14171
diff changeset
1326 ## Test non-square size
14843
7d4f87c75dbb data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents: 14635
diff changeset
1327 %!assert (diag ([1,2,3], 6, 3), [1 0 0; 0 2 0; 0 0 3; 0 0 0; 0 0 0; 0 0 0])
21317
a4faec57f4c8 maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents: 21301
diff changeset
1328 %!assert (diag (1, 2, 3), [1,0,0; 0,0,0])
a4faec57f4c8 maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents: 21301
diff changeset
1329 %!assert (diag ({1}, 2, 3), {1,[],[]; [],[],[]})
a4faec57f4c8 maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents: 21301
diff changeset
1330 %!assert (diag ({1,2}, 3, 4), {1,[],[],[]; [],2,[],[]; [],[],[],[]})
27323
1582a6140275 Stop segfault when calling 3-input form of diag with cell arrays (bug #56711).
Rik <rik@octave.org>
parents: 27081
diff changeset
1331 %!assert <*56711> (diag ({1,2,3}, 2, 1), {1; []})
14490
3959f3f81e33 Initialise memory in non-square diag call (bug #35946)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14171
diff changeset
1332
18146
a86d608c413c Return empty matrix rather than issuing error when requested diagonal is out of range.
Marco Caliari <marco.caliari@univr.it>
parents: 18112
diff changeset
1333 ## Test out-of-range diagonals
a86d608c413c Return empty matrix rather than issuing error when requested diagonal is out of range.
Marco Caliari <marco.caliari@univr.it>
parents: 18112
diff changeset
1334 %!assert (diag (ones (3,3), 4), zeros (0, 1))
a86d608c413c Return empty matrix rather than issuing error when requested diagonal is out of range.
Marco Caliari <marco.caliari@univr.it>
parents: 18112
diff changeset
1335 %!assert (diag (cell (3,3), 4), cell (0, 1))
a86d608c413c Return empty matrix rather than issuing error when requested diagonal is out of range.
Marco Caliari <marco.caliari@univr.it>
parents: 18112
diff changeset
1336 %!assert (diag (sparse (ones (3,3)), 4), sparse (zeros (0, 1)))
a86d608c413c Return empty matrix rather than issuing error when requested diagonal is out of range.
Marco Caliari <marco.caliari@univr.it>
parents: 18112
diff changeset
1337
22737
7abc25e6206a maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22708
diff changeset
1338 ## Test input validation
14491
5bd9e47e9277 maint: periodic merge of stable to default
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14429 14490
diff changeset
1339 %!error <Invalid call to diag> diag ()
5bd9e47e9277 maint: periodic merge of stable to default
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14429 14490
diff changeset
1340 %!error <Invalid call to diag> diag (1,2,3,4)
27325
983dab0902f7 More explicit error messages for invalid 2nd and 3rd inputs to diag().
Rik <rik@octave.org>
parents: 27324
diff changeset
1341 %!error <V must be a vector> diag (ones (2), 3, 3)
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1342 %!error diag (1:3, -4, 3)
27325
983dab0902f7 More explicit error messages for invalid 2nd and 3rd inputs to diag().
Rik <rik@octave.org>
parents: 27324
diff changeset
1343 %!error diag (1:3, 4, -3)
983dab0902f7 More explicit error messages for invalid 2nd and 3rd inputs to diag().
Rik <rik@octave.org>
parents: 27324
diff changeset
1344
14557
e8e86ae3abbc make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents: 14521
diff changeset
1345 */
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
1346
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1940
diff changeset
1347 DEFUN (prod, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1348 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
1349 @deftypefn {} {@var{y} =} prod (@var{x})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
1350 @deftypefnx {} {@var{y} =} prod (@var{x}, @var{dim})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
1351 @deftypefnx {} {@var{y} =} prod (@dots{}, "native")
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
1352 @deftypefnx {} {@var{y} =} prod (@dots{}, "double")
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1353 Product of elements along dimension @var{dim}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1354
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1355 If @var{dim} is omitted, it defaults to the first non-singleton dimension.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1356
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1357 The optional @qcode{"type"} input determines the class of the variable
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1358 used for calculations. If the argument @qcode{"native"} is given, then
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1359 the operation is performed in the same type as the original argument, rather
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1360 than the default double type.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1361
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1362 For example:
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1363
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1364 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1365 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1366 prod ([true, true])
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1367 @result{} 1
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1368 prod ([true, true], "native")
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1369 @result{} true
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1370 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1371 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1372
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1373 On the contrary, if @qcode{"double"} is given, the operation is performed
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1374 in double precision even for single precision inputs.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1375 @seealso{cumprod, sum}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
1376 @end deftypefn */)
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1377 {
18725
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1378 int nargin = args.length ();
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1379
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1380 bool isnative = false;
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1381 bool isdouble = false;
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1382
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1383 if (nargin > 1 && args(nargin - 1).is_string ())
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1384 {
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1385 std::string str = args(nargin - 1).string_value ();
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1386
19743
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
1387 if (str == "native")
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
1388 isnative = true;
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
1389 else if (str == "double")
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
1390 isdouble = true;
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
1391 else
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
1392 error ("prod: unrecognized type argument '%s'", str.c_str ());
21055
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
1393
21062
d9c1884d1aaa maint: Eliminate space between variable and decrement '--' operator.
Rik <rik@octave.org>
parents: 21055
diff changeset
1394 nargin--;
18725
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1395 }
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1396
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1397 if (nargin < 1 || nargin > 2)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1398 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1399
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
1400 octave_value retval;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
1401
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1402 octave_value arg = args(0);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1403
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1404 int dim = -1;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1405 if (nargin == 2)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1406 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1407 dim = args(1).int_value () - 1;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1408 if (dim < 0)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1409 error ("prod: invalid dimension DIM = %d", dim + 1);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1410 }
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1411
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1412 switch (arg.builtin_type ())
18725
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1413 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1414 case btyp_double:
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
1415 if (arg.issparse ())
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1416 retval = arg.sparse_matrix_value ().prod (dim);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1417 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1418 retval = arg.array_value ().prod (dim);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1419 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1420 case btyp_complex:
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
1421 if (arg.issparse ())
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1422 retval = arg.sparse_complex_matrix_value ().prod (dim);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1423 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1424 retval = arg.complex_array_value ().prod (dim);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1425 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1426 case btyp_float:
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1427 if (isdouble)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1428 retval = arg.float_array_value ().dprod (dim);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1429 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1430 retval = arg.float_array_value ().prod (dim);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1431 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1432 case btyp_float_complex:
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1433 if (isdouble)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1434 retval = arg.float_complex_array_value ().dprod (dim);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1435 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1436 retval = arg.float_complex_array_value ().prod (dim);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1437 break;
18725
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1438
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
1439 #define MAKE_INT_BRANCH(X) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
1440 case btyp_ ## X: \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
1441 if (isnative) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
1442 retval = arg.X ## _array_value ().prod (dim); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
1443 else \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
1444 retval = arg.array_value ().prod (dim); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
1445 break;
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1446
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1447 MAKE_INT_BRANCH (int8);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1448 MAKE_INT_BRANCH (int16);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1449 MAKE_INT_BRANCH (int32);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1450 MAKE_INT_BRANCH (int64);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1451 MAKE_INT_BRANCH (uint8);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1452 MAKE_INT_BRANCH (uint16);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1453 MAKE_INT_BRANCH (uint32);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1454 MAKE_INT_BRANCH (uint64);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1455
18725
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1456 #undef MAKE_INT_BRANCH
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1457
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
1458 // GAGME: Accursed Matlab compatibility...
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1459 case btyp_char:
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1460 retval = arg.array_value (true).prod (dim);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1461 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1462
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1463 case btyp_bool:
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
1464 if (arg.issparse ())
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1465 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1466 if (isnative)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1467 retval = arg.sparse_bool_matrix_value ().all (dim);
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1468 else
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1469 retval = arg.sparse_matrix_value ().prod (dim);
18725
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1470 }
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1471 else if (isnative)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1472 retval = arg.bool_array_value ().all (dim);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1473 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1474 retval = NDArray (arg.bool_array_value ().all (dim));
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1475 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1476
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
1477 default:
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21078
diff changeset
1478 err_wrong_type_arg ("prod", arg);
18725
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1479 }
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1480
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1481 return retval;
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1482 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1483
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1484 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1485 %!assert (prod ([1, 2, 3]), 6)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1486 %!assert (prod ([-1; -2; -3]), -6)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1487 %!assert (prod ([i, 2+i, -3+2i, 4]), -4 - 32i)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1488 %!assert (prod ([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i]), [-1+i, -8+8i, -27+27i])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1489
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1490 %!assert (prod (single ([1, 2, 3])), single (6))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1491 %!assert (prod (single ([-1; -2; -3])), single (-6))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1492 %!assert (prod (single ([i, 2+i, -3+2i, 4])), single (-4 - 32i))
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1493 %!assert (prod (single ([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i])),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1494 %! single ([-1+i, -8+8i, -27+27i]))
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1495
22737
7abc25e6206a maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22708
diff changeset
1496 ## Test sparse
18725
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1497 %!assert (prod (sparse ([1, 2, 3])), sparse (6))
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1498 %!assert (prod (sparse ([-1; -2; -3])), sparse (-6))
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1499 ## Commented out until bug #42290 is fixed
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1500 #%!assert (prod (sparse ([i, 2+i, -3+2i, 4])), sparse (-4 - 32i))
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1501 #%!assert (prod (sparse ([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i])),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1502 #%! sparse ([-1+i, -8+8i, -27+27i]))
18725
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1503
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1504 %!assert (prod ([1, 2; 3, 4], 1), [3, 8])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1505 %!assert (prod ([1, 2; 3, 4], 2), [2; 12])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1506 %!assert (prod (zeros (1, 0)), 1)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1507 %!assert (prod (zeros (1, 0), 1), zeros (1, 0))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1508 %!assert (prod (zeros (1, 0), 2), 1)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1509 %!assert (prod (zeros (0, 1)), 1)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1510 %!assert (prod (zeros (0, 1), 1), 1)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1511 %!assert (prod (zeros (0, 1), 2), zeros (0, 1))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1512 %!assert (prod (zeros (2, 0)), zeros (1, 0))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1513 %!assert (prod (zeros (2, 0), 1), zeros (1, 0))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1514 %!assert (prod (zeros (2, 0), 2), [1; 1])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1515 %!assert (prod (zeros (0, 2)), [1, 1])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1516 %!assert (prod (zeros (0, 2), 1), [1, 1])
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1517 %!assert (prod (zeros (0, 2), 2), zeros (0, 1))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1518
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1519 %!assert (prod (single ([1, 2; 3, 4]), 1), single ([3, 8]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1520 %!assert (prod (single ([1, 2; 3, 4]), 2), single ([2; 12]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1521 %!assert (prod (zeros (1, 0, "single")), single (1))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1522 %!assert (prod (zeros (1, 0, "single"), 1), zeros (1, 0, "single"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1523 %!assert (prod (zeros (1, 0, "single"), 2), single (1))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1524 %!assert (prod (zeros (0, 1, "single")), single (1))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1525 %!assert (prod (zeros (0, 1, "single"), 1), single (1))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1526 %!assert (prod (zeros (0, 1, "single"), 2), zeros (0, 1, "single"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1527 %!assert (prod (zeros (2, 0, "single")), zeros (1, 0, "single"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1528 %!assert (prod (zeros (2, 0, "single"), 1), zeros (1, 0, "single"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1529 %!assert (prod (zeros (2, 0, "single"), 2), single ([1; 1]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1530 %!assert (prod (zeros (0, 2, "single")), single ([1, 1]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1531 %!assert (prod (zeros (0, 2, "single"), 1), single ([1, 1]))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1532 %!assert (prod (zeros (0, 2, "single"), 2), zeros (0, 1, "single"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1533
22737
7abc25e6206a maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22708
diff changeset
1534 ## Test "double" type argument
18725
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1535 %!assert (prod (single ([1, 2, 3]), "double"), 6)
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1536 %!assert (prod (single ([-1; -2; -3]), "double"), -6)
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1537 %!assert (prod (single ([i, 2+i, -3+2i, 4]), "double"), -4 - 32i)
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1538 %!assert (prod (single ([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i]), "double"),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
1539 %! [-1+i, -8+8i, -27+27i])
18725
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1540
22737
7abc25e6206a maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22708
diff changeset
1541 ## Test "native" type argument
18725
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1542 %!assert (prod (uint8 ([1, 2, 3]), "native"), uint8 (6))
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1543 %!assert (prod (uint8 ([-1; -2; -3]), "native"), uint8 (0))
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1544 %!assert (prod (int8 ([1, 2, 3]), "native"), int8 (6))
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1545 %!assert (prod (int8 ([-1; -2; -3]), "native"), int8 (-6))
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1546 %!assert (prod ([true false; true true], "native"), [true false])
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1547 %!assert (prod ([true false; true true], 2, "native"), [false; true])
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1548
22737
7abc25e6206a maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22708
diff changeset
1549 ## Test input validation
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1550 %!error prod ()
18725
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1551 %!error prod (1,2,3)
8cc66f091584 Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents: 18679
diff changeset
1552 %!error <unrecognized type argument 'foobar'> prod (1, "foobar")
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
1553 */
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
1554
10758
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1555 static bool
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1556 all_scalar_1x1 (const octave_value_list& args)
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1557 {
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1558 int n_args = args.length ();
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1559 for (int i = 0; i < n_args; i++)
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1560 if (args(i).numel () != 1)
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1561 return false;
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1562
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1563 return true;
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1564 }
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1565
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
1566 template <typename TYPE, typename T>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
1567 static void
10533
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10498
diff changeset
1568 single_type_concat (Array<T>& result,
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10498
diff changeset
1569 const octave_value_list& args,
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10498
diff changeset
1570 int dim)
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10498
diff changeset
1571 {
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10498
diff changeset
1572 int n_args = args.length ();
10758
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1573 if (! (equal_types<T, char>::value
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1574 || equal_types<T, octave_value>::value)
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1575 && all_scalar_1x1 (args))
10533
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10498
diff changeset
1576 {
10758
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1577 // Optimize all scalars case.
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1578 dim_vector dv (1, 1);
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1579 if (dim == -1 || dim == -2)
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1580 dim = -dim - 1;
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1581 else if (dim >= 2)
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1582 dv.resize (dim+1, 1);
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1583 dv(dim) = n_args;
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1584
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1585 result.clear (dv);
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1586
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1587 for (int j = 0; j < n_args; j++)
10758
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1588 {
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1589 octave_quit ();
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1590
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1591 result(j) = octave_value_extract<T> (args(j));
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1592 }
10533
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10498
diff changeset
1593 }
10758
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1594 else
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1595 {
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1596 OCTAVE_LOCAL_BUFFER (Array<T>, array_list, n_args);
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1597
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1598 for (int j = 0; j < n_args; j++)
10758
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1599 {
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1600 octave_quit ();
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1601
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1602 array_list[j] = octave_value_extract<TYPE> (args(j));
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1603 }
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1604
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1605 result = Array<T>::cat (dim, n_args, array_list);
10758
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1606 }
10533
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10498
diff changeset
1607 }
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10498
diff changeset
1608
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
1609 template <typename TYPE, typename T>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
1610 static void
10533
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10498
diff changeset
1611 single_type_concat (Sparse<T>& result,
10498
8615b55b5caf fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents: 10436
diff changeset
1612 const octave_value_list& args,
8615b55b5caf fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents: 10436
diff changeset
1613 int dim)
8615b55b5caf fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents: 10436
diff changeset
1614 {
10533
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10498
diff changeset
1615 int n_args = args.length ();
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1616 OCTAVE_LOCAL_BUFFER (Sparse<T>, sparse_list, n_args);
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1617
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1618 for (int j = 0; j < n_args; j++)
10498
8615b55b5caf fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents: 10436
diff changeset
1619 {
8615b55b5caf fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents: 10436
diff changeset
1620 octave_quit ();
8615b55b5caf fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents: 10436
diff changeset
1621
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1622 sparse_list[j] = octave_value_extract<TYPE> (args(j));
10498
8615b55b5caf fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents: 10436
diff changeset
1623 }
10533
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10498
diff changeset
1624
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1625 result = Sparse<T>::cat (dim, n_args, sparse_list);
10498
8615b55b5caf fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents: 10436
diff changeset
1626 }
8615b55b5caf fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents: 10436
diff changeset
1627
10533
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10498
diff changeset
1628 // Dispatcher.
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
1629 template <typename TYPE>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
1630 static TYPE
10533
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10498
diff changeset
1631 do_single_type_concat (const octave_value_list& args, int dim)
10498
8615b55b5caf fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents: 10436
diff changeset
1632 {
10533
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10498
diff changeset
1633 TYPE result;
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10498
diff changeset
1634
f094ac9bc93e reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10498
diff changeset
1635 single_type_concat<TYPE, typename TYPE::element_type> (result, args, dim);
10498
8615b55b5caf fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents: 10436
diff changeset
1636
8615b55b5caf fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents: 10436
diff changeset
1637 return result;
8615b55b5caf fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents: 10436
diff changeset
1638 }
8615b55b5caf fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents: 10436
diff changeset
1639
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
1640 template <typename MAP>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
1641 static void
10758
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1642 single_type_concat_map (octave_map& result,
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1643 const octave_value_list& args,
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1644 int dim)
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1645 {
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1646 int n_args = args.length ();
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1647 OCTAVE_LOCAL_BUFFER (MAP, map_list, n_args);
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1648
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1649 for (int j = 0; j < n_args; j++)
10758
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1650 {
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1651 octave_quit ();
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1652
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1653 map_list[j] = octave_value_extract<MAP> (args(j));
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1654 }
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1655
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
1656 result = octave_map::cat (dim, n_args, map_list);
10758
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1657 }
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1658
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1659 static octave_map
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1660 do_single_type_concat_map (const octave_value_list& args,
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1661 int dim)
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1662 {
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1663 octave_map result;
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1664 if (all_scalar_1x1 (args)) // optimize all scalars case.
10763
b397b8edd8c5 fix off-by-1 dim in scalar map horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents: 10758
diff changeset
1665 single_type_concat_map<octave_scalar_map> (result, args, dim);
10758
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1666 else
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1667 single_type_concat_map<octave_map> (result, args, dim);
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1668
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1669 return result;
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1670 }
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1671
4824
4829055e154f [project @ 2004-03-08 18:16:04 by jwe]
jwe
parents: 4806
diff changeset
1672 static octave_value
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1673 attempt_type_conversion (const octave_value& ov, std::string dtype)
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1674 {
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1675 octave_value retval;
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1676
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1677 // First try to find function in the class of OV that can convert to
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1678 // the dispatch type dtype. It will have the name of the dispatch
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1679 // type.
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1680
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1681 std::string cname = ov.class_name ();
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1682
31730
610a85b0ff62 use interpreter::feval instead of global feval function
John W. Eaton <jwe@octave.org>
parents: 31707
diff changeset
1683 interpreter& interp = __get_interpreter__ ();
610a85b0ff62 use interpreter::feval instead of global feval function
John W. Eaton <jwe@octave.org>
parents: 31707
diff changeset
1684
610a85b0ff62 use interpreter::feval instead of global feval function
John W. Eaton <jwe@octave.org>
parents: 31707
diff changeset
1685 symbol_table& symtab = interp.get_symbol_table ();
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23592
diff changeset
1686
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23592
diff changeset
1687 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
1688
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1689 if (fcn.is_defined ())
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1690 {
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20726
diff changeset
1691 octave_value_list result;
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20726
diff changeset
1692
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20726
diff changeset
1693 try
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20726
diff changeset
1694 {
31730
610a85b0ff62 use interpreter::feval instead of global feval function
John W. Eaton <jwe@octave.org>
parents: 31707
diff changeset
1695 result = interp.feval (fcn, ovl (ov), 1);
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20726
diff changeset
1696 }
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
1697 catch (execution_exception& ee)
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20726
diff changeset
1698 {
29163
8f67ad8b3103 maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents: 29117
diff changeset
1699 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
1700 cname.c_str ());
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20726
diff changeset
1701 }
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20726
diff changeset
1702
21885
0806871e3e1e maint: Prefer is_empty() rather than "length () == 0".
Rik <rik@octave.org>
parents: 21782
diff changeset
1703 if (result.empty ())
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1704 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
1705 cname.c_str ());
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1706
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1707 retval = result(0);
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1708 }
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1709 else
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1710 {
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1711 // 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
1712 // dispatch type.
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1713
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23592
diff changeset
1714 fcn = symtab.find_method (dtype, dtype);
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1715
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
1716 if (! fcn.is_defined ())
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
1717 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
1718
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
1719 octave_value_list result;
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
1720
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
1721 try
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1722 {
31730
610a85b0ff62 use interpreter::feval instead of global feval function
John W. Eaton <jwe@octave.org>
parents: 31707
diff changeset
1723 result = interp.feval (fcn, ovl (ov), 1);
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
1724 }
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
1725 catch (execution_exception& ee)
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
1726 {
29163
8f67ad8b3103 maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents: 29117
diff changeset
1727 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
1728 cname.c_str ());
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1729 }
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
1730
21885
0806871e3e1e maint: Prefer is_empty() rather than "length () == 0".
Rik <rik@octave.org>
parents: 21782
diff changeset
1731 if (result.empty ())
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
1732 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
1733 cname.c_str ());
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1734
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1735 retval = result(0);
13294
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
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1738 return retval;
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
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1741 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
1742 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
1743 const std::string& cattype, int dim)
4806
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1744 {
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1745 octave_value retval;
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1746
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1747 // Get dominant type for list
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1748
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
1749 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
1750
31730
610a85b0ff62 use interpreter::feval instead of global feval function
John W. Eaton <jwe@octave.org>
parents: 31707
diff changeset
1751 interpreter& interp = __get_interpreter__ ();
610a85b0ff62 use interpreter::feval instead of global feval function
John W. Eaton <jwe@octave.org>
parents: 31707
diff changeset
1752
610a85b0ff62 use interpreter::feval instead of global feval function
John W. Eaton <jwe@octave.org>
parents: 31707
diff changeset
1753 symbol_table& symtab = interp.get_symbol_table ();
23599
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23592
diff changeset
1754
5cb3a2bb5e1e don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents: 23592
diff changeset
1755 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
1756
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1757 if (fcn.is_defined ())
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1758 {
20726
25d676f9619c Preface error() messages with name of function when possible.
Rik <rik@octave.org>
parents: 20720
diff changeset
1759 // 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
1760
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20726
diff changeset
1761 octave_value_list tmp2;
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20726
diff changeset
1762
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20726
diff changeset
1763 try
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1764 {
31730
610a85b0ff62 use interpreter::feval instead of global feval function
John W. Eaton <jwe@octave.org>
parents: 31707
diff changeset
1765 tmp2 = interp.feval (fcn, ovl, 1);
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20726
diff changeset
1766 }
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
1767 catch (execution_exception& ee)
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20726
diff changeset
1768 {
29163
8f67ad8b3103 maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents: 29117
diff changeset
1769 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
1770 }
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1771
21885
0806871e3e1e maint: Prefer is_empty() rather than "length () == 0".
Rik <rik@octave.org>
parents: 21782
diff changeset
1772 if (tmp2.empty ())
20741
a5ab31b52ae8 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20726
diff changeset
1773 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
1774 cattype.c_str ());
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1775
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
1776 retval = tmp2(0);
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1777 }
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1778 else
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1779 {
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1780 // 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
1781 // 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
1782 // default operation for octave_class values.
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1783
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1784 octave_idx_type j = 0;
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1785 octave_idx_type len = ovl.length ();
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1786 octave_value_list tmp (len, octave_value ());
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1787 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
1788 {
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1789 octave_value elt = ovl(k);
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1790
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1791 std::string t1_type = elt.class_name ();
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1792
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1793 if (t1_type == dtype)
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1794 tmp(j++) = elt;
23587
0c468af9dc00 maint: Deprecate is_object and replace with isobject.
Rik <rik@octave.org>
parents: 23586
diff changeset
1795 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
1796 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
1797 }
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1798
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1799 tmp.resize (j);
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1800
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1801 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
1802
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1803 std::string cname = tmp(0).class_name ();
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1804 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
1805
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1806 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
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 return retval;
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1810 }
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1811
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1812 static octave_value
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1813 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
1814 {
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1815 octave_value retval;
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1816
20811
5979314bb15a Fix BIST tests for rows.
Rik <rik@octave.org>
parents: 20810
diff changeset
1817 // 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
1818 // 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
1819 // counts.
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1820 octave_value_list args = xargs;
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1821
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
1822 int n_args = args.length ();
4806
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1823
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1824 if (n_args == 0)
5714
24f6a13878c2 [project @ 2006-03-23 21:46:09 by jwe]
jwe
parents: 5677
diff changeset
1825 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
1826 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
1827 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
1828 else if (n_args > 1)
4824
4829055e154f [project @ 2004-03-08 18:16:04 by jwe]
jwe
parents: 4806
diff changeset
1829 {
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1830 std::string result_type;
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1831
19399
2304ddfd736f Restore warning Octave:num-to-str missing since 3.2.4 (bug #43814).
Rik <rik@octave.org>
parents: 18869
diff changeset
1832 bool all_strings_p = true;
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1833 bool all_sq_strings_p = true;
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1834 bool all_dq_strings_p = true;
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1835 bool all_real_p = true;
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1836 bool all_cmplx_p = true;
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1837 bool any_sparse_p = false;
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1838 bool any_cell_p = false;
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1839 bool any_class_p = false;
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1840
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1841 bool first_elem_is_struct = false;
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1842
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1843 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
1844 {
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1845 if (i == 0)
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1846 {
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1847 result_type = args(i).class_name ();
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1848
23584
7ed6b258db91 maint: Deprecate is_map and replace with isstruct.
Rik <rik@octave.org>
parents: 23583
diff changeset
1849 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
1850 }
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1851 else
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
1852 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
1853
19399
2304ddfd736f Restore warning Octave:num-to-str missing since 3.2.4 (bug #43814).
Rik <rik@octave.org>
parents: 18869
diff changeset
1854 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
1855 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
1856 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
1857 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
1858 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
1859 all_dq_strings_p = false;
23582
0cc2011d800e maint: Deprecate is_real_type and replace with isreal.
Rik <rik@octave.org>
parents: 23581
diff changeset
1860 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
1861 all_real_p = false;
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
1862 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
1863 || args(i).isreal ()))
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1864 all_cmplx_p = false;
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
1865 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
1866 any_sparse_p = true;
23576
00e518162fda maint: Deprecate is_cell and replace with iscell.
Rik <rik@octave.org>
parents: 23575
diff changeset
1867 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
1868 any_cell_p = true;
23587
0c468af9dc00 maint: Deprecate is_object and replace with isobject.
Rik <rik@octave.org>
parents: 23586
diff changeset
1869 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
1870 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
1871 }
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1872
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1873 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
1874 {
22895
0ab9eecbb165 Concatenate empty matrices/cells in cat() the same as the parser (bug #49759).
Rik <rik@octave.org>
parents: 22853
diff changeset
1875 int j = 0;
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1876 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
1877 {
23576
00e518162fda maint: Deprecate is_cell and replace with iscell.
Rik <rik@octave.org>
parents: 23575
diff changeset
1878 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
1879 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
1880 else
0ab9eecbb165 Concatenate empty matrices/cells in cat() the same as the parser (bug #49759).
Rik <rik@octave.org>
parents: 22853
diff changeset
1881 {
23577
80c42f4cca13 maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents: 23576
diff changeset
1882 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
1883 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
1884 else
0ab9eecbb165 Concatenate empty matrices/cells in cat() the same as the parser (bug #49759).
Rik <rik@octave.org>
parents: 22853
diff changeset
1885 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
1886 }
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1887 }
22895
0ab9eecbb165 Concatenate empty matrices/cells in cat() the same as the parser (bug #49759).
Rik <rik@octave.org>
parents: 22853
diff changeset
1888 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
1889 args.resize (n_args);
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1890 }
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1891
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1892 if (any_class_p)
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1893 {
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
1894 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
1895 }
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
1896 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
1897 {
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1898 if (any_sparse_p)
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
1899 {
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1900 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
1901 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
1902 else
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1903 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
1904 }
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 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1906 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1907 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
1908 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
1909 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
1910 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
1911 }
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1912 }
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1913 else 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
1914 {
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1915 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
1916 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
1917 else
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1918 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
1919 }
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1920 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
1921 {
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23449
diff changeset
1922 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
1923
19399
2304ddfd736f Restore warning Octave:num-to-str missing since 3.2.4 (bug #43814).
Rik <rik@octave.org>
parents: 18869
diff changeset
1924 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
1925 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
1926 "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
1927 else
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
1928 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
1929
2304ddfd736f Restore warning Octave:num-to-str missing since 3.2.4 (bug #43814).
Rik <rik@octave.org>
parents: 18869
diff changeset
1930 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
1931
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1932 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
1933 }
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1934 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
1935 {
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1936 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
1937 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
1938 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
1939 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
1940 }
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1941 else if (result_type == "int8")
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1942 retval = do_single_type_concat<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
1943 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
1944 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
1945 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
1946 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
1947 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
1948 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
1949 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
1950 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
1951 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
1952 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
1953 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
1954 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
1955 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
1956 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
1957 else if (result_type == "cell")
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1958 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
1959 else if (result_type == "struct")
f3892d8eea9f optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents: 10716
diff changeset
1960 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
1961 else
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1962 {
20218
b2100e1659ac maint: Use cuddled parentheses when indexing dimension_vectors.
Rik <rik@octave.org>
parents: 20183
diff changeset
1963 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
1964
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1965 // Default concatenation.
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1966 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
1967 = &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
1968
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1969 if (dim == -1 || dim == -2)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
1970 {
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1971 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
1972 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
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
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1975 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
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 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
1978 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
1979 }
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1980
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1981 // 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
1982 // 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
1983 // 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
1984 // 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
1985 // 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
1986 // 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
1987 // 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
1988 //
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
1989 // 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
1990 //
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
1991 // 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
1992 //
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21730
diff changeset
1993 // 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
1994 // 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
1995
18112
b560bac0fca2 maint: Don't use space between 'args' and '(' when doing indexing.
Rik <rik@octave.org>
parents: 18100
diff changeset
1996 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
1997 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
1998
21660
53728df3e4c9 maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents: 21602
diff changeset
1999 int dv_len = dv.ndims ();
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
2000 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
2001
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
2002 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
2003 {
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
2004 // 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
2005 // 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
2006 // 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
2007 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
2008
18112
b560bac0fca2 maint: Don't use space between 'args' and '(' when doing indexing.
Rik <rik@octave.org>
parents: 18100
diff changeset
2009 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
2010
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
2011 if (dim >= dv_len)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
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 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
2014 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
2015
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
2016 break;
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 else
21660
53728df3e4c9 maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents: 21602
diff changeset
2019 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
2020 }
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
2021 retval = tmp;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
2022 }
4806
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
2023 }
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
2024 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
2025 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
2026
4806
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
2027 return retval;
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
2028 }
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
2029
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
2030 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
2031 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2032 @deftypefn {} {@var{A} =} horzcat (@var{array1}, @var{array2}, @dots{}, @var{arrayN})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2033 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
2034 @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
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 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
2037 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
2038
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2039 @example
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2040 @var{A} = [ @var{array1}, @var{array2}, @dots{} ]
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2041 @end example
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2042
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2043 This syntax is slightly more efficient because the Octave parser can
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2044 concatenate the arrays without the overhead of a function call.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2045 @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
2046 @end deftypefn */)
4806
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
2047 {
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
2048 return do_cat (args, -2, "horzcat");
4806
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
2049 }
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
2050
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
2051 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2052 ## 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
2053 %!test
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2054 %! warning ("off", "Octave:num-to-str", "local");
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
2055 %! assert (horzcat ("", 65* ones (1,10)), "AAAAAAAAAA");
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
2056 %! 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
2057
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), int64 (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), int32 (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), int16 (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), int8 (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), uint64 (1))), "int64")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2063 %!assert (class (horzcat (int64 (1), uint32 (1))), "int64")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2064 %!assert (class (horzcat (int64 (1), uint16 (1))), "int64")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2065 %!assert (class (horzcat (int64 (1), uint8 (1))), "int64")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2066 %!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
2067 %!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
2068 %!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
2069 %!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
2070 %!test
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2071 %! 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
2072 %! 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
2073
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), int64 (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), int32 (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), int16 (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), int8 (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), uint64 (1))), "int32")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2079 %!assert (class (horzcat (int32 (1), uint32 (1))), "int32")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2080 %!assert (class (horzcat (int32 (1), uint16 (1))), "int32")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2081 %!assert (class (horzcat (int32 (1), uint8 (1))), "int32")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2082 %!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
2083 %!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
2084 %!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
2085 %!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
2086 %!test
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2087 %! 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
2088 %! 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
2089
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), int64 (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), int32 (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), int16 (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), int8 (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), uint64 (1))), "int16")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2095 %!assert (class (horzcat (int16 (1), uint32 (1))), "int16")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2096 %!assert (class (horzcat (int16 (1), uint16 (1))), "int16")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2097 %!assert (class (horzcat (int16 (1), uint8 (1))), "int16")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2098 %!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
2099 %!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
2100 %!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
2101 %!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
2102 %!test
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2103 %! 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
2104 %! 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
2105
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), int64 (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), int32 (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), int16 (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), int8 (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), uint64 (1))), "int8")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2111 %!assert (class (horzcat (int8 (1), uint32 (1))), "int8")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2112 %!assert (class (horzcat (int8 (1), uint16 (1))), "int8")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2113 %!assert (class (horzcat (int8 (1), uint8 (1))), "int8")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2114 %!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
2115 %!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
2116 %!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
2117 %!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
2118 %!test
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2119 %! 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
2120 %! 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
2121
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), int64 (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), int32 (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), int16 (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), int8 (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), uint64 (1))), "uint64")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2127 %!assert (class (horzcat (uint64 (1), uint32 (1))), "uint64")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2128 %!assert (class (horzcat (uint64 (1), uint16 (1))), "uint64")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2129 %!assert (class (horzcat (uint64 (1), uint8 (1))), "uint64")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2130 %!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
2131 %!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
2132 %!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
2133 %!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
2134 %!test
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2135 %! 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
2136 %! 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
2137
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), int64 (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), int32 (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), int16 (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), int8 (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), uint64 (1))), "uint32")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2143 %!assert (class (horzcat (uint32 (1), uint32 (1))), "uint32")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2144 %!assert (class (horzcat (uint32 (1), uint16 (1))), "uint32")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2145 %!assert (class (horzcat (uint32 (1), uint8 (1))), "uint32")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2146 %!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
2147 %!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
2148 %!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
2149 %!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
2150 %!test
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2151 %! 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
2152 %! 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
2153
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), int64 (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), int32 (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), int16 (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), int8 (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), uint64 (1))), "uint16")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2159 %!assert (class (horzcat (uint16 (1), uint32 (1))), "uint16")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2160 %!assert (class (horzcat (uint16 (1), uint16 (1))), "uint16")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2161 %!assert (class (horzcat (uint16 (1), uint8 (1))), "uint16")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2162 %!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
2163 %!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
2164 %!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
2165 %!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
2166 %!test
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2167 %! 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
2168 %! 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
2169
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), int64 (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), int32 (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), int16 (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), int8 (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), uint64 (1))), "uint8")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2175 %!assert (class (horzcat (uint8 (1), uint32 (1))), "uint8")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2176 %!assert (class (horzcat (uint8 (1), uint16 (1))), "uint8")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2177 %!assert (class (horzcat (uint8 (1), uint8 (1))), "uint8")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2178 %!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
2179 %!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
2180 %!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
2181 %!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
2182 %!test
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2183 %! 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
2184 %! 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
2185
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), int64 (1))), "int64")
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), int32 (1))), "int32")
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), int16 (1))), "int16")
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), int8 (1))), "int8")
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), uint64 (1))), "uint64")
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), uint32 (1))), "uint32")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2192 %!assert (class (horzcat (single (1), uint16 (1))), "uint16")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2193 %!assert (class (horzcat (single (1), uint8 (1))), "uint8")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2194 %!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
2195 %!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
2196 %!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
2197 %!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
2198 %!test
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2199 %! 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
2200 %! 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
2201
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), int64 (1))), "int64")
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), int32 (1))), "int32")
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), int16 (1))), "int16")
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), int8 (1))), "int8")
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), uint64 (1))), "uint64")
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), uint32 (1))), "uint32")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2208 %!assert (class (horzcat (double (1), uint16 (1))), "uint16")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2209 %!assert (class (horzcat (double (1), uint8 (1))), "uint8")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2210 %!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
2211 %!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
2212 %!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
2213 %!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
2214 %!test
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2215 %! 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
2216 %! 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
2217
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), int64 (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), int32 (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), int16 (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), int8 (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), uint64 (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), uint32 (1))), "cell")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2224 %!assert (class (horzcat (cell (1), uint16 (1))), "cell")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2225 %!assert (class (horzcat (cell (1), uint8 (1))), "cell")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2226 %!assert (class (horzcat (cell (1), single (1))), "cell")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2227 %!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
2228 %!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
2229 %!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
2230 %!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
2231
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2232 %!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
2233 %!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
2234 %!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
2235 %!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
2236 %!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
2237 %!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
2238 %!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
2239 %!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
2240 %!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
2241 %!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
2242 %!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
2243 %!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
2244 %!test
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2245 %! warning ("off", "Octave:num-to-str", "local");
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2246 %! assert (class (horzcat (true, "a")), "char");
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2247
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2248 %!test
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2249 %! 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
2250 %! assert (class (horzcat ("a", int64 (1))), "char");
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2251 %! assert (class (horzcat ("a", int32 (1))), "char");
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2252 %! assert (class (horzcat ("a", int16 (1))), "char");
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2253 %! assert (class (horzcat ("a", int8 (1))), "char");
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2254 %! assert (class (horzcat ("a", int64 (1))), "char");
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2255 %! assert (class (horzcat ("a", int32 (1))), "char");
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2256 %! assert (class (horzcat ("a", int16 (1))), "char");
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2257 %! assert (class (horzcat ("a", int8 (1))), "char");
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2258 %! assert (class (horzcat ("a", single (1))), "char");
bc9aa534bc29 maint: Clean up BIST tests so they don't produce warnings.
Rik <rik@octave.org>
parents: 21547
diff changeset
2259 %! 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
2260 %! 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
2261 %! 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
2262 %! 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
2263
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2264 %!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
2265
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2266 %!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
2267
28915
c40a367a84c0 maint: Use Octave convention of space after function name in libinterp/.
Rik <rik@octave.org>
parents: 28888
diff changeset
2268 %!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
2269 %!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
2270 */
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
2271
4806
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
2272 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
2273 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2274 @deftypefn {} {@var{A} =} vertcat (@var{array1}, @var{array2}, @dots{}, @var{arrayN})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2275 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
2276 @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
2277
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2278 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
2279 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
2280
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2281 @example
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2282 @var{A} = [ @var{array1}; @var{array2}; @dots{} ]
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2283 @end example
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2284
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2285 This syntax is slightly more efficient because the Octave parser can
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2286 concatenate the arrays without the overhead of a function call.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2287 @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
2288 @end deftypefn */)
4806
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
2289 {
10716
f7f26094021b improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
2290 return do_cat (args, -1, "vertcat");
4806
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
2291 }
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
2292
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
2293 /*
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
2294 %!test
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2295 %! 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
2296 %! 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
2297 %! {"foo"; "bar"; "bazoloa"; "a"; "bc"; "def"});
13294
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
2298 */
7dce7e110511 make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents: 13029
diff changeset
2299
4758
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
2300 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
2301 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2302 @deftypefn {} {@var{A} =} cat (@var{dim}, @var{array1}, @var{array2}, @dots{}, @var{arrayN})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2303 Return the concatenation of N-D array objects, @var{array1}, @var{array2},
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2304 @dots{}, @var{arrayN} along dimension @var{dim}.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2305
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2306 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2307 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2308 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
2309 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
2310 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
2311 @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
2312 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
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
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2316 Alternatively, we can concatenate @var{A} and @var{B} along the second
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2317 dimension in the following way:
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2318
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2319 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2320 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2321 [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
2322 @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
2323 @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
2324
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2325 @var{dim} can be larger than the dimensions of the N-D array objects and the
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2326 result will thus have @var{dim} dimensions as the following example shows:
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
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 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2329 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2330 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
2331 @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
2332
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2333 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
2334 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
2335
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2336 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
2337
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2338 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
2339 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
2340 @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
2341 @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
2342 @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
2343 @end deftypefn */)
4758
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
2344 {
20850
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
2345 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
2346 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
2347
20850
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
2348 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
2349
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
2350 if (dim < 0)
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
2351 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
2352
21127
df7891224709 maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents: 21121
diff changeset
2353 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
2354 }
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
2355
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
2356 /*
14085
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 14022
diff changeset
2357 %!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
2358 %! 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
2359 %!
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2360 %! 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
2361 %! 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
2362 %! 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
2363 %! 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
2364 %! 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
2365 %! 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
2366 %! 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
2367 %! 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
2368 %! 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
2369 %! 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
2370 %!
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2371 %! assert ([cast(1, t1); cast(2, t2)], cast ([1; 2], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2372 %! assert ([cast(1, t1); cast([2; 3], t2)], cast ([1; 2; 3], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2373 %! assert ([cast([1; 2], t1); cast(3, t2)], cast ([1; 2; 3], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2374 %! assert ([cast([1; 2], t1); cast([3; 4], t2)], cast ([1; 2; 3; 4], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2375 %! 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
2376 %! 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
2377 %! 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
2378 %! 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
2379 %!
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2380 %! if (nargin == 3 || cmplx)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2381 %! 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
2382 %! 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
2383 %! 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
2384 %! 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
2385 %! 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
2386 %! 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
2387 %! 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
2388 %! 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
2389 %! 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
2390 %! 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
2391 %! assert ([cast(1i, t1); cast(2, t2)], cast ([1i; 2], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2392 %! assert ([cast(1i, t1); cast([2; 3], t2)], cast ([1i; 2; 3], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2393 %! assert ([cast([1i; 2], t1); cast(3, t2)], cast ([1i; 2; 3], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2394 %! assert ([cast([1i; 2], t1); cast([3; 4], t2)], cast ([1i; 2; 3; 4], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2395 %! 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
2396 %! 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
2397 %! 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
2398 %! 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
2399 %!
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2400 %! 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
2401 %! 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
2402 %! 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
2403 %! 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
2404 %! 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
2405 %! 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
2406 %! 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
2407 %! 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
2408 %! 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
2409 %! 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
2410 %! assert ([cast(1, t1); cast(2i, t2)], cast ([1; 2i], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2411 %! assert ([cast(1, t1); cast([2i; 3], t2)], cast ([1; 2i; 3], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2412 %! assert ([cast([1; 2], t1); cast(3i, t2)], cast ([1; 2; 3i], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2413 %! assert ([cast([1; 2], t1); cast([3i; 4], t2)], cast ([1; 2; 3i; 4], tr));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2414 %! 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
2415 %! 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
2416 %! 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
2417 %! 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
2418 %!
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2419 %! 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
2420 %! 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
2421 %! 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
2422 %! 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
2423 %! 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
2424 %! 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
2425 %! 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
2426 %! 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
2427 %! 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
2428 %! 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
2429 %! 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
2430 %! 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
2431 %! 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
2432 %! 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
2433 %!
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2434 %! 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
2435 %! 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
2436 %! 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
2437 %! 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
2438 %! 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
2439 %! 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
2440 %! 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
2441 %! 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
2442 %! 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
2443 %! 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
2444 %! endif
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2445 %! ret = true;
14085
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 14022
diff changeset
2446 %!endfunction
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 14022
diff changeset
2447
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2448 %!assert (__testcat ("double", "double", "double"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2449 %!assert (__testcat ("single", "double", "single"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2450 %!assert (__testcat ("double", "single", "single"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2451 %!assert (__testcat ("single", "single", "single"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2452
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2453 %!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
2454 %!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
2455 %!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
2456 %!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
2457 %!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
2458 %!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
2459 %!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
2460 %!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
2461 %!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
2462 %!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
2463 %!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
2464 %!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
2465 %!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
2466 %!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
2467 %!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
2468 %!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
2469 %!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
2470 %!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
2471 %!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
2472 %!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
2473
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
2474 %!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
2475 %!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
2476 %!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
2477 %!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
2478 %!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
2479 %!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
2480 %!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
2481 %!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
2482 %!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
2483 %!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
2484 %!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
2485 %!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
2486 %!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
2487 %!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
2488 %!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
2489 %!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
2490 %!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
2491 %!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
2492 %!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
2493 %!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
2494
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 14022
diff changeset
2495 %!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
2496 %!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
2497 %!assert (cat (3, [], [1,2;3,4], []), [1,2;3,4])
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 14022
diff changeset
2498 %!assert (cat (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
2499
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 14022
diff changeset
2500 %!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
2501 %!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
2502 %!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
2503
18678
6113e0c6920b maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents: 18676
diff changeset
2504 %!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
2505 %!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
2506
23573
1b4f4ec53b4a use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents: 23572
diff changeset
2507 %!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
2508 %! A = [];
0ab9eecbb165 Concatenate empty matrices/cells in cat() the same as the parser (bug #49759).
Rik <rik@octave.org>
parents: 22853
diff changeset
2509 %! 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
2510 %! 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
2511 %! 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
2512
14085
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 14022
diff changeset
2513 %!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
2514 %!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
2515 */
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
2516
4593
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
2517 static octave_value
6959
47f4f4e88166 [project @ 2007-10-04 20:43:32 by jwe]
jwe
parents: 6953
diff changeset
2518 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
2519 {
20850
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
2520 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
2521 print_usage ();
4593
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
2522
20850
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
2523 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
2524
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
2525 // 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
2526 // and pass that to permute?
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
2527 int n = vec.numel ();
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
2528 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
2529 vec(i)--;
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
2530
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
2531 return octave_value (args(0).permute (vec, inv));
4593
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
2532 }
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
2533
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
2534 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
2535 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2536 @deftypefn {} {@var{B} =} permute (@var{A}, @var{perm})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2537 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
2538
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2539 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
2540 @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
2541 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
2542 @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
2543
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2544 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2545 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2546 @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
2547 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
2548 @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
2549
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2550 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
2551 @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
2552
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2553 size (permute (@var{x}, [1, 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
2554 @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
2555
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2556 ## 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
2557 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
2558 @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
2559 @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
2560 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2561 @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
2562 @end deftypefn */)
4593
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
2563 {
6959
47f4f4e88166 [project @ 2007-10-04 20:43:32 by jwe]
jwe
parents: 6953
diff changeset
2564 return do_permute (args, false);
4593
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
2565 }
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
2566
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
2567 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
2568 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2569 @deftypefn {} {@var{A} =} ipermute (@var{B}, @var{iperm})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2570 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
2571
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2572 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
2573
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2574 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2575 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
2576 @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
2577
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2578 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2579 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
2580 @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
2581 @end deftypefn */)
4593
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
2582 {
6959
47f4f4e88166 [project @ 2007-10-04 20:43:32 by jwe]
jwe
parents: 6953
diff changeset
2583 return do_permute (args, true);
4593
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
2584 }
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
2585
3195
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3186
diff changeset
2586 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
2587 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2588 @deftypefn {} {@var{n} =} length (@var{A})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2589 Return the length of the object @var{A}.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2590
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2591 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
2592 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
2593 of elements along the largest dimension
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2594 (equivalent to @w{@code{max (size (@var{A}))}}).
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2595 @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
2596 @end deftypefn */)
3195
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3186
diff changeset
2597 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2598 if (args.length () != 1)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
2599 print_usage ();
3195
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3186
diff changeset
2600
21127
df7891224709 maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents: 21121
diff changeset
2601 return ovl (args(0).length ());
3195
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3186
diff changeset
2602 }
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3186
diff changeset
2603
4554
78e34346f6fd [project @ 2003-10-27 22:01:49 by jwe]
jwe
parents: 4545
diff changeset
2604 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
2605 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2606 @deftypefn {} {@var{n} =} ndims (@var{A})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2607 Return the number of dimensions of @var{A}.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2608
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2609 For any array, the result will always be greater than or equal to 2.
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2610 Trailing singleton dimensions are not counted, i.e., trailing dimensions @var{d}
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2611 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
2612
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2613 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2614 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2615 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
2616 @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
2617 @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
2618 @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
2619 @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
2620 @end deftypefn */)
4554
78e34346f6fd [project @ 2003-10-27 22:01:49 by jwe]
jwe
parents: 4545
diff changeset
2621 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2622 if (args.length () != 1)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
2623 print_usage ();
4554
78e34346f6fd [project @ 2003-10-27 22:01:49 by jwe]
jwe
parents: 4545
diff changeset
2624
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
2625 // 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
2626 // 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
2627 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
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 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
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 // 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
2632 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
2633 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
2634
ba937c3dce82 Determine an object's shape by "size" (bug #51308, bug #44498, bug #43925).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25861
diff changeset
2635 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
2636 }
ba937c3dce82 Determine an object's shape by "size" (bug #51308, bug #44498, bug #43925).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25861
diff changeset
2637
ba937c3dce82 Determine an object's shape by "size" (bug #51308, bug #44498, bug #43925).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25861
diff changeset
2638 /*
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
2639 %!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
2640 %!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
2641 %!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
2642 */
4554
78e34346f6fd [project @ 2003-10-27 22:01:49 by jwe]
jwe
parents: 4545
diff changeset
2643
4559
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4556
diff changeset
2644 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
2645 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2646 @deftypefn {} {@var{n} =} numel (@var{A})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2647 @deftypefnx {} {@var{n} =} numel (@var{A}, @var{idx1}, @var{idx2}, @dots{})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2648 Return the number of elements in the object @var{A}.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2649
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2650 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
2651 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
2652
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2653 @example
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2654 @var{A}(@var{idx1}, @var{idx2}, @dots{})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2655 @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
2656
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2657 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
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 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2660 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2661 @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
2662 @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
2663 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
2664 @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
2665 @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
2666
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2667 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2668 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
2669 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
2670 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
2671
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2672 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2673 @group
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2674 @var{A} = ones (5, 3);
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2675 numel (@var{A}, 2, ":")
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2676 @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
2677 @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
2678
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2679 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2680 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
2681
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2682 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
2683 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
2684 @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
2685 @end deftypefn */)
4559
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4556
diff changeset
2686 {
20850
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
2687 int nargin = args.length ();
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
2688
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
2689 if (nargin == 0)
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
2690 print_usage ();
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
2691
4559
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4556
diff changeset
2692 octave_value retval;
9329
67fc970dad7d improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9319
diff changeset
2693
9705
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2694 if (nargin == 1)
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2695 retval = args(0).numel ();
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2696 else if (nargin > 1)
4559
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4556
diff changeset
2697 {
9705
5acd99c3e794 avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents: 9689
diff changeset
2698 // 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
2699 // 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
2700 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
2701 }
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4556
diff changeset
2702
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4556
diff changeset
2703 return retval;
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4556
diff changeset
2704 }
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4556
diff changeset
2705
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1940
diff changeset
2706 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
2707 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2708 @deftypefn {} {@var{sz} =} size (@var{A})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2709 @deftypefnx {} {@var{dim_sz} =} size (@var{A}, @var{dim})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2710 @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
2711 @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
2712 Return a row vector with the size (number of elements) of each dimension for
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2713 the object @var{A}.
22699
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2714
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2715 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
2716 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
2717 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
2718
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2719 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
2720 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
2721 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
2722 first argument, the number of columns, dimension 2, is returned in the
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2723 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
2724 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
2725 remaining dimensions in the final output argument.
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2726
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2727 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
2728
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2729 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2730 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2731 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
2732 @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
2733 @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
2734 @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
2735
22699
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2736 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
2737
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2738 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2739 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2740 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
2741 @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
2742 @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
2743 @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
2744
22699
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2745 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
2746
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2747 @example
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2748 @group
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2749 [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
2750 @result{} nr = 3
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2751 @result{} nc = 2
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2752 @end group
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2753 @end example
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2754
25574
0e09d5fd7dab doc: Clarify description of Example 4 for size() (bug #54283).
Rik <rik@octave.org>
parents: 25471
diff changeset
2755 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
2756
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2757 @example
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2758 @group
22845
e23f7f47d8a3 doc: Small fixes to docstrings (bug #49733).
Rik <rik@octave.org>
parents: 22827
diff changeset
2759 [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
2760 @result{} nr = 2
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2761 @result{} remainder = 60
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2762 @end group
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2763 @end example
2100cd2e1be0 doc: Clarify behavior of size (bug #49478).
Rik <rik@octave.org>
parents: 22495
diff changeset
2764
22429
00986ee43956 doc: Add more @seealso links to numel, size, size_equal.
Rik <rik@octave.org>
parents: 22407
diff changeset
2765 @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
2766 @end deftypefn */)
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
2767 {
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
2768 int nargin = args.length ();
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
2769
30230
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2770 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
2771 print_usage ();
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2772
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2773 // 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
2774
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2775 Matrix m;
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2776
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2777 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
2778 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
2779
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4512
diff changeset
2780 if (nargin == 1)
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
2781 {
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4512
diff changeset
2782 if (nargout > 1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
2783 {
30230
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2784 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
2785 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
2786 }
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2787
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2788 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
2789
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2790 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
2791 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
2792 }
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2793 else
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2794 {
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2795 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
2796
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2797 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
2798 {
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2799 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
2800
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2801 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
2802 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
2803 }
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4512
diff changeset
2804 else
30230
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2805 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
2806
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2807 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
2808 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
2809
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2810 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
2811
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2812 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
2813
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2814 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
2815 {
30230
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2816 octave_idx_type 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
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 (nd < 1)
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2819 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
2820 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
2821
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2822 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
2823 }
1031
59f5eb2d5eb3 [project @ 1995-01-15 21:11:11 by jwe]
jwe
parents: 1009
diff changeset
2824 }
30230
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2825
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2826 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
2827 {
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2828 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
2829
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2830 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
2831 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
2832
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2833 return retval;
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2834 }
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2835
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2836 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
2837 }
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2838
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2839 /*
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2840 ## Plain call
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2841
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2842 %!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
2843
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2844 %!test
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2845 %! [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
2846 %! 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
2847 %! 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
2848
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2849 %!test
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2850 %! [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
2851 %! 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
2852 %! 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
2853
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2854 ## 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
2855
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2856 %!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
2857 %!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
2858
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2859 ## 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
2860
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2861 %!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
2862 %!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
2863
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2864 ## 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
2865
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2866 %!test
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2867 %! [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
2868 %! 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
2869 %! 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
2870 %! 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
2871 %! 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
2872
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2873 ## 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
2874
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2875 %!test
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2876 %! 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
2877 %! 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
2878 %! 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
2879 %! 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
2880 %! 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
2881 %! [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
2882 %! 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
2883 %! 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
2884 %! [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
2885 %! 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
2886 %! assert (b, dim(j));
31564
332a6ccac881 maint: cleanup code in BIST tests to use Octave coding conventions.
Rik <rik@octave.org>
parents: 31375
diff changeset
2887 %! endfor
332a6ccac881 maint: cleanup code in BIST tests to use Octave coding conventions.
Rik <rik@octave.org>
parents: 31375
diff changeset
2888 %! endfor
30230
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2889
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2890 ## 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
2891
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2892 %!test
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2893 %! 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
2894 %! 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
2895 %! 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
2896 %! 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
2897 %! 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
2898 %! 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
2899 %! [a, b, c] = size ([1, 2; 3, 4; 5, 6], i, j, k);
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2900 %! assert (a, dim(i));
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2901 %! assert (b, dim(j));
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2902 %! assert (c, dim(k));
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2903 %! [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
2904 %! 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
2905 %! 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
2906 %! assert (c, dim(k));
31564
332a6ccac881 maint: cleanup code in BIST tests to use Octave coding conventions.
Rik <rik@octave.org>
parents: 31375
diff changeset
2907 %! endfor
332a6ccac881 maint: cleanup code in BIST tests to use Octave coding conventions.
Rik <rik@octave.org>
parents: 31375
diff changeset
2908 %! endfor
332a6ccac881 maint: cleanup code in BIST tests to use Octave coding conventions.
Rik <rik@octave.org>
parents: 31375
diff changeset
2909 %! endfor
30230
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2910
bd02f48ac38f allow size function to query arbitrary list of dimensions (bug #61098)
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2911 %!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
2912 %! [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
2913 */
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
2914
6156
a46f14cdbecd [project @ 2006-11-13 19:20:23 by jwe]
jwe
parents: 6133
diff changeset
2915 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
2916 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2917 @deftypefn {} {@var{TF} =} size_equal (@var{A}, @var{B})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2918 @deftypefnx {} {@var{TF} =} size_equal (@var{A}, @var{B}, @dots{})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2919 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
2920
22429
00986ee43956 doc: Add more @seealso links to numel, size, size_equal.
Rik <rik@octave.org>
parents: 22407
diff changeset
2921 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
2922 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
2923 @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
2924 @end deftypefn */)
6156
a46f14cdbecd [project @ 2006-11-13 19:20:23 by jwe]
jwe
parents: 6133
diff changeset
2925 {
6561
dc83c15d7149 [project @ 2007-04-23 16:58:17 by jwe]
jwe
parents: 6556
diff changeset
2926 int nargin = args.length ();
dc83c15d7149 [project @ 2007-04-23 16:58:17 by jwe]
jwe
parents: 6556
diff changeset
2927
8947
1e4b3149365a allow size_equal called with 1 arg
Jaroslav Hajek <highegg@gmail.com>
parents: 8934
diff changeset
2928 if (nargin >= 1)
6156
a46f14cdbecd [project @ 2006-11-13 19:20:23 by jwe]
jwe
parents: 6133
diff changeset
2929 {
a46f14cdbecd [project @ 2006-11-13 19:20:23 by jwe]
jwe
parents: 6133
diff changeset
2930 dim_vector a_dims = args(0).dims ();
6561
dc83c15d7149 [project @ 2007-04-23 16:58:17 by jwe]
jwe
parents: 6556
diff changeset
2931
dc83c15d7149 [project @ 2007-04-23 16:58:17 by jwe]
jwe
parents: 6556
diff changeset
2932 for (int i = 1; i < nargin; ++i)
dc83c15d7149 [project @ 2007-04-23 16:58:17 by jwe]
jwe
parents: 6556
diff changeset
2933 {
dc83c15d7149 [project @ 2007-04-23 16:58:17 by jwe]
jwe
parents: 6556
diff changeset
2934 dim_vector b_dims = args(i).dims ();
dc83c15d7149 [project @ 2007-04-23 16:58:17 by jwe]
jwe
parents: 6556
diff changeset
2935
dc83c15d7149 [project @ 2007-04-23 16:58:17 by jwe]
jwe
parents: 6556
diff changeset
2936 if (a_dims != b_dims)
21078
49852ff04747 maint: Remove unnecessary declarations of retval.
Rik <rik@octave.org>
parents: 21062
diff changeset
2937 return ovl (false);
6561
dc83c15d7149 [project @ 2007-04-23 16:58:17 by jwe]
jwe
parents: 6556
diff changeset
2938 }
6156
a46f14cdbecd [project @ 2006-11-13 19:20:23 by jwe]
jwe
parents: 6133
diff changeset
2939 }
a46f14cdbecd [project @ 2006-11-13 19:20:23 by jwe]
jwe
parents: 6133
diff changeset
2940
21078
49852ff04747 maint: Remove unnecessary declarations of retval.
Rik <rik@octave.org>
parents: 21062
diff changeset
2941 return ovl (true);
6156
a46f14cdbecd [project @ 2006-11-13 19:20:23 by jwe]
jwe
parents: 6133
diff changeset
2942 }
a46f14cdbecd [project @ 2006-11-13 19:20:23 by jwe]
jwe
parents: 6133
diff changeset
2943
5602
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5533
diff changeset
2944 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
2945 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2946 @deftypefn {} {@var{n} =} nnz (@var{A})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2947 Return the number of nonzero elements in @var{A}.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2948 @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
2949 @end deftypefn */)
5602
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5533
diff changeset
2950 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2951 if (args.length () != 1)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
2952 print_usage ();
5602
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5533
diff changeset
2953
21127
df7891224709 maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents: 21121
diff changeset
2954 return ovl (args(0).nnz ());
5602
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5533
diff changeset
2955 }
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5533
diff changeset
2956
24859
00ecff875f8a Add nnz implementation for Range type (bug #53185).
maorshutman <maorus12@gmail.com>
parents: 24634
diff changeset
2957 /*
00ecff875f8a Add nnz implementation for Range type (bug #53185).
maorshutman <maorus12@gmail.com>
parents: 24634
diff changeset
2958 %!assert (nnz (1:5), 5)
00ecff875f8a Add nnz implementation for Range type (bug #53185).
maorshutman <maorus12@gmail.com>
parents: 24634
diff changeset
2959 %!assert (nnz (-5:-1), 5)
00ecff875f8a Add nnz implementation for Range type (bug #53185).
maorshutman <maorus12@gmail.com>
parents: 24634
diff changeset
2960 %!assert (nnz (0:5), 5)
00ecff875f8a Add nnz implementation for Range type (bug #53185).
maorshutman <maorus12@gmail.com>
parents: 24634
diff changeset
2961 %!assert (nnz (-5:0), 5)
00ecff875f8a Add nnz implementation for Range type (bug #53185).
maorshutman <maorus12@gmail.com>
parents: 24634
diff changeset
2962 %!assert (nnz (-5:5), 10)
00ecff875f8a Add nnz implementation for Range type (bug #53185).
maorshutman <maorus12@gmail.com>
parents: 24634
diff changeset
2963 %!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
2964 %!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
2965 %!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
2966 %!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
2967 %!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
2968 %!assert (nnz ([1:5] * 0), 0)
00ecff875f8a Add nnz implementation for Range type (bug #53185).
maorshutman <maorus12@gmail.com>
parents: 24634
diff changeset
2969 %!assert (nnz ([-5:-1] * 0), 0)
00ecff875f8a Add nnz implementation for Range type (bug #53185).
maorshutman <maorus12@gmail.com>
parents: 24634
diff changeset
2970 %!assert (nnz ([-1:1] * 0), 0)
00ecff875f8a Add nnz implementation for Range type (bug #53185).
maorshutman <maorus12@gmail.com>
parents: 24634
diff changeset
2971 */
00ecff875f8a Add nnz implementation for Range type (bug #53185).
maorshutman <maorus12@gmail.com>
parents: 24634
diff changeset
2972
5604
2857357f9d3c [project @ 2006-01-31 18:22:59 by jwe]
jwe
parents: 5602
diff changeset
2973 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
2974 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
2975 @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
2976 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
2977
27081
c0d8ce61c1c9 Always reserve at least 1 element of storage for sparse matrices (bug #56232).
Rik <rik@octave.org>
parents: 27034
diff changeset
2978 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
2979 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
2980 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
2981
c0d8ce61c1c9 Always reserve at least 1 element of storage for sparse matrices (bug #56232).
Rik <rik@octave.org>
parents: 27034
diff changeset
2982 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
2983 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
2984 @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
2985 @end deftypefn */)
5604
2857357f9d3c [project @ 2006-01-31 18:22:59 by jwe]
jwe
parents: 5602
diff changeset
2986 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
2987 if (args.length () != 1)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
2988 print_usage ();
5604
2857357f9d3c [project @ 2006-01-31 18:22:59 by jwe]
jwe
parents: 5602
diff changeset
2989
21127
df7891224709 maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents: 21121
diff changeset
2990 return ovl (args(0).nzmax ());
5604
2857357f9d3c [project @ 2006-01-31 18:22:59 by jwe]
jwe
parents: 5602
diff changeset
2991 }
2857357f9d3c [project @ 2006-01-31 18:22:59 by jwe]
jwe
parents: 5602
diff changeset
2992
5677
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
2993 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
2994 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2995 @deftypefn {} {@var{nr} =} rows (@var{A})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2996 Return the number of rows of @var{A}.
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2997
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
2998 This is equivalent to @code{size (@var{A}, 1)}.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
2999 @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
3000 @end deftypefn */)
5677
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
3001 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3002 if (args.length () != 1)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
3003 print_usage ();
5677
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
3004
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
3005 // 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
3006 // 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
3007
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
3008 return ovl ((octave_value (args(0)).size ())(0));
5677
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
3009 }
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
3010
20810
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 %!assert (rows (ones (2,5)), 2)
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
3013 %!assert (rows (ones (5,2)), 5)
20811
5979314bb15a Fix BIST tests for rows.
Rik <rik@octave.org>
parents: 20810
diff changeset
3014 %!assert (rows (ones (5,4,3,2)), 5)
20810
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
3015 %!assert (rows (ones (3,4,5,2)), 3)
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
3016
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
3017 %!assert (rows (cell (2,5)), 2)
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
3018 %!assert (rows (cell (5,2)), 5)
20811
5979314bb15a Fix BIST tests for rows.
Rik <rik@octave.org>
parents: 20810
diff changeset
3019 %!assert (rows (cell (5,4,3,2)), 5)
20810
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
3020 %!assert (rows (cell (3,4,5,2)), 3)
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
3021
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
3022 %!test
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
3023 %! x(2,5,3).a = 1;
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
3024 %! assert (rows (x), 2);
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
3025 %! y(5,4,3).b = 2;
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
3026 %! assert (rows (y), 5);
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
3027
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
3028 %!assert (rows ("Hello World"), 1)
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
3029
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
3030 %!assert (rows ([]), 0)
20815
6935b8f038cc Fix BIST tests for rows()
Rik <rik@octave.org>
parents: 20811
diff changeset
3031 %!assert (rows (zeros (2,0)), 2)
20810
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
3032
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
3033 ## Test input validation
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
3034 %!error rows ()
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
3035 %!error rows (1,2)
dc9039163760 Add BIST tests for rows().
Rik <rik@octave.org>
parents: 20809
diff changeset
3036 */
5677
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
3037
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
3038 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
3039 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
3040 @deftypefn {} {@var{nc} =} columns (@var{A})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
3041 Return the number of columns of @var{A}.
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
3042
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
3043 This is equivalent to @code{size (@var{A}, 2)}.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3044 @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
3045 @end deftypefn */)
5677
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
3046 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3047 if (args.length () != 1)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
3048 print_usage ();
5677
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
3049
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
3050 // 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
3051 // 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
3052
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
3053 return ovl ((octave_value (args(0)).size ())(1));
5677
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
3054 }
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
3055
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1940
diff changeset
3056 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
3057 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
3058 @deftypefn {} {@var{y} =} sum (@var{x})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
3059 @deftypefnx {} {@var{y} =} sum (@var{x}, @var{dim})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
3060 @deftypefnx {} {@var{y} =} sum (@dots{}, "native")
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
3061 @deftypefnx {} {@var{y} =} sum (@dots{}, "double")
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
3062 @deftypefnx {} {@var{y} =} sum (@dots{}, "extra")
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3063 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
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 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
3066
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3067 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
3068 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
3069 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
3070 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
3071 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
3072 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
3073
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3074 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
3075
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3076 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3077 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3078 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
3079 @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
3080 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
3081 @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
3082 @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
3083 @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
3084
25286
44c0aca121cc doc: Clarify docstring for sum (bug #53698).
Rik <rik@octave.org>
parents: 25103
diff changeset
3085 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
3086 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
3087
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3088 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
3089 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
3090 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
3091 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
3092 @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
3093 @end deftypefn */)
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
3094 {
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
3095 int nargin = args.length ();
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
3096
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
3097 bool isnative = false;
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
3098 bool isdouble = false;
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
3099 bool isextra = false;
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
3100
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
3101 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
3102 {
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
3103 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
3104
19743
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
3105 if (str == "native")
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
3106 isnative = true;
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
3107 else if (str == "double")
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
3108 isdouble = true;
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
3109 else if (str == "extra")
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
3110 isextra = true;
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
3111 else
67f2c76f9f4d Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents: 19739
diff changeset
3112 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
3113
21062
d9c1884d1aaa maint: Eliminate space between variable and decrement '--' operator.
Rik <rik@octave.org>
parents: 21055
diff changeset
3114 nargin--;
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
3115 }
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
3116
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3117 if (nargin < 1 || nargin > 2)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3118 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3119
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3120 int dim = -1;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3121 if (nargin == 2)
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
3122 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3123 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
3124 if (dim < 0)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3125 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
3126 }
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3127
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3128 octave_value retval;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3129 octave_value arg = args(0);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3130
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3131 switch (arg.builtin_type ())
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3132 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3133 case btyp_double:
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
3134 if (arg.issparse ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3135 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3136 if (isextra)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3137 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
3138 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
3139 }
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3140 else if (isextra)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3141 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
3142 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3143 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
3144 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3145
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3146 case btyp_complex:
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
3147 if (arg.issparse ())
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3148 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3149 if (isextra)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3150 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
3151 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
3152 }
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3153 else if (isextra)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3154 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
3155 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3156 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
3157 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3158
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3159 case btyp_float:
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3160 if (isdouble || isextra)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3161 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
3162 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3163 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
3164 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3165
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3166 case btyp_float_complex:
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3167 if (isdouble || isextra)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3168 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
3169 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3170 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
3171 break;
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
3172
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
3173 #define MAKE_INT_BRANCH(X) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
3174 case btyp_ ## X: \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
3175 if (isnative) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
3176 retval = arg.X ## _array_value ().sum (dim); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
3177 else \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
3178 retval = arg.X ## _array_value ().dsum (dim); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
3179 break;
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3180
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3181 MAKE_INT_BRANCH (int8);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3182 MAKE_INT_BRANCH (int16);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3183 MAKE_INT_BRANCH (int32);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3184 MAKE_INT_BRANCH (int64);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3185 MAKE_INT_BRANCH (uint8);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3186 MAKE_INT_BRANCH (uint16);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3187 MAKE_INT_BRANCH (uint32);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3188 MAKE_INT_BRANCH (uint64);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3189
9721
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
3190 #undef MAKE_INT_BRANCH
19597
db92e7e28e1f strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 19596
diff changeset
3191
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
3192 // GAGME: Accursed Matlab compatibility...
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3193 case btyp_char:
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3194 if (isextra)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3195 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
3196 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3197 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
3198 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3199
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3200 case btyp_bool:
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
3201 if (arg.issparse ())
20806
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 if (isnative)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3204 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
3205 else
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3206 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
3207 }
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3208 else if (isnative)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3209 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
3210 else
22773
7f70e420e342 deprecate boolNDArray::sum and boolNDArray::cumsum
John W. Eaton <jwe@octave.org>
parents: 22763
diff changeset
3211 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
3212 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3213
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3214 default:
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21078
diff changeset
3215 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
3216 }
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
3217
192d94cff6c1 improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents: 9706
diff changeset
3218 return retval;
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
3219 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
3220
7112
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
3221 /*
14429
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]), 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]), -6)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3224 %!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
3225 %!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
3226
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3227 %!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
3228 %!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
3229 %!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
3230 %!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
3231 %! 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
3232
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3233 %!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
3234 %!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
3235 %!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
3236 %!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
3237 %!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
3238 %!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
3239 %!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
3240 %!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
3241 %!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
3242 %!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
3243 %!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
3244 %!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
3245 %!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
3246 %!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
3247 %!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
3248 %!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
3249 %!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
3250 %!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
3251 %!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
3252
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3253 %!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
3254 %!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
3255 %!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
3256 %!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
3257 %!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
3258 %!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
3259 %!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
3260 %!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
3261 %!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
3262 %!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
3263 %!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
3264 %!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
3265 %!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
3266 %!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
3267 %!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
3268 %!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
3269 %!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
3270 %!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
3271 %!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
3272
18726
5baada25d5a2 Rewrite docstring of sum() to match prod().
Rik <rik@octave.org>
parents: 18725
diff changeset
3273 ## Test "native"
5baada25d5a2 Rewrite docstring of sum() to match prod().
Rik <rik@octave.org>
parents: 18725
diff changeset
3274 %!assert (sum ([true,true]), 2)
5baada25d5a2 Rewrite docstring of sum() to match prod().
Rik <rik@octave.org>
parents: 18725
diff changeset
3275 %!assert (sum ([true,true], "native"), true)
5baada25d5a2 Rewrite docstring of sum() to match prod().
Rik <rik@octave.org>
parents: 18725
diff changeset
3276 %!assert (sum (int8 ([127,10,-20])), 117)
5baada25d5a2 Rewrite docstring of sum() to match prod().
Rik <rik@octave.org>
parents: 18725
diff changeset
3277 %!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
3278
15623
d928ad126b66 maint: add a new test for Fsum corresponding to cset e9d842dcfc91
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 15621
diff changeset
3279 ;-)
d928ad126b66 maint: add a new test for Fsum corresponding to cset e9d842dcfc91
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 15621
diff changeset
3280 %!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
3281
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3282 %!error sum ()
18726
5baada25d5a2 Rewrite docstring of sum() to match prod().
Rik <rik@octave.org>
parents: 18725
diff changeset
3283 %!error sum (1,2,3)
5baada25d5a2 Rewrite docstring of sum() to match prod().
Rik <rik@octave.org>
parents: 18725
diff changeset
3284 %!error <unrecognized type argument 'foobar'> sum (1, "foobar")
7112
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
3285 */
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
3286
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1940
diff changeset
3287 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
3288 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
3289 @deftypefn {} {@var{y} =} sumsq (@var{x})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
3290 @deftypefnx {} {@var{y} =} sumsq (@var{x}, @var{dim})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3291 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
3292
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3293 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
3294
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3295 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
3296
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3297 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3298 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
3299 @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
3300
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3301 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3302 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
3303 @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
3304 @end deftypefn */)
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
3305 {
3723
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
3306 DATA_REDUCTION (sumsq);
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
3307 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
3308
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
3309 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3310 %!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
3311 %!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
3312 %!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
3313
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3314 %!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
3315 %!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
3316 %!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
3317
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3318 %!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
3319 %!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
3320
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3321 %!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
3322 %!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
3323
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3324 %!error sumsq ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3325 */
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
3326
6688
b26a8e0e42cd [project @ 2007-06-04 06:25:21 by jwe]
jwe
parents: 6671
diff changeset
3327 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
3328 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
3329 @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
3330 @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
3331 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
3332 @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
3333 @end deftypefn */)
3209
fbb332b96e4f [project @ 1998-11-03 20:48:54 by jwe]
jwe
parents: 3206
diff changeset
3334 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3335 if (args.length () != 1)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
3336 print_usage ();
3209
fbb332b96e4f [project @ 1998-11-03 20:48:54 by jwe]
jwe
parents: 3206
diff changeset
3337
23579
c20a0fa91c0c maint: Deprecate is_bool_type and replace with islogical.
Rik <rik@octave.org>
parents: 23577
diff changeset
3338 return ovl (args(0).islogical ());
3209
fbb332b96e4f [project @ 1998-11-03 20:48:54 by jwe]
jwe
parents: 3206
diff changeset
3339 }
fbb332b96e4f [project @ 1998-11-03 20:48:54 by jwe]
jwe
parents: 3206
diff changeset
3340
6688
b26a8e0e42cd [project @ 2007-06-04 06:25:21 by jwe]
jwe
parents: 6671
diff changeset
3341 DEFALIAS (isbool, islogical);
3209
fbb332b96e4f [project @ 1998-11-03 20:48:54 by jwe]
jwe
parents: 3206
diff changeset
3342
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
3343 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3344 %!assert (islogical (true), true)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3345 %!assert (islogical (false), true)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3346 %!assert (islogical ([true, false]), true)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3347 %!assert (islogical (1), false)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3348 %!assert (islogical (1i), false)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3349 %!assert (islogical ([1,1]), false)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3350 %!assert (islogical (single (1)), false)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3351 %!assert (islogical (single (1i)), false)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3352 %!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
3353 %!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
3354 %!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
3355 */
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7814
diff changeset
3356
6223
a6cc01dd09f9 [project @ 2007-01-03 20:59:28 by jwe]
jwe
parents: 6197
diff changeset
3357 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
3358 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
3359 @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
3360 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
3361
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3362 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
3363 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
3364 @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
3365 @end deftypefn */)
6223
a6cc01dd09f9 [project @ 2007-01-03 20:59:28 by jwe]
jwe
parents: 6197
diff changeset
3366 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3367 if (args.length () != 1)
6223
a6cc01dd09f9 [project @ 2007-01-03 20:59:28 by jwe]
jwe
parents: 6197
diff changeset
3368 print_usage ();
a6cc01dd09f9 [project @ 2007-01-03 20:59:28 by jwe]
jwe
parents: 6197
diff changeset
3369
23580
2230f9e10fb3 maint: Deprecate is_integer_type and replace with isinteger.
Rik <rik@octave.org>
parents: 23579
diff changeset
3370 return ovl (args(0).isinteger ());
6223
a6cc01dd09f9 [project @ 2007-01-03 20:59:28 by jwe]
jwe
parents: 6197
diff changeset
3371 }
a6cc01dd09f9 [project @ 2007-01-03 20:59:28 by jwe]
jwe
parents: 6197
diff changeset
3372
22749
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3373 /*
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3374 %!assert (isinteger (int8 (16)))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3375 %!assert (isinteger (int16 (16)))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3376 %!assert (isinteger (int32 (16)))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3377 %!assert (isinteger (int64 (16)))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3378
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3379 %!assert (isinteger (uint8 (16)))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3380 %!assert (isinteger (uint16 (16)))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3381 %!assert (isinteger (uint32 (16)))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3382 %!assert (isinteger (uint64 (16)))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3383
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3384 %!assert (isinteger (intmax ("int8")))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3385 %!assert (isinteger (intmax ("int16")))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3386 %!assert (isinteger (intmax ("int32")))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3387 %!assert (isinteger (intmax ("int64")))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3388
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3389 %!assert (isinteger (intmax ("uint8")))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3390 %!assert (isinteger (intmax ("uint16")))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3391 %!assert (isinteger (intmax ("uint32")))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3392 %!assert (isinteger (intmax ("uint64")))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3393
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3394 %!assert (isinteger (intmin ("int8")))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3395 %!assert (isinteger (intmin ("int16")))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3396 %!assert (isinteger (intmin ("int32")))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3397 %!assert (isinteger (intmin ("int64")))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3398
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3399 %!assert (isinteger (intmin ("uint8")))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3400 %!assert (isinteger (intmin ("uint16")))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3401 %!assert (isinteger (intmin ("uint32")))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3402 %!assert (isinteger (intmin ("uint64")))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3403
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3404 %!assert (isinteger (uint8 ([1:10])))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3405 %!assert (isinteger (uint8 ([1:10; 1:10])))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3406
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3407 %!assert (! isinteger (16))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3408 %!assert (! isinteger ("parrot"))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3409 %!assert (! isinteger ([1, 2, 3]))
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3410
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3411 %!error isinteger ()
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3412 %!error isinteger ("multiple", "parameters")
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3413 */
e6bf4f8920d3 * data.cc (Fisinteger): Add BIST tests.
NVS Abhilash <nvs232@gmail.com>
parents: 22699
diff changeset
3414
4028
ef75c970c8f5 [project @ 2002-08-09 07:19:02 by jwe]
jwe
parents: 4025
diff changeset
3415 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
3416 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
3417 @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
3418 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
3419 @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
3420 @end deftypefn */)
3186
edaa9a2d3d9c [project @ 1998-10-02 19:12:19 by jwe]
jwe
parents: 3174
diff changeset
3421 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3422 if (args.length () != 1)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
3423 print_usage ();
3186
edaa9a2d3d9c [project @ 1998-10-02 19:12:19 by jwe]
jwe
parents: 3174
diff changeset
3424
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
3425 return ovl (args(0).iscomplex ());
3186
edaa9a2d3d9c [project @ 1998-10-02 19:12:19 by jwe]
jwe
parents: 3174
diff changeset
3426 }
edaa9a2d3d9c [project @ 1998-10-02 19:12:19 by jwe]
jwe
parents: 3174
diff changeset
3427
26198
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 %!assert (iscomplex (4), false)
d57d30caffd6 Add BISTS tests for iscomplex().
Rik <rik@octave.org>
parents: 26164
diff changeset
3430 %!assert (iscomplex (i), true)
d57d30caffd6 Add BISTS tests for iscomplex().
Rik <rik@octave.org>
parents: 26164
diff changeset
3431 %!assert (iscomplex (4+3i), true)
d57d30caffd6 Add BISTS tests for iscomplex().
Rik <rik@octave.org>
parents: 26164
diff changeset
3432 %!assert (iscomplex ([1, 2, 3]), false)
d57d30caffd6 Add BISTS tests for iscomplex().
Rik <rik@octave.org>
parents: 26164
diff changeset
3433 %!assert (iscomplex ([1, 2i, 3]), true)
d57d30caffd6 Add BISTS tests for iscomplex().
Rik <rik@octave.org>
parents: 26164
diff changeset
3434
d57d30caffd6 Add BISTS tests for iscomplex().
Rik <rik@octave.org>
parents: 26164
diff changeset
3435 %!assert (iscomplex (0j), false)
d57d30caffd6 Add BISTS tests for iscomplex().
Rik <rik@octave.org>
parents: 26164
diff changeset
3436 %!assert (iscomplex (complex (0,0)), true)
d57d30caffd6 Add BISTS tests for iscomplex().
Rik <rik@octave.org>
parents: 26164
diff changeset
3437 %!assert (iscomplex ("4"), false)
d57d30caffd6 Add BISTS tests for iscomplex().
Rik <rik@octave.org>
parents: 26164
diff changeset
3438 %!assert (iscomplex ({i}), false)
d57d30caffd6 Add BISTS tests for iscomplex().
Rik <rik@octave.org>
parents: 26164
diff changeset
3439
d57d30caffd6 Add BISTS tests for iscomplex().
Rik <rik@octave.org>
parents: 26164
diff changeset
3440 ## Test input validation
d57d30caffd6 Add BISTS tests for iscomplex().
Rik <rik@octave.org>
parents: 26164
diff changeset
3441 %!error iscomplex ()
d57d30caffd6 Add BISTS tests for iscomplex().
Rik <rik@octave.org>
parents: 26164
diff changeset
3442 %!error iscomplex (1, 2)
d57d30caffd6 Add BISTS tests for iscomplex().
Rik <rik@octave.org>
parents: 26164
diff changeset
3443 */
d57d30caffd6 Add BISTS tests for iscomplex().
Rik <rik@octave.org>
parents: 26164
diff changeset
3444
7576
7ebdc99a0bab new isfloat function
John W. Eaton <jwe@octave.org>
parents: 7515
diff changeset
3445 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
3446 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
3447 @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
3448 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
3449
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3450 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
3451 @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
3452 @end deftypefn */)
7576
7ebdc99a0bab new isfloat function
John W. Eaton <jwe@octave.org>
parents: 7515
diff changeset
3453 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3454 if (args.length () != 1)
7576
7ebdc99a0bab new isfloat function
John W. Eaton <jwe@octave.org>
parents: 7515
diff changeset
3455 print_usage ();
7ebdc99a0bab new isfloat function
John W. Eaton <jwe@octave.org>
parents: 7515
diff changeset
3456
23585
570170b6eb09 maint: Deprecate is_float_type and replace with isfloat.
Rik <rik@octave.org>
parents: 23584
diff changeset
3457 return ovl (args(0).isfloat ());
7576
7ebdc99a0bab new isfloat function
John W. Eaton <jwe@octave.org>
parents: 7515
diff changeset
3458 }
7ebdc99a0bab new isfloat function
John W. Eaton <jwe@octave.org>
parents: 7515
diff changeset
3459
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
3460 // FIXME: perhaps this should be implemented with an
5476
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3461 // octave_value member function?
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3462
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3463 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
3464 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
3465 @deftypefn {} {@var{z} =} complex (@var{x})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
3466 @deftypefnx {} {@var{z} =} complex (@var{re}, @var{im})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3467 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
3468
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3469 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
3470 @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
3471
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3472 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
3473 @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
3474 @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
3475 @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
3476 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
3477
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3478 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3479 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3480 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
3481 @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
3482 @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
3483 @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
3484 @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
3485 @end deftypefn */)
30673
1182fcd6cdaf Coding changes for performance in complex() (bug #61912)
Rik <rik@octave.org>
parents: 30594
diff changeset
3486 // Programming Note: Throughout this function the coding pattern
1182fcd6cdaf Coding changes for performance in complex() (bug #61912)
Rik <rik@octave.org>
parents: 30594
diff changeset
3487 // octave_value (new XXX)) is used. This is done specifically because the
1182fcd6cdaf Coding changes for performance in complex() (bug #61912)
Rik <rik@octave.org>
parents: 30594
diff changeset
3488 // default octave_value constructor would otherwise perform automatic narrowing
1182fcd6cdaf Coding changes for performance in complex() (bug #61912)
Rik <rik@octave.org>
parents: 30594
diff changeset
3489 // (i.e., complex values with 0 for the imaginary part would be converted
1182fcd6cdaf Coding changes for performance in complex() (bug #61912)
Rik <rik@octave.org>
parents: 30594
diff changeset
3490 // to real values). The complex() function *must* return a complex value
1182fcd6cdaf Coding changes for performance in complex() (bug #61912)
Rik <rik@octave.org>
parents: 30594
diff changeset
3491 // even when the imaginary part is 0.
5476
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3492 {
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3493 int nargin = args.length ();
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3494
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3495 if (nargin < 1 || nargin > 2)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3496 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3497
5476
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3498 octave_value retval;
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3499
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3500 if (nargin == 1)
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3501 {
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3502 octave_value arg = args(0);
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3503
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
3504 if (arg.iscomplex ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3505 retval = arg;
5476
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3506 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3507 {
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
3508 if (arg.issparse ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3509 {
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20700
diff changeset
3510 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
3511
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3512 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
3513 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3514 else if (arg.is_single_type ())
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3515 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3516 if (arg.numel () == 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3517 {
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20700
diff changeset
3518 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
3519
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3520 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
3521 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3522 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3523 {
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20700
diff changeset
3524 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
3525
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3526 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
3527 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3528 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3529 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3530 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3531 if (arg.numel () == 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3532 {
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20700
diff changeset
3533 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
3534
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3535 retval = octave_value (new octave_complex (val));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3536 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3537 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3538 {
20704
571508c1ed06 eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20700
diff changeset
3539 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
3540
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3541 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
3542 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3543 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3544 }
5476
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3545 }
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3546 else
5476
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3547 {
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3548 octave_value re = args(0);
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3549 octave_value im = args(1);
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3550
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
3551 if (re.issparse () && im.issparse ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3552 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3553 const SparseMatrix re_val = re.sparse_matrix_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3554 const SparseMatrix im_val = im.sparse_matrix_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3555
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3556 if (re.numel () == 1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3557 {
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3558 SparseComplexMatrix result;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3559 if (re_val.nnz () == 0)
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3560 result = Complex (0, 1) * SparseComplexMatrix (im_val);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3561 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3562 {
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3563 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
3564 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
3565 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
3566
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3567 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
3568 {
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3569 octave_idx_type off = j * nr;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3570 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
3571 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
3572 result.data (im_val.ridx (i) + off)
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
3573 += Complex (0, im_val.data (i));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3574 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3575 }
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3576 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
3577 }
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3578 else if (im.numel () == 1)
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3579 {
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3580 SparseComplexMatrix result;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3581 if (im_val.nnz () == 0)
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3582 result = SparseComplexMatrix (re_val);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3583 else
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3584 {
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3585 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
3586 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
3587 result = SparseComplexMatrix (nr, nc,
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3588 Complex (0, im_val(0)));
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3589
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3590 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
3591 {
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3592 octave_idx_type off = j * nr;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3593 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
3594 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
3595 result.data (re_val.ridx (i) + off)
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
3596 += re_val.data (i);
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3597 }
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3598 }
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3599 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
3600 }
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3601 else
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3602 {
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3603 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
3604 error ("complex: dimension mismatch");
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3605
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3606 SparseComplexMatrix result;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3607 result = SparseComplexMatrix (re_val)
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
3608 + Complex (0, 1) * SparseComplexMatrix (im_val);
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3609 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
3610 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3611 }
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7743
diff changeset
3612 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
3613 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3614 if (re.numel () == 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3615 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3616 float re_val = re.float_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3617
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3618 if (im.numel () == 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3619 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3620 float im_val = im.double_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3621
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3622 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
3623 (FloatComplex (re_val, im_val)));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3624 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3625 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3626 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3627 const FloatNDArray im_val = im.float_array_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3628
30673
1182fcd6cdaf Coding changes for performance in complex() (bug #61912)
Rik <rik@octave.org>
parents: 30594
diff changeset
3629 FloatComplexNDArray result (im_val.dims ());
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3630
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3631 for (octave_idx_type i = 0; i < im_val.numel (); i++)
30673
1182fcd6cdaf Coding changes for performance in complex() (bug #61912)
Rik <rik@octave.org>
parents: 30594
diff changeset
3632 result.xelem (i) = FloatComplex (re_val, im_val.xelem (i));
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3633
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3634 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
3635 (result));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3636 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3637 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3638 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3639 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3640 const FloatNDArray re_val = re.float_array_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3641
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3642 if (im.numel () == 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3643 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3644 float im_val = im.float_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3645
30673
1182fcd6cdaf Coding changes for performance in complex() (bug #61912)
Rik <rik@octave.org>
parents: 30594
diff changeset
3646 FloatComplexNDArray result (re_val.dims ());
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3647
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3648 for (octave_idx_type i = 0; i < re_val.numel (); i++)
30673
1182fcd6cdaf Coding changes for performance in complex() (bug #61912)
Rik <rik@octave.org>
parents: 30594
diff changeset
3649 result.xelem (i) = FloatComplex (re_val.xelem (i), im_val);
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3650
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3651 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
3652 (result));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3653 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3654 else
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 const FloatNDArray im_val = im.float_array_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3657
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3658 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
3659 error ("complex: dimension mismatch");
20921
4d3daf7e43f3 eliminate trailing whitespace in source files
John W. Eaton <jwe@octave.org>
parents: 20918
diff changeset
3660
30673
1182fcd6cdaf Coding changes for performance in complex() (bug #61912)
Rik <rik@octave.org>
parents: 30594
diff changeset
3661 FloatComplexNDArray result (re_val.dims ());
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3662
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3663 for (octave_idx_type i = 0; i < re_val.numel (); i++)
30673
1182fcd6cdaf Coding changes for performance in complex() (bug #61912)
Rik <rik@octave.org>
parents: 30594
diff changeset
3664 result.xelem (i) = FloatComplex (re_val.xelem (i),
1182fcd6cdaf Coding changes for performance in complex() (bug #61912)
Rik <rik@octave.org>
parents: 30594
diff changeset
3665 im_val.xelem (i));
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3666
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3667 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
3668 (result));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3669 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3670 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3671 }
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7743
diff changeset
3672 else if (re.numel () == 1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3673 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3674 double re_val = re.double_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3675
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3676 if (im.numel () == 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3677 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3678 double im_val = im.double_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3679
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3680 retval = octave_value (new octave_complex
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3681 (Complex (re_val, im_val)));
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 else
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 const NDArray im_val = im.array_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3686
30673
1182fcd6cdaf Coding changes for performance in complex() (bug #61912)
Rik <rik@octave.org>
parents: 30594
diff changeset
3687 ComplexNDArray result (im_val.dims ());
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3688
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3689 for (octave_idx_type i = 0; i < im_val.numel (); i++)
30673
1182fcd6cdaf Coding changes for performance in complex() (bug #61912)
Rik <rik@octave.org>
parents: 30594
diff changeset
3690 result.xelem (i) = Complex (re_val, im_val.xelem (i));
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3691
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3692 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
3693 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3694 }
5476
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3695 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3696 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3697 const NDArray re_val = re.array_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3698
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3699 if (im.numel () == 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3700 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3701 double im_val = im.double_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3702
30673
1182fcd6cdaf Coding changes for performance in complex() (bug #61912)
Rik <rik@octave.org>
parents: 30594
diff changeset
3703 ComplexNDArray result (re_val.dims ());
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3704
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3705 for (octave_idx_type i = 0; i < re_val.numel (); i++)
30673
1182fcd6cdaf Coding changes for performance in complex() (bug #61912)
Rik <rik@octave.org>
parents: 30594
diff changeset
3706 result.xelem (i) = Complex (re_val.xelem (i), im_val);
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
3707
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
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 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3711 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3712 const NDArray im_val = im.array_value ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3713
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3714 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
3715 error ("complex: dimension mismatch");
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3716
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3717 ComplexNDArray result (re_val.dims (), Complex ());
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3718
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3719 for (octave_idx_type i = 0; i < re_val.numel (); i++)
30673
1182fcd6cdaf Coding changes for performance in complex() (bug #61912)
Rik <rik@octave.org>
parents: 30594
diff changeset
3720 result.xelem (i) = Complex (re_val.xelem (i),
1182fcd6cdaf Coding changes for performance in complex() (bug #61912)
Rik <rik@octave.org>
parents: 30594
diff changeset
3721 im_val.xelem (i));
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3722
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
3723 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
3724 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
3725 }
5476
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3726 }
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3727
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3728 return retval;
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3729 }
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
3730
22590
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 %!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
3733 %!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
3734
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3735 %!test <31974>
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3736 %! 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
3737 %!
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3738 %! assert (1 + Inf*i, complex (1, Inf))
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3739 %! assert (1 + Inf*j, complex (1, Inf))
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3740 %!
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3741 %! ## 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
3742 %! 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
3743 %! 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
3744 %!
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3745 %! 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
3746 %!
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3747 %! 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
3748
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3749 %!test <31974>
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3750 %! x = Inf;
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3751 %! 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
3752 %! 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
3753 %! 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
3754
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3755 %!test <31974>
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3756 %! 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
3757 %! 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
3758 %! 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
3759 %! 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
3760 %! 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
3761
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3762 %!test <31974>
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3763 %! 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
3764 %! 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
3765 %! 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
3766
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3767 %!test <31974>
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3768 %! 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
3769 %! 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
3770 %! 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
3771 %! 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
3772 */
354b7a6e642c Add failing tests for creating numbers with Inf complex parts (bug #31974)
Carnë Draug <carandraug@octave.org>
parents: 22495
diff changeset
3773
3258
4964d5391acc [project @ 1999-07-21 21:51:33 by jwe]
jwe
parents: 3238
diff changeset
3774 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
3775 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
3776 @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
3777 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
3778
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3779 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
3780 matrices.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3781 @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
3782 @end deftypefn */)
3258
4964d5391acc [project @ 1999-07-21 21:51:33 by jwe]
jwe
parents: 3238
diff changeset
3783 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3784 if (args.length () != 1)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
3785 print_usage ();
3258
4964d5391acc [project @ 1999-07-21 21:51:33 by jwe]
jwe
parents: 3238
diff changeset
3786
23582
0cc2011d800e maint: Deprecate is_real_type and replace with isreal.
Rik <rik@octave.org>
parents: 23581
diff changeset
3787 return ovl (args(0).isreal ());
3258
4964d5391acc [project @ 1999-07-21 21:51:33 by jwe]
jwe
parents: 3238
diff changeset
3788 }
4964d5391acc [project @ 1999-07-21 21:51:33 by jwe]
jwe
parents: 3238
diff changeset
3789
3202
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3195
diff changeset
3790 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
3791 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
3792 @deftypefn {} {@var{tf} =} isempty (@var{A})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
3793 Return true if @var{A} is an empty matrix (any one of its dimensions is
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3794 zero).
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3795 @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
3796 @end deftypefn */)
3202
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3195
diff changeset
3797 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3798 if (args.length () != 1)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
3799 print_usage ();
3202
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3195
diff changeset
3800
23577
80c42f4cca13 maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents: 23576
diff changeset
3801 return ovl (args(0).isempty ());
3202
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3195
diff changeset
3802 }
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3195
diff changeset
3803
16779
8fce0ed4894a Specialize is_empty and numel methods for sparse matrices (debian bug #706376)
David Bateman <dbateman@free.fr>
parents: 16077
diff changeset
3804 /*
22737
7abc25e6206a maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22708
diff changeset
3805 ## Debian bug #706376
28915
c40a367a84c0 maint: Use Octave convention of space after function name in libinterp/.
Rik <rik@octave.org>
parents: 28888
diff changeset
3806 %!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
3807 */
8fce0ed4894a Specialize is_empty and numel methods for sparse matrices (debian bug #706376)
David Bateman <dbateman@free.fr>
parents: 16077
diff changeset
3808
3206
d0d2b69dc6c2 [project @ 1998-11-03 02:43:31 by jwe]
jwe
parents: 3204
diff changeset
3809 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
3810 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
3811 @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
3812 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
3813 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
3814
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
3815 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
3816 @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
3817 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
3818 @end deftypefn */)
3206
d0d2b69dc6c2 [project @ 1998-11-03 02:43:31 by jwe]
jwe
parents: 3204
diff changeset
3819 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3820 if (args.length () != 1)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
3821 print_usage ();
3206
d0d2b69dc6c2 [project @ 1998-11-03 02:43:31 by jwe]
jwe
parents: 3204
diff changeset
3822
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23585
diff changeset
3823 return ovl (args(0).isnumeric ());
3206
d0d2b69dc6c2 [project @ 1998-11-03 02:43:31 by jwe]
jwe
parents: 3204
diff changeset
3824 }
d0d2b69dc6c2 [project @ 1998-11-03 02:43:31 by jwe]
jwe
parents: 3204
diff changeset
3825
11435
20f53b3a558f Add tests for sparse forms of logical matrices to islogical, isnumeric.
Rik <octave@nomad.inbox5.com>
parents: 11431
diff changeset
3826 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3827 %!assert (isnumeric (1), true)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3828 %!assert (isnumeric (1i), true)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3829 %!assert (isnumeric ([1,1]), true)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3830 %!assert (isnumeric (single (1)), true)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3831 %!assert (isnumeric (single (1i)), true)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3832 %!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
3833 %!assert (isnumeric (int8 (1)), true)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3834 %!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
3835 %!assert (isnumeric ("Hello World"), false)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3836 %!assert (isnumeric (true), false)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3837 %!assert (isnumeric (false), false)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3838 %!assert (isnumeric ([true, false]), false)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
3839 %!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
3840 */
20f53b3a558f Add tests for sparse forms of logical matrices to islogical, isnumeric.
Rik <octave@nomad.inbox5.com>
parents: 11431
diff changeset
3841
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
3842 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
3843 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
3844 @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
3845 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
3846
711cf9b1be49 doc: Reword isscalar, isvector, isrow, iscolumn, ismatrix, issquare docstrings.
Rik <rik@octave.org>
parents: 28012
diff changeset
3847 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
3848 returns @w{@code{[1, 1]}}.
711cf9b1be49 doc: Reword isscalar, isvector, isrow, iscolumn, ismatrix, issquare docstrings.
Rik <rik@octave.org>
parents: 28012
diff changeset
3849 @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
3850 @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
3851 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3852 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
3853 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
3854
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
3855 // 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
3856 // 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
3857 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
3858
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
3859 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
3860 }
bc52657a7d29 Convert isscalar from an m-file to a built-in function (bug #42422).
Jason Alan Palmer <jalanpalmer@gmail.com>
parents: 18812
diff changeset
3861
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 /*
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 %!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
3864 %!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
3865 %!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
3866 %!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
3867
bc52657a7d29 Convert isscalar from an m-file to a built-in function (bug #42422).
Jason Alan Palmer <jalanpalmer@gmail.com>
parents: 18812
diff changeset
3868 %!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
3869 %!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
3870 %!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
3871
bc52657a7d29 Convert isscalar from an m-file to a built-in function (bug #42422).
Jason Alan Palmer <jalanpalmer@gmail.com>
parents: 18812
diff changeset
3872 %!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
3873 %! 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
3874 %! 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
3875
22737
7abc25e6206a maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22708
diff changeset
3876 ## 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
3877 %!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
3878 %!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
3879 */
bc52657a7d29 Convert isscalar from an m-file to a built-in function (bug #42422).
Jason Alan Palmer <jalanpalmer@gmail.com>
parents: 18812
diff changeset
3880
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3881 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
3882 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
3883 @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
3884 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
3885
28714
d8dcb36bb904 maint: spellcheck documentation ahead of 6.1 release.
Rik <rik@octave.org>
parents: 28043
diff changeset
3886 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
3887 @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
3888 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
3889 @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
3890 @end deftypefn */)
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3891 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3892 if (args.length () != 1)
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3893 print_usage ();
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3894
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
3895 // 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
3896 // 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
3897 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
3898
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
3899 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
3900 }
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3901
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3902 /*
19700
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3903 %!assert (isvector (1), true)
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3904 %!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
3905 %!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
3906 %!assert (isvector ([]), false)
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3907 %!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
3908
19700
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3909 %!assert (isvector ("t"), true)
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3910 %!assert (isvector ("test"), true)
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3911 %!assert (isvector (["test"; "ing"]), false)
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3912
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3913 %!test
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3914 %! s.a = 1;
19700
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3915 %! assert (isvector (s), true);
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3916
22737
7abc25e6206a maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22708
diff changeset
3917 ## Test input validation
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3918 %!error isvector ()
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3919 %!error isvector ([1, 2], 2)
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3920 */
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3921
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3922 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
3923 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
3924 @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
3925 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
3926
711cf9b1be49 doc: Reword isscalar, isvector, isrow, iscolumn, ismatrix, issquare docstrings.
Rik <rik@octave.org>
parents: 28012
diff changeset
3927 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
3928 @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
3929 @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
3930 @end deftypefn */)
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3931 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3932 if (args.length () != 1)
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3933 print_usage ();
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3934
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
3935 // 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
3936 // 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
3937 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
3938
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
3939 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
3940 }
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3941
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3942 /*
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3943 %!assert (isrow ([1, 2, 3]))
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3944 %!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
3945 %!assert (isrow (1))
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3946 %!assert (isrow ([]), false)
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3947 %!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
3948
19700
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3949 %!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
3950 %!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
3951 %!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
3952 %!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
3953 %!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
3954
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3955 %!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
3956 %!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
3957
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3958 %!assert (isrow ("t"), true)
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3959 %!assert (isrow ("test"), true)
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3960 %!assert (isrow (["test"; "ing"]), false)
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3961
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3962 %!test
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3963 %! s.a = 1;
19700
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3964 %! assert (isrow (s), true);
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3965
22737
7abc25e6206a maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22708
diff changeset
3966 ## Test input validation
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3967 %!error isrow ()
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3968 %!error isrow ([1, 2], 2)
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3969 */
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3970
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3971 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
3972 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
3973 @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
3974 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
3975
711cf9b1be49 doc: Reword isscalar, isvector, isrow, iscolumn, ismatrix, issquare docstrings.
Rik <rik@octave.org>
parents: 28012
diff changeset
3976 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
3977 @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
3978 @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
3979 @end deftypefn */)
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3980 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
3981 if (args.length () != 1)
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3982 print_usage ();
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3983
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
3984 // 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
3985 // 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
3986 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
3987
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
3988 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
3989 }
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3990
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3991 /*
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3992 %!assert (iscolumn ([1, 2, 3]), false)
19700
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3993 %!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
3994 %!assert (iscolumn (1), true)
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3995 %!assert (iscolumn ([]), false)
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3996 %!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
3997
19700
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
3998 %!assert (iscolumn ("t"), true)
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
3999 %!assert (iscolumn ("test"), false)
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
4000 %!assert (iscolumn (["test"; "ing"]), false)
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
4001
19700
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
4002 %!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
4003 %!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
4004 %!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
4005 %!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
4006 %!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
4007
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
4008 %!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
4009 %!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
4010
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
4011 %!test
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
4012 %! s.a = 1;
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
4013 %! assert (iscolumn (s));
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
4014
22737
7abc25e6206a maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22708
diff changeset
4015 ## Test input validation
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
4016 %!error iscolumn ()
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
4017 %!error iscolumn ([1, 2], 2)
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
4018 */
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
4019
4028
ef75c970c8f5 [project @ 2002-08-09 07:19:02 by jwe]
jwe
parents: 4025
diff changeset
4020 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
4021 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
4022 @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
4023 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
4024
711cf9b1be49 doc: Reword isscalar, isvector, isrow, iscolumn, ismatrix, issquare docstrings.
Rik <rik@octave.org>
parents: 28012
diff changeset
4025 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
4026 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
4027 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
4028 @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
4029 @end deftypefn */)
3202
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3195
diff changeset
4030 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
4031 if (args.length () != 1)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
4032 print_usage ();
3202
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3195
diff changeset
4033
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
4034 // 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
4035 // 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
4036 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
4037
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
4038 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
4039 }
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3195
diff changeset
4040
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
4041 /*
19700
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
4042 %!assert (ismatrix ([]), true)
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
4043 %!assert (ismatrix (1), true)
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
4044 %!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
4045 %!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
4046
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
4047 %!assert (ismatrix (zeros (0)), true)
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
4048 %!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
4049 %!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
4050 %!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
4051
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
4052 %!assert (ismatrix (single ([])), true)
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
4053 %!assert (ismatrix (single (1)), true)
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
4054 %!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
4055 %!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
4056
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
4057 %!assert (ismatrix ("t"), true)
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
4058 %!assert (ismatrix ("test"), true)
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
4059 %!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
4060
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
4061 %!test
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
4062 %! s.a = 1;
19700
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
4063 %! assert (ismatrix (s), true);
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4064
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4065 %!error ismatrix ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4066 %!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
4067 */
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
4068
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
4069 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
4070 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
4071 @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
4072 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
4073
711cf9b1be49 doc: Reword isscalar, isvector, isrow, iscolumn, ismatrix, issquare docstrings.
Rik <rik@octave.org>
parents: 28012
diff changeset
4074 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
4075 @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
4076 @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
4077 @end deftypefn */)
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
4078 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
4079 if (args.length () != 1)
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
4080 print_usage ();
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
4081
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
4082 // 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
4083 // 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
4084 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
4085
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
4086 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
4087 }
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
4088
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
4089 /*
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
4090 %!assert (issquare ([]))
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
4091 %!assert (issquare (1))
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
4092 %!assert (! issquare ([1, 2]))
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
4093 %!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
4094 %!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
4095 %!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
4096 %!assert (issquare ("t"))
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
4097 %!assert (! issquare ("test"))
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
4098 %!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
4099 %!test
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
4100 %! s.a = 1;
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
4101 %! assert (issquare (s));
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
4102 %!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
4103 %!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
4104
22737
7abc25e6206a maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22708
diff changeset
4105 ## Test input validation
18814
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
4106 %!error issquare ()
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
4107 %!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
4108 */
4f0e4f20a33f Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents: 18813
diff changeset
4109
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3333
diff changeset
4110 static octave_value
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4111 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
4112 {
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3333
diff changeset
4113 octave_value retval;
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
4114
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
4115 int nargin = args.length ();
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
4116
4946
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
4117 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
4118
4946
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
4119 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
4120 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
4121 bool iscomplex = false;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
4122
4481
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4479
diff changeset
4123 if (nargin > 0 && args(nargin-1).is_string ())
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4479
diff changeset
4124 {
4946
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
4125 std::string nm = args(nargin-1).string_value ();
4481
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4479
diff changeset
4126 nargin--;
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4479
diff changeset
4127
4946
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
4128 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
4129 }
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4479
diff changeset
4130
29086
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4131 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
4132 && 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
4133 {
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4134 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
4135 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
4136 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
4137 nargin -= 2;
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4138 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
4139 }
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4140
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
4141 switch (nargin)
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
4142 {
712
36ba0576bd1b [project @ 1994-09-19 14:18:15 by jwe]
jwe
parents: 649
diff changeset
4143 case 0:
36ba0576bd1b [project @ 1994-09-19 14:18:15 by jwe]
jwe
parents: 649
diff changeset
4144 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 767
diff changeset
4145
610
14b2a186a5c0 [project @ 1994-08-14 00:55:49 by jwe]
jwe
parents: 597
diff changeset
4146 case 1:
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
4147 get_dimensions (args(0), fcn, dims);
610
14b2a186a5c0 [project @ 1994-08-14 00:55:49 by jwe]
jwe
parents: 597
diff changeset
4148 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 767
diff changeset
4149
4563
742993a501b9 [project @ 2003-10-29 06:25:12 by jwe]
jwe
parents: 4559
diff changeset
4150 default:
742993a501b9 [project @ 2003-10-29 06:25:12 by jwe]
jwe
parents: 4559
diff changeset
4151 {
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4152 dims.resize (nargin);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4153
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4154 for (int i = 0; i < nargin; i++)
30934
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4155 {
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4156 if (args(i).numel () > 1)
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4157 error ("%s: dimensions must be scalars.", fcn);
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4158
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4159 dims(i) = (args(i).isempty () ? 0 : args(i).idx_type_value (true));
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4160 }
4563
742993a501b9 [project @ 2003-10-29 06:25:12 by jwe]
jwe
parents: 4559
diff changeset
4161 }
742993a501b9 [project @ 2003-10-29 06:25:12 by jwe]
jwe
parents: 4559
diff changeset
4162 break;
4481
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4479
diff changeset
4163 }
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4479
diff changeset
4164
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4165 dims.chop_trailing_singletons ();
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4166
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
4167 check_dimensions (dims, fcn);
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4168
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
4169 // 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
4170 // 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
4171
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4172 // 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
4173 // NDArray to scalar.
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4174
29086
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4175 if (issparse)
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4176 {
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4177 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
4178 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
4179
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4180 switch (dt)
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4181 {
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4182 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
4183 if (iscomplex)
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4184 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
4185 else
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4186 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
4187 break;
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4188
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4189 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
4190 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
4191 break;
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4192
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4193 default:
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4194 // 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
4195 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
4196 }
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4197
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4198 return retval;
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4199 }
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4200
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4201 switch (dt)
4481
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4479
diff changeset
4202 {
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4203 case oct_data_conv::dt_int8:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4204 retval = int8NDArray (dims, val);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4205 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4206
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4207 case oct_data_conv::dt_uint8:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4208 retval = uint8NDArray (dims, val);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4209 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4210
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4211 case oct_data_conv::dt_int16:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4212 retval = int16NDArray (dims, val);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4213 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4214
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4215 case oct_data_conv::dt_uint16:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4216 retval = uint16NDArray (dims, val);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4217 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4218
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4219 case oct_data_conv::dt_int32:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4220 retval = int32NDArray (dims, val);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4221 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4222
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4223 case oct_data_conv::dt_uint32:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4224 retval = uint32NDArray (dims, val);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4225 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4226
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4227 case oct_data_conv::dt_int64:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4228 retval = int64NDArray (dims, val);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4229 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4230
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4231 case oct_data_conv::dt_uint64:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4232 retval = uint64NDArray (dims, val);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4233 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4234
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4235 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
4236 if (iscomplex)
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4237 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
4238 else
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4239 retval = FloatNDArray (dims, val);
20562
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 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
4243 if (iscomplex)
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4244 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
4245 else
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4246 retval = NDArray (dims, val);
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4247 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4248
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4249 case oct_data_conv::dt_logical:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4250 retval = boolNDArray (dims, val);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4251 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4252
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4253 default:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4254 error ("%s: invalid class name", fcn);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4255 break;
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
4256 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
4257
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
4258 return retval;
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
4259 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
4260
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4261 static octave_value
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
4262 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
4263 const char *fcn)
7795
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4264 {
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4265 octave_value retval;
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4266
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4267 int nargin = args.length ();
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 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
4270
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4271 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
4272 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
4273 bool iscomplex = false;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
4274
7795
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4275 if (nargin > 0 && args(nargin-1).is_string ())
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4276 {
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4277 std::string nm = args(nargin-1).string_value ();
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4278 nargin--;
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4279
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4280 dt = oct_data_conv::string_to_data_type (nm);
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4281 }
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4282
29086
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4283 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
4284 && 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
4285 && (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
4286 || 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
4287 {
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4288 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
4289 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
4290 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
4291 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
4292 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
4293 nargin -= 2;
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4294 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
4295 }
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4296
7795
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4297 switch (nargin)
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4298 {
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4299 case 0:
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4300 break;
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4301
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4302 case 1:
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
4303 get_dimensions (args(0), fcn, dims);
7795
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4304 break;
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4305
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4306 default:
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4307 {
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4308 dims.resize (nargin);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4309
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4310 for (int i = 0; i < nargin; i++)
30934
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4311 {
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4312 if (args(i).numel () > 1)
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4313 error ("%s: dimensions must be scalars.", fcn);
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4314
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4315 dims(i) = (args(i).isempty () ? 0 : args(i).idx_type_value (true));
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4316 }
7795
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4317 }
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4318 break;
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4319 }
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4320
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4321 dims.chop_trailing_singletons ();
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4322
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
4323 check_dimensions (dims, fcn);
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4324
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4325 // 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
4326 // NDArray to scalar.
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4327
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 (issparse)
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4329 {
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4330 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
4331 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
4332
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4333 if (iscomplex)
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4334 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
4335 else
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4336 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
4337
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4338 return retval;
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4339 }
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4340
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4341 switch (dt)
7795
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4342 {
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4343 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
4344 if (iscomplex)
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4345 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
4346 else
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4347 retval = FloatNDArray (dims, fval);
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4348 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4349
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4350 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
4351 if (iscomplex)
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4352 retval = ComplexNDArray (dims, Complex (val, 0));
27568
e78b6e7f743c Store constant row vectors for ones(), zeros(), pi(), e() as Ranges for compactness.
Rik <rik@octave.org>
parents: 27435
diff changeset
4353 else
e78b6e7f743c Store constant row vectors for ones(), zeros(), pi(), e() as Ranges for compactness.
Rik <rik@octave.org>
parents: 27435
diff changeset
4354 retval = NDArray (dims, val);
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4355 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4356
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4357 default:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4358 error ("%s: invalid class name", fcn);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4359 break;
7795
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4360 }
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4361
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4362 return retval;
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4363 }
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4364
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
4365 static octave_value
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4366 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
4367 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4368 octave_value retval;
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 int nargin = args.length ();
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 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
4373
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4374 dim_vector dims (1, 1);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
4375
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4376 if (nargin > 0 && args(nargin-1).is_string ())
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 std::string nm = args(nargin-1).string_value ();
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4379 nargin--;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4380
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4381 dt = oct_data_conv::string_to_data_type (nm);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4382 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4383
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4384 switch (nargin)
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4385 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4386 case 0:
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4387 break;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4388
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4389 case 1:
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
4390 get_dimensions (args(0), fcn, dims);
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4391 break;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4392
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4393 default:
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4394 {
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4395 dims.resize (nargin);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4396
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4397 for (int i = 0; i < nargin; i++)
30934
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4398 {
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4399 if (args(i).numel () > 1)
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4400 error ("%s: dimensions must be scalars.", fcn);
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4401
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4402 dims(i) = (args(i).isempty () ? 0 : args(i).idx_type_value (true));
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4403 }
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4404 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4405 break;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4406 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4407
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4408 dims.chop_trailing_singletons ();
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4409
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
4410 check_dimensions (dims, fcn);
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4411
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4412 // 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
4413 // NDArray to scalar.
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 switch (dt)
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4416 {
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4417 case oct_data_conv::dt_single:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4418 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
4419 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4420
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4421 case oct_data_conv::dt_double:
30853
fc3bd70cd1be eliminate range<T>::make_constant function
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
4422 retval = NDArray (dims, val);
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4423 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4424
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4425 default:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4426 error ("%s: invalid class name", fcn);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4427 break;
5747
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
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4430 return retval;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4431 }
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 static octave_value
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4434 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
4435 const char *fcn)
5747
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 octave_value retval;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4438
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4439 int nargin = args.length ();
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4440
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4441 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
4442
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4443 dim_vector dims (1, 1);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
4444
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4445 if (nargin > 0 && args(nargin-1).is_string ())
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4446 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4447 std::string nm = args(nargin-1).string_value ();
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4448 nargin--;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4449
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4450 dt = oct_data_conv::string_to_data_type (nm);
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
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4453 switch (nargin)
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4454 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4455 case 0:
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4456 break;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4457
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4458 case 1:
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
4459 get_dimensions (args(0), fcn, dims);
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4460 break;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4461
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4462 default:
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4463 {
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4464 dims.resize (nargin);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4465
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4466 for (int i = 0; i < nargin; i++)
30934
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4467 {
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4468 if (args(i).numel () > 1)
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4469 error ("%s: dimensions must be scalars.", fcn);
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4470
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4471 dims(i) = (args(i).isempty () ? 0 : args(i).idx_type_value (true));
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4472 }
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4473 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4474 break;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4475 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4476
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4477 dims.chop_trailing_singletons ();
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4478
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
4479 check_dimensions (dims, fcn);
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4480
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4481 // 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
4482 // NDArray to scalar.
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4483
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4484 switch (dt)
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4485 {
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4486 case oct_data_conv::dt_single:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4487 retval = FloatComplexNDArray (dims,
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4488 static_cast<FloatComplex> (val));
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4489 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4490
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4491 case oct_data_conv::dt_double:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4492 retval = ComplexNDArray (dims, val);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4493 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4494
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4495 default:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4496 error ("%s: invalid class name", fcn);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4497 break;
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4498 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4499
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4500 return retval;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4501 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4502
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4503 static octave_value
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4504 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
4505 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4506 octave_value retval;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4507
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4508 int nargin = args.length ();
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4509
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4510 dim_vector dims (1, 1);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
4511
28115
de2c73ae450f allow data type argument for true and false functions
John W. Eaton <jwe@octave.org>
parents: 28043
diff changeset
4512 // 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
4513 // 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
4514
de2c73ae450f allow data type argument for true and false functions
John W. Eaton <jwe@octave.org>
parents: 28043
diff changeset
4515 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
4516 {
de2c73ae450f allow data type argument for true and false functions
John W. Eaton <jwe@octave.org>
parents: 28043
diff changeset
4517 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
4518 nargin--;
de2c73ae450f allow data type argument for true and false functions
John W. Eaton <jwe@octave.org>
parents: 28043
diff changeset
4519
de2c73ae450f allow data type argument for true and false functions
John W. Eaton <jwe@octave.org>
parents: 28043
diff changeset
4520 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
4521 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
4522 }
de2c73ae450f allow data type argument for true and false functions
John W. Eaton <jwe@octave.org>
parents: 28043
diff changeset
4523
29086
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4524 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
4525
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4526 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
4527 && 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
4528 {
a61e1a0f6024 maint: style check C++ files in libinterp/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 30377
diff changeset
4529 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
4530 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
4531
a61e1a0f6024 maint: style check C++ files in libinterp/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 30377
diff changeset
4532 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
4533 nargin -= 2;
a61e1a0f6024 maint: style check C++ files in libinterp/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 30377
diff changeset
4534 }
29086
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4535
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4536 switch (nargin)
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4537 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4538 case 0:
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4539 break;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4540
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4541 case 1:
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
4542 get_dimensions (args(0), fcn, dims);
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4543 break;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4544
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4545 default:
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4546 {
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4547 dims.resize (nargin);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4548
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
4549 for (int i = 0; i < nargin; i++)
30934
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4550 {
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4551 if (args(i).numel () > 1)
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4552 error ("%s: dimensions must be scalars.", fcn);
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4553
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4554 dims(i) = (args(i).isempty () ? 0 : args(i).idx_type_value (true));
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4555 }
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 break;
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
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4560 dims.chop_trailing_singletons ();
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4561
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
4562 check_dimensions (dims, fcn);
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4563
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4564 // 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
4565 // NDArray to scalar.
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
4566
29086
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4567 if (issparse)
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4568 {
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4569 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
4570 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
4571
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4572 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
4573 }
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4574 else
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4575 retval = boolNDArray (dims, val);
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4576
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4577 return retval;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4578 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4579
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3333
diff changeset
4580 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
4581 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
4582 @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
4583 @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
4584 @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
4585 @deftypefnx {} {@var{val} =} ones ([@var{m} @var{n} @dots{}])
31611
535492e34f8f doc: Don't use TexInfo @var{} macro "like" for zeros, ones, etc.
Rik <rik@octave.org>
parents: 31607
diff changeset
4586 @deftypefnx {} {@var{val} =} ones (@dots{}, "like", @var{var})
29218
8469b3aad7ac ones, zeros, NaN, NA, false, true: Document syntax with "like" (bug #50854).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29163
diff changeset
4587 @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
4588 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
4589
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4590 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
4591 @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
4592
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4593 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
4594 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
4595
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4596 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
4597 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
4598
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4599 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4600 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
4601 @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
4602
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
4603 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
4604 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
4605
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4606 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
4607 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
4608
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4609 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4610 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
4611 @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
4612 @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
4613 @end deftypefn */)
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
4614 {
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4615 return fill_matrix (args, 1, "ones");
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
4616 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
4617
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
4618 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4619 %!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
4620 %!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
4621 %!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
4622 %!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
4623
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4624 %!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
4625 %!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
4626 %!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
4627 %!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
4628
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4629 %!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
4630 %!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
4631 %!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
4632 %!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
4633
29086
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4634 %!assert (ones (2, 2, "like", 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
4635 %!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
4636 %!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
4637 %!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
4638 %!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
4639 %!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
4640 %!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
4641
32060
1203a2d81a42 Add BIST tests for Matlab compatibility for functions which accept negative dimensions.
Rik <rik@octave.org>
parents: 32046
diff changeset
4642 ## Note: Matlab compatibility requires using 0 for negative dimensions.
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
4643 %!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
4644
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
4645 ## 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
4646 %!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
4647 %!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
4648 %!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
4649 %!error <sparse ND .* not supported> ones (3, 3, 3, "like", speye (1))
30934
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4650 %!error <must be scalar> ones (1:3, 1)
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4651 %!error <must be scalar> ones (1, 1:3)
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4652 %!error <must be scalar> ones (1, 2, 1:3)
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4653 %!error <must be scalar> ones (1:3, 1, "like", single (1))
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4654 */
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
4655
21405
120bb822c6f4 Handle empty vectors for size of ones(), zeros(), inf(), etc... (bug #47298)
Carnë Draug <carandraug@octave.org>
parents: 21317
diff changeset
4656 /*
120bb822c6f4 Handle empty vectors for size of ones(), zeros(), inf(), etc... (bug #47298)
Carnë Draug <carandraug@octave.org>
parents: 21317
diff changeset
4657 ## 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
4658 ## 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
4659 ## n to be a 1x0 vector (returns 0x0) but not a 0x1 vector. Octave supports
31278
076c8f94d7f4 Allow empty input for dimension vector (bug #63181).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31141
diff changeset
4660 ## row and column vectors and therefore must support 0x1, 1x0, and 0x1x1.
076c8f94d7f4 Allow empty input for dimension vector (bug #63181).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31141
diff changeset
4661 ## Also any empty input results in a 0x0 output.
23573
1b4f4ec53b4a use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents: 23572
diff changeset
4662 %!test <*47298>
30896
c9788d7f6e65 maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents: 30892
diff changeset
4663 %! fcns = {@zeros, @ones, @inf, @nan, @NA, @i, @pi, @e};
c9788d7f6e65 maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents: 30892
diff changeset
4664 %! for idx = 1:numel (fcns)
c9788d7f6e65 maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents: 30892
diff changeset
4665 %! fcn = fcns{idx};
c9788d7f6e65 maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents: 30892
diff changeset
4666 %! assert (fcn (zeros (1, 0)), zeros (0, 0));
c9788d7f6e65 maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents: 30892
diff changeset
4667 %! assert (fcn (zeros (0, 1)), zeros (0, 0));
c9788d7f6e65 maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents: 30892
diff changeset
4668 %! assert (fcn (zeros (0, 1, 1)), zeros (0, 0));
31278
076c8f94d7f4 Allow empty input for dimension vector (bug #63181).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31141
diff changeset
4669 %! assert (fcn (zeros ([])), zeros (0, 0));
076c8f94d7f4 Allow empty input for dimension vector (bug #63181).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31141
diff changeset
4670 %! assert (fcn (zeros (0, 0, 1)), zeros (0, 0));
21405
120bb822c6f4 Handle empty vectors for size of ones(), zeros(), inf(), etc... (bug #47298)
Carnë Draug <carandraug@octave.org>
parents: 21317
diff changeset
4671 %! endfor
120bb822c6f4 Handle empty vectors for size of ones(), zeros(), inf(), etc... (bug #47298)
Carnë Draug <carandraug@octave.org>
parents: 21317
diff changeset
4672 */
120bb822c6f4 Handle empty vectors for size of ones(), zeros(), inf(), etc... (bug #47298)
Carnë Draug <carandraug@octave.org>
parents: 21317
diff changeset
4673
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3333
diff changeset
4674 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
4675 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
4676 @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
4677 @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
4678 @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
4679 @deftypefnx {} {@var{val} =} zeros ([@var{m} @var{n} @dots{}])
31611
535492e34f8f doc: Don't use TexInfo @var{} macro "like" for zeros, ones, etc.
Rik <rik@octave.org>
parents: 31607
diff changeset
4680 @deftypefnx {} {@var{val} =} zeros (@dots{}, "like", @var{var})
29218
8469b3aad7ac ones, zeros, NaN, NA, false, true: Document syntax with "like" (bug #50854).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29163
diff changeset
4681 @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
4682 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
4683
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4684 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
4685 @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
4686
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4687 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
4688 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
4689
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
4690 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
4691 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
4692
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4693 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
4694 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
4695
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4696 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4697 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
4698 @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
4699 @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
4700 @end deftypefn */)
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
4701 {
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4702 return fill_matrix (args, 0, "zeros");
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4703 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4704
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
4705 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4706 %!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
4707 %!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
4708 %!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
4709 %!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
4710
29086
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4711 %!assert (zeros (2, 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
4712 %!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
4713 %!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
4714 %!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
4715 %!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
4716 %!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
4717
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4718 %!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
4719 %!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
4720 %!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
4721 %!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
4722
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4723 %!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
4724 %!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
4725 %!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
4726 %!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
4727
a533a7c4d2cc Emit an error when utility matrices (zeros, ones, rand, etc.) are given a fractional dimension in a dimension vector (bug #54781).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 25927
diff changeset
4728 ## 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
4729 %!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
4730 %!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
4731 %!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
4732 %!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
4733 %!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
4734 %!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
4735 %!error <sparse ND .* not supported> zeros (3, 3, 3, "like", speye (1))
30934
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4736 %!error <must be scalar> zeros (1:3, 1)
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4737 %!error <must be scalar> zeros (1, 1:3)
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4738 %!error <must be scalar> zeros (1, 2, 1:3)
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4739 %!error <must be scalar> zeros (1:3, 1, "like", single (1))
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4740 */
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
4741
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4742 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
4743 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
4744 @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
4745 @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
4746
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
4747 @deftypefn {} {@var{A} =} Inf
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
4748 @deftypefnx {} {@var{A} =} Inf (@var{n})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
4749 @deftypefnx {} {@var{A} =} Inf (@var{n}, @var{m})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
4750 @deftypefnx {} {@var{A} =} Inf (@var{n}, @var{m}, @var{k}, @dots{})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
4751 @deftypefnx {} {@var{A} =} Inf (@dots{}, @var{class})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4752 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
4753 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
4754
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4755 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
4756 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
4757 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
4758
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4759 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4760 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4761 [ 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
4762 @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
4763 @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
4764 @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
4765
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4766 When called with 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
4767
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4768 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
4769 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
4770
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4771 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
4772 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
4773 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
4774
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4775 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
4776 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
4777 @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
4778 @end deftypefn */)
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4779 {
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
4780 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
4781 lo_ieee_float_inf_value (), "Inf");
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4782 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4783
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4784 DEFALIAS (inf, Inf);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4785
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
4786 /*
29086
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4787 %!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
4788 %!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
4789 %!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
4790 %!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
4791
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
4792 %!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
4793 %! 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
4794 %!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
4795 %!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
4796 %!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
4797
32060
1203a2d81a42 Add BIST tests for Matlab compatibility for functions which accept negative dimensions.
Rik <rik@octave.org>
parents: 32046
diff changeset
4798 ## Note: Matlab compatibility requires using 0 for negative dimensions.
1203a2d81a42 Add BIST tests for Matlab compatibility for functions which accept negative dimensions.
Rik <rik@octave.org>
parents: 32046
diff changeset
4799 %!assert (size (Inf (2, -3, 2)), [2, 0, 2])
1203a2d81a42 Add BIST tests for Matlab compatibility for functions which accept negative dimensions.
Rik <rik@octave.org>
parents: 32046
diff changeset
4800
29086
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4801 %!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
4802 %!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
4803 %!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
4804 %!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
4805 %! 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
4806 %!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
4807
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4808 %!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
4809
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4810 %!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
4811 %!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
4812 %!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
4813 %!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
4814 %!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
4815 %!error <input .* floating> Inf (2, "like", uint8 (1))
30934
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4816 %!error <must be scalar> Inf (1:3, 1)
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4817 %!error <must be scalar> Inf (1, 1:3)
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4818 %!error <must be scalar> Inf (1, 2, 1:3)
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4819 %!error <must be scalar> Inf (1:3, 1, "like", single (1))
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4820 */
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
4821
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4822 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
4823 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
4824 @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
4825 @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
4826
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
4827 @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
4828 @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
4829 @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
4830 @deftypefnx {} {@var{val} =} NaN (@var{n}, @var{m}, @var{k}, @dots{})
31611
535492e34f8f doc: Don't use TexInfo @var{} macro "like" for zeros, ones, etc.
Rik <rik@octave.org>
parents: 31607
diff changeset
4831 @deftypefnx {} {@var{val} =} NaN (@dots{}, "like", @var{var})
29218
8469b3aad7ac ones, zeros, NaN, NA, false, true: Document syntax with "like" (bug #50854).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29163
diff changeset
4832 @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
4833 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
4834 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
4835
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4836 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
4837 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
4838 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
4839 @tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4840 ($\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
4841 @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
4842 @ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4843 (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
4844 @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
4845 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
4846
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4847 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
4848 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
4849 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
4850
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4851 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
4852
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4853 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
4854 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
4855
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4856 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
4857 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
4858 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
4859
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
4860 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
4861 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
4862
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4863 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
4864 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
4865 @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
4866 @end deftypefn */)
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4867 {
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
4868 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
4869 lo_ieee_float_nan_value (), "NaN");
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4870 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4871
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4872 DEFALIAS (nan, NaN);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4873
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
4874 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4875 %!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
4876 %!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
4877 %!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
4878 %!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
4879
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
4880 %!assert (NaN (3, "single"),
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
4881 %! single ([NaN, NaN, NaN; NaN, NaN, NaN; NaN, NaN, NaN]))
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4882 %!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
4883 %!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
4884 %!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
4885
29086
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4886 %!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
4887 %!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
4888 %!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
4889 %! 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
4890 %!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
4891 %!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
4892
d0fe364977c1 zeros, ones, NaN, Inf, NA: Add "like" syntax (bug #50865).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28960
diff changeset
4893 %!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
4894
28930
2883b3d08b7e maint: Remove unnecessary parentheses bracketing %!error BIST tests.
Rik <rik@octave.org>
parents: 28919
diff changeset
4895 %!error NaN (3, "int8")
2883b3d08b7e maint: Remove unnecessary parentheses bracketing %!error BIST tests.
Rik <rik@octave.org>
parents: 28919
diff changeset
4896 %!error NaN (2, 3, "int8")
2883b3d08b7e maint: Remove unnecessary parentheses bracketing %!error BIST tests.
Rik <rik@octave.org>
parents: 28919
diff changeset
4897 %!error NaN (3, 2, "int8")
2883b3d08b7e maint: Remove unnecessary parentheses bracketing %!error BIST tests.
Rik <rik@octave.org>
parents: 28919
diff changeset
4898 %!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
4899 %!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
4900 %!error <input .* floating> NaN (2, "like", uint8 (1))
30934
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4901 %!error <must be scalar> NaN (1:3, 1)
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4902 %!error <must be scalar> NaN (1, 1:3)
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4903 %!error <must be scalar> NaN (1, 2, 1:3)
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
4904 %!error <must be scalar> NaN (1:3, 1, "like", single (1))
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
4905 */
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
4906
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4907 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
4908 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
4909 @deftypefn {} {@var{A} =} e
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
4910 @deftypefnx {} {@var{A} =} e (@var{n})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
4911 @deftypefnx {} {@var{A} =} e (@var{n}, @var{m})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
4912 @deftypefnx {} {@var{A} =} e (@var{n}, @var{m}, @var{k}, @dots{})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
4913 @deftypefnx {} {@var{A} =} e (@dots{}, @var{class})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4914 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
4915 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
4916
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4917 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
4918 @tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4919 $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
4920 @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
4921 @ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4922 @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
4923 @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
4924
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4925 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
4926
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
4927 When called with a single argument, return a square matrix with the dimension
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
4928 specified.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4929
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4930 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
4931 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
4932 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
4933
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
4934 The optional argument @var{class} specifies the return type and may be either
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
4935 @qcode{"double"} or @qcode{"single"}.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4936 @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
4937 @end deftypefn */)
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4938 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4939 #if defined (M_E)
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4940 double e_val = M_E;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4941 #else
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4942 double e_val = exp (1.0);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4943 #endif
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4944
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4945 return fill_matrix (args, e_val, "e");
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4946 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4947
24295
48e7efceb427 libinterp/corefcn/data.cc: template eps() to reduce code duplication
Carnë Draug <carandraug@octave.org>
parents: 24219
diff changeset
4948 template <typename T>
48e7efceb427 libinterp/corefcn/data.cc: template eps() to reduce code duplication
Carnë Draug <carandraug@octave.org>
parents: 24219
diff changeset
4949 T
48e7efceb427 libinterp/corefcn/data.cc: template eps() to reduce code duplication
Carnë Draug <carandraug@octave.org>
parents: 24219
diff changeset
4950 eps (const T& x)
48e7efceb427 libinterp/corefcn/data.cc: template eps() to reduce code duplication
Carnë Draug <carandraug@octave.org>
parents: 24219
diff changeset
4951 {
48e7efceb427 libinterp/corefcn/data.cc: template eps() to reduce code duplication
Carnë Draug <carandraug@octave.org>
parents: 24219
diff changeset
4952 T epsval = x.abs ();
48e7efceb427 libinterp/corefcn/data.cc: template eps() to reduce code duplication
Carnë Draug <carandraug@octave.org>
parents: 24219
diff changeset
4953 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
4954 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
4955 {
48e7efceb427 libinterp/corefcn/data.cc: template eps() to reduce code duplication
Carnë Draug <carandraug@octave.org>
parents: 24219
diff changeset
4956 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
4957 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
4958 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
4959 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
4960 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
4961 else
48e7efceb427 libinterp/corefcn/data.cc: template eps() to reduce code duplication
Carnë Draug <carandraug@octave.org>
parents: 24219
diff changeset
4962 {
48e7efceb427 libinterp/corefcn/data.cc: template eps() to reduce code duplication
Carnë Draug <carandraug@octave.org>
parents: 24219
diff changeset
4963 int exponent;
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
4964 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
4965 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
4966 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
4967 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
4968 }
48e7efceb427 libinterp/corefcn/data.cc: template eps() to reduce code duplication
Carnë Draug <carandraug@octave.org>
parents: 24219
diff changeset
4969 }
48e7efceb427 libinterp/corefcn/data.cc: template eps() to reduce code duplication
Carnë Draug <carandraug@octave.org>
parents: 24219
diff changeset
4970 return epsval;
48e7efceb427 libinterp/corefcn/data.cc: template eps() to reduce code duplication
Carnë Draug <carandraug@octave.org>
parents: 24219
diff changeset
4971 }
48e7efceb427 libinterp/corefcn/data.cc: template eps() to reduce code duplication
Carnë Draug <carandraug@octave.org>
parents: 24219
diff changeset
4972
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
4973 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
4974 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
4975 @deftypefn {} {@var{d} =} eps
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
4976 @deftypefnx {} {@var{d} =} eps (@var{x})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
4977 @deftypefnx {} {@var{d} =} eps (@var{n}, @var{m})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
4978 @deftypefnx {} {@var{d} =} eps (@var{n}, @var{m}, @var{k}, @dots{})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
4979 @deftypefnx {} {@var{d} =} eps (@dots{}, @var{class})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4980 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
4981 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
4982
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4983 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
4984 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
4985 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
4986 @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
4987 @tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4988 $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
4989 @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
4990 @ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4991 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
4992 @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
4993 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
4994
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4995 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
4996 @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
4997
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
4998 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
4999 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
5000
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5001 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
5002 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
5003 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
5004 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
5005 @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
5006 @end deftypefn */)
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5007 {
7795
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
5008 octave_value retval;
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
5009
20819
f428cbe7576f eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents: 20816
diff changeset
5010 if (args.length () == 1 && ! args(0).is_string ())
7795
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
5011 {
24295
48e7efceb427 libinterp/corefcn/data.cc: template eps() to reduce code duplication
Carnë Draug <carandraug@octave.org>
parents: 24219
diff changeset
5012 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
5013 if (arg0.is_single_type ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5014 {
24295
48e7efceb427 libinterp/corefcn/data.cc: template eps() to reduce code duplication
Carnë Draug <carandraug@octave.org>
parents: 24219
diff changeset
5015 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
5016 retval = epsval;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5017 }
24296
3981e3a11150 eps: error if input is not of floating point type
Carnë Draug <carandraug@octave.org>
parents: 24295
diff changeset
5018 else if (arg0.is_double_type ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5019 {
24295
48e7efceb427 libinterp/corefcn/data.cc: template eps() to reduce code duplication
Carnë Draug <carandraug@octave.org>
parents: 24219
diff changeset
5020 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
5021 retval = epsval;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5022 }
7795
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
5023 else
24296
3981e3a11150 eps: error if input is not of floating point type
Carnë Draug <carandraug@octave.org>
parents: 24295
diff changeset
5024 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
5025 }
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
5026 else
15213
336f42406671 use numeric_limits functions instead of DBL_MIN, DBL_MAX, etc.
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
5027 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
5028 std::numeric_limits<float>::epsilon (), "eps");
7795
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
5029
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
5030 return retval;
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5031 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5032
7795
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
5033 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5034 %!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
5035 %!assert (eps (1), 2^(-52))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5036 %!assert (eps (2), 2^(-51))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5037 %!assert (eps (realmax), 2^971)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5038 %!assert (eps (0), 2^(-1074))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5039 %!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
5040 %!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
5041 %!assert (eps (Inf), NaN)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5042 %!assert (eps (NaN), NaN)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
5043 %!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
5044 %! [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
5045 %!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
5046 %!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
5047 %!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
5048 %!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
5049 %!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
5050 %!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
5051 %!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
5052 %!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
5053 %!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
5054 %!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
5055 %! single ([2^-24 2^-23 2^-22 2^104 2^-149 2^-149 2^-149 NaN NaN]))
32060
1203a2d81a42 Add BIST tests for Matlab compatibility for functions which accept negative dimensions.
Rik <rik@octave.org>
parents: 32046
diff changeset
5056
1203a2d81a42 Add BIST tests for Matlab compatibility for functions which accept negative dimensions.
Rik <rik@octave.org>
parents: 32046
diff changeset
5057 ## Note: Matlab compatibility requires using 0 for negative dimensions.
1203a2d81a42 Add BIST tests for Matlab compatibility for functions which accept negative dimensions.
Rik <rik@octave.org>
parents: 32046
diff changeset
5058 %!assert (size (eps (2, -3, 2)), [2, 0, 2])
1203a2d81a42 Add BIST tests for Matlab compatibility for functions which accept negative dimensions.
Rik <rik@octave.org>
parents: 32046
diff changeset
5059
24296
3981e3a11150 eps: error if input is not of floating point type
Carnë Draug <carandraug@octave.org>
parents: 24295
diff changeset
5060 %!error <X must be of a floating point type> eps (uint8 ([0 1 2]))
30934
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
5061 %!error <must be scalar> eps (1:3, 1)
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
5062 %!error <must be scalar> eps (1, 1:3)
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
5063 %!error <must be scalar> eps (1, 2, 1:3)
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
5064 %!error <must be scalar> eps (1:3, 1, "single")
7795
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
5065 */
df9519e9990c Handle single precision eps values
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
5066
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5067 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
5068 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5069 @deftypefn {} {@var{p} =} pi
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5070 @deftypefnx {} {@var{p} =} pi (@var{n})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5071 @deftypefnx {} {@var{p} =} pi (@var{n}, @var{m})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5072 @deftypefnx {} {@var{p} =} pi (@var{n}, @var{m}, @var{k}, @dots{})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5073 @deftypefnx {} {@var{p} =} pi (@dots{}, @var{class})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5074 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
5075 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
5076 @tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5077 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
5078 @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
5079 @ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5080 diameter.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5081 @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
5082
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5083 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
5084 @tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5085 $\pi$.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5086 @end tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5087 @ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5088 pi.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5089 @end ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5090
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5091 When called with a single argument, return a square matrix with the dimension
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5092 specified.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5093
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5094 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
5095 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
5096 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
5097
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5098 The optional argument @var{class} specifies the return type and may be either
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5099 @qcode{"double"} or @qcode{"single"}.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5100 @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
5101 @end deftypefn */)
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 #if defined (M_PI)
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5104 double pi_val = M_PI;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5105 #else
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5106 double pi_val = 4.0 * atan (1.0);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5107 #endif
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5108
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5109 return fill_matrix (args, pi_val, "pi");
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5110 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5111
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5112 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
5113 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5114 @deftypefn {} {@var{Rmax} =} realmax
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5115 @deftypefnx {} {@var{Rmax} =} realmax (@var{n})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5116 @deftypefnx {} {@var{Rmax} =} realmax (@var{n}, @var{m})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5117 @deftypefnx {} {@var{Rmax} =} realmax (@var{n}, @var{m}, @var{k}, @dots{})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5118 @deftypefnx {} {@var{Rmax} =} realmax (@dots{}, @var{class})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5119 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
5120 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
5121
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5122 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
5123 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
5124 @tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5125 $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
5126 @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
5127 @ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5128 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
5129 @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
5130 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
5131
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5132 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
5133 @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
5134
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5135 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
5136 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
5137
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5138 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
5139 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
5140 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
5141
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5142 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
5143 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
5144 @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
5145 @end deftypefn */)
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5146 {
15213
336f42406671 use numeric_limits functions instead of DBL_MIN, DBL_MAX, etc.
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
5147 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
5148 std::numeric_limits<float>::max (), "realmax");
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5149 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5150
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5151 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
5152 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5153 @deftypefn {} {@var{Rmin} =} realmin
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5154 @deftypefnx {} {@var{Rmin} =} realmin (@var{n})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5155 @deftypefnx {} {@var{Rmin} =} realmin (@var{n}, @var{m})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5156 @deftypefnx {} {@var{Rmin} =} realmin (@var{n}, @var{m}, @var{k}, @dots{})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5157 @deftypefnx {} {@var{Rmin} =} realmin (@dots{}, @var{class})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5158 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
5159 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
5160
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5161 The actual value is system dependent. On machines that support IEEE floating
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5162 point arithmetic, @code{realmin} is approximately
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5163 @tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5164 $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
5165 @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
5166 @ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5167 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
5168 @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
5169 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
5170
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5171 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
5172 @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
5173
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5174 When called with a single argument, return a square matrix with the dimension
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5175 specified.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5176
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5177 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
5178 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
5179 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
5180
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5181 The optional argument @var{class} specifies the return type and may be either
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5182 @qcode{"double"} or @qcode{"single"}.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5183 @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
5184 @end deftypefn */)
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5185 {
15213
336f42406671 use numeric_limits functions instead of DBL_MIN, DBL_MAX, etc.
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
5186 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
5187 std::numeric_limits<float>::min (), "realmin");
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5188 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5189
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5190 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
5191 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
5192 @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
5193 @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
5194 @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
5195 @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
5196
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5197 @deftypefn {} {@var{A} =} I
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5198 @deftypefnx {} {@var{A} =} I (@var{n})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5199 @deftypefnx {} {@var{A} =} I (@var{n}, @var{m})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5200 @deftypefnx {} {@var{A} =} I (@var{n}, @var{m}, @var{k}, @dots{})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5201 @deftypefnx {} {@var{A} =} I (@dots{}, @var{class})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5202 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
5203 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
5204 @tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5205 $\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
5206 @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
5207 @ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5208 @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
5209 @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
5210
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5211 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
5212 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
5213
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5214 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
5215
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5216 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
5217 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
5218
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5219 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
5220 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
5221 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
5222
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5223 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
5224 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
5225 @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
5226 @end deftypefn */)
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5227 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5228 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
5229 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5230
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5231 DEFALIAS (i, I);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5232 DEFALIAS (J, I);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5233 DEFALIAS (j, I);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5234
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5235 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
5236 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
5237 @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
5238 @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
5239 @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
5240 @deftypefnx {} {@var{val} =} NA (@var{n}, @var{m}, @var{k}, @dots{})
31611
535492e34f8f doc: Don't use TexInfo @var{} macro "like" for zeros, ones, etc.
Rik <rik@octave.org>
parents: 31607
diff changeset
5241 @deftypefnx {} {@var{val} =} NA (@dots{}, "like", @var{var})
29218
8469b3aad7ac ones, zeros, NaN, NA, false, true: Document syntax with "like" (bug #50854).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29163
diff changeset
5242 @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
5243 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
5244 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
5245
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5246 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
5247 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
5248
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5249 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
5250
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5251 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
5252 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
5253
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5254 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
5255 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
5256 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
5257
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
5258 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
5259 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
5260
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 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
5262 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
5263 @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
5264 @end deftypefn */)
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5265 {
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
5266 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
5267 lo_ieee_float_na_value (), "NA");
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5268 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5269
7991
139f47cf17ab Change NA value to support single to double precision conversion
David Bateman <dbateman@free.fr>
parents: 7919
diff changeset
5270 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5271 %!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
5272 %!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
5273 */
7991
139f47cf17ab Change NA value to support single to double precision conversion
David Bateman <dbateman@free.fr>
parents: 7919
diff changeset
5274
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5275 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
5276 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
5277 @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
5278 @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
5279 @deftypefnx {} {@var{val} =} false (@var{n}, @var{m}, @var{k}, @dots{})
31611
535492e34f8f doc: Don't use TexInfo @var{} macro "like" for zeros, ones, etc.
Rik <rik@octave.org>
parents: 31607
diff changeset
5280 @deftypefnx {} {@var{val} =} false (@dots{}, "like", @var{var})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5281 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
5282
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5283 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
5284 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
5285
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5286 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
5287 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
5288
8469b3aad7ac ones, zeros, NaN, NA, false, true: Document syntax with "like" (bug #50854).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29163
diff changeset
5289 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
5290 @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
5291 @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
5292 @end deftypefn */)
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5293 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5294 return fill_matrix (args, false, "false");
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5295 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5296
28115
de2c73ae450f allow data type argument for true and false functions
John W. Eaton <jwe@octave.org>
parents: 28043
diff changeset
5297 /*
de2c73ae450f allow data type argument for true and false functions
John W. Eaton <jwe@octave.org>
parents: 28043
diff changeset
5298 %!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
5299 %!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
5300 %!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
5301 %!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
5302
28115
de2c73ae450f allow data type argument for true and false functions
John W. Eaton <jwe@octave.org>
parents: 28043
diff changeset
5303 %!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
5304 %!error <input .* logical> false (2, 1, "like", sparse (1))
30934
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
5305 %!error <must be scalar> false (1:3, 1)
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
5306 %!error <must be scalar> false (1, 1:3)
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
5307 %!error <must be scalar> false (1, 2, 1:3)
28115
de2c73ae450f allow data type argument for true and false functions
John W. Eaton <jwe@octave.org>
parents: 28043
diff changeset
5308 */
de2c73ae450f allow data type argument for true and false functions
John W. Eaton <jwe@octave.org>
parents: 28043
diff changeset
5309
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5310 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
5311 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
5312 @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
5313 @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
5314 @deftypefnx {} {@var{val} =} true (@var{n}, @var{m}, @var{k}, @dots{})
31611
535492e34f8f doc: Don't use TexInfo @var{} macro "like" for zeros, ones, etc.
Rik <rik@octave.org>
parents: 31607
diff changeset
5315 @deftypefnx {} {@var{val} =} true (@dots{}, "like", @var{var})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5316 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
5317
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5318 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
5319 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
5320
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5321 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
5322 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
5323
8469b3aad7ac ones, zeros, NaN, NA, false, true: Document syntax with "like" (bug #50854).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29163
diff changeset
5324 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
5325 @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
5326 @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
5327 @end deftypefn */)
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5328 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
5329 return fill_matrix (args, true, "true");
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3333
diff changeset
5330 }
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
5331
28115
de2c73ae450f allow data type argument for true and false functions
John W. Eaton <jwe@octave.org>
parents: 28043
diff changeset
5332 /*
de2c73ae450f allow data type argument for true and false functions
John W. Eaton <jwe@octave.org>
parents: 28043
diff changeset
5333 %!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
5334 %!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
5335 %!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
5336 %!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
5337
28115
de2c73ae450f allow data type argument for true and false functions
John W. Eaton <jwe@octave.org>
parents: 28043
diff changeset
5338 %!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
5339 %!error <input .* logical> true (2, 1, "like", double (1))
30934
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
5340 %!error <must be scalar> true (1:3, 1)
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
5341 %!error <must be scalar> true (1, 1:3)
d7f799e6d836 Check that dimensions input arguments for ones/zeros/... are scalar (bug #62291).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30896
diff changeset
5342 %!error <must be scalar> true (1, 2, 1:3)
28115
de2c73ae450f allow data type argument for true and false functions
John W. Eaton <jwe@octave.org>
parents: 28043
diff changeset
5343 */
de2c73ae450f allow data type argument for true and false functions
John W. Eaton <jwe@octave.org>
parents: 28043
diff changeset
5344
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
5345 template <typename MT>
4946
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5346 octave_value
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5347 identity_matrix (int nr, int nc)
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5348 {
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5349 octave_value retval;
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5350
9685
e793865ede63 implement builtin_type
Jaroslav Hajek <highegg@gmail.com>
parents: 9658
diff changeset
5351 typename MT::element_type one (1);
4946
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5352
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5353 if (nr == 1 && nc == 1)
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5354 retval = one;
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5355 else
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5356 {
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5357 dim_vector dims (nr, nc);
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5358
9685
e793865ede63 implement builtin_type
Jaroslav Hajek <highegg@gmail.com>
parents: 9658
diff changeset
5359 typename MT::element_type zero (0);
4946
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5360
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5361 MT m (dims, zero);
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5362
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5363 if (nr > 0 && nc > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5364 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5365 int n = std::min (nr, nc);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5366
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5367 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
5368 m(i, i) = one;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5369 }
4946
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5370
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5371 retval = m;
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5372 }
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5373
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5374 return retval;
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5375 }
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5376
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
5377 #define INSTANTIATE_EYE(T) \
5058
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
5378 template octave_value identity_matrix<T> (int, int)
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
5379
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
5380 INSTANTIATE_EYE (int8NDArray);
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
5381 INSTANTIATE_EYE (uint8NDArray);
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
5382 INSTANTIATE_EYE (int16NDArray);
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
5383 INSTANTIATE_EYE (uint16NDArray);
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
5384 INSTANTIATE_EYE (int32NDArray);
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
5385 INSTANTIATE_EYE (uint32NDArray);
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
5386 INSTANTIATE_EYE (int64NDArray);
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
5387 INSTANTIATE_EYE (uint64NDArray);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7743
diff changeset
5388 INSTANTIATE_EYE (FloatNDArray);
5058
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
5389 INSTANTIATE_EYE (NDArray);
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
5390 INSTANTIATE_EYE (boolNDArray);
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
5391
4945
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
5392 static octave_value
4948
7124436476cb [project @ 2004-08-31 17:57:21 by jwe]
jwe
parents: 4947
diff changeset
5393 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
5394 {
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
5395 octave_value retval;
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
5396
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
5397 // 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
5398 // 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
5399
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5400 switch (dt)
4946
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5401 {
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5402 case oct_data_conv::dt_int8:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5403 retval = identity_matrix<int8NDArray> (nr, nc);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5404 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5405
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5406 case oct_data_conv::dt_uint8:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5407 retval = identity_matrix<uint8NDArray> (nr, nc);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5408 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5409
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5410 case oct_data_conv::dt_int16:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5411 retval = identity_matrix<int16NDArray> (nr, nc);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5412 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5413
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5414 case oct_data_conv::dt_uint16:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5415 retval = identity_matrix<uint16NDArray> (nr, nc);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5416 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5417
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5418 case oct_data_conv::dt_int32:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5419 retval = identity_matrix<int32NDArray> (nr, nc);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5420 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5421
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5422 case oct_data_conv::dt_uint32:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5423 retval = identity_matrix<uint32NDArray> (nr, nc);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5424 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5425
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5426 case oct_data_conv::dt_int64:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5427 retval = identity_matrix<int64NDArray> (nr, nc);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5428 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5429
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5430 case oct_data_conv::dt_uint64:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5431 retval = identity_matrix<uint64NDArray> (nr, nc);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5432 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5433
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5434 case oct_data_conv::dt_single:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5435 retval = FloatDiagMatrix (nr, nc, 1.0f);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5436 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5437
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5438 case oct_data_conv::dt_double:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5439 retval = DiagMatrix (nr, nc, 1.0);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5440 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5441
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5442 case oct_data_conv::dt_logical:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5443 retval = identity_matrix<boolNDArray> (nr, nc);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5444 break;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5445
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5446 default:
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5447 error ("eye: invalid class name");
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5448 break;
4945
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
5449 }
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
5450
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
5451 return retval;
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
5452 }
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
5453
4946
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5454 #undef INT_EYE_MATRIX
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
5455
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1940
diff changeset
5456 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
5457 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5458 @deftypefn {} {@var{I} =} eye (@var{n})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5459 @deftypefnx {} {@var{I} =} eye (@var{m}, @var{n})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5460 @deftypefnx {} {@var{I} =} eye ([@var{m} @var{n}])
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5461 @deftypefnx {} {@var{I} =} eye (@dots{}, @var{class})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5462 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
5463
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5464 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
5465 @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
5466
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5467 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
5468 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
5469 @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
5470 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
5471
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5472 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5473 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5474 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
5475 @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
5476 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
5477 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
5478 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5479 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5480
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5481 The 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
5482
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5483 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5484 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5485 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
5486 @equiv{}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5487 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
5488 @equiv{}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5489 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
5490 @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
5491 @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
5492
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5493 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
5494 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
5495
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5496 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5497 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
5498 @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
5499
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5500 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
5501 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
5502 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
5503 @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
5504 @end deftypefn */)
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
5505 {
4948
7124436476cb [project @ 2004-08-31 17:57:21 by jwe]
jwe
parents: 4947
diff changeset
5506 int nargin = args.length ();
4945
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
5507
4948
7124436476cb [project @ 2004-08-31 17:57:21 by jwe]
jwe
parents: 4947
diff changeset
5508 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
5509
4945
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
5510 // Check for type information.
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
5511
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
5512 if (nargin > 0 && args(nargin-1).is_string ())
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
5513 {
4948
7124436476cb [project @ 2004-08-31 17:57:21 by jwe]
jwe
parents: 4947
diff changeset
5514 std::string nm = args(nargin-1).string_value ();
4945
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
5515 nargin--;
4948
7124436476cb [project @ 2004-08-31 17:57:21 by jwe]
jwe
parents: 4947
diff changeset
5516
7124436476cb [project @ 2004-08-31 17:57:21 by jwe]
jwe
parents: 4947
diff changeset
5517 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
5518 }
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
5519
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5520 if (nargin > 2)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5521 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5522
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5523 octave_value retval;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5524
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5525 if (nargin == 0)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5526 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
5527 else if (nargin == 1)
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
5528 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5529 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
5530 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
5531
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5532 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
5533 }
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5534 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5535 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5536 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
5537 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
5538
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5539 retval = identity_matrix (nr, nc, dt);
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
5540 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
5541
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
5542 return retval;
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
5543 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
5544
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5545 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5546 %!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
5547 %!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
5548
32060
1203a2d81a42 Add BIST tests for Matlab compatibility for functions which accept negative dimensions.
Rik <rik@octave.org>
parents: 32046
diff changeset
5549 %!assert (full (eye (3, "single")), single ([1, 0, 0; 0, 1, 0; 0, 0, 1]))
1203a2d81a42 Add BIST tests for Matlab compatibility for functions which accept negative dimensions.
Rik <rik@octave.org>
parents: 32046
diff changeset
5550 %!assert (full (eye (2, 3, "single")), single ([1, 0, 0; 0, 1, 0]))
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5551
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5552 %!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
5553 %!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
5554
32060
1203a2d81a42 Add BIST tests for Matlab compatibility for functions which accept negative dimensions.
Rik <rik@octave.org>
parents: 32046
diff changeset
5555 ## Note: Matlab compatibility requires using 0 for negative dimensions.
1203a2d81a42 Add BIST tests for Matlab compatibility for functions which accept negative dimensions.
Rik <rik@octave.org>
parents: 32046
diff changeset
5556 %!assert (size (eye (2, -3)), [2, 0])
1203a2d81a42 Add BIST tests for Matlab compatibility for functions which accept negative dimensions.
Rik <rik@octave.org>
parents: 32046
diff changeset
5557
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
5558 ## Test input validation
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
5559 %!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
5560 %!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
5561 %!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
5562 %!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
5563 */
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5564
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
5565 template <typename MT>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
5566 static octave_value
9658
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5567 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
5568 octave_idx_type n)
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5569 {
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5570 typedef typename MT::column_vector_type CVT;
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5571 typedef typename MT::element_type T;
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5572
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5573 octave_value retval;
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5574
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5575 if (base.is_scalar_type ())
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5576 {
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5577 T bs = octave_value_extract<T> (base);
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5578 if (limit.is_scalar_type ())
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5579 {
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5580 T ls = octave_value_extract<T> (limit);
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5581 retval = linspace (bs, ls, n);
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5582 }
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5583 else
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5584 {
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5585 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
5586 CVT bv (lv.numel (), bs);
9658
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5587 retval = linspace (bv, lv, n);
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5588 }
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5589 }
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5590 else
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5591 {
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5592 CVT bv = octave_value_extract<CVT> (base);
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5593 if (limit.is_scalar_type ())
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5594 {
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5595 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
5596 CVT lv (bv.numel (), ls);
9658
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5597 retval = linspace (bv, lv, n);
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5598 }
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5599 else
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5600 {
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5601 CVT lv = octave_value_extract<CVT> (limit);
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5602 retval = linspace (bv, lv, n);
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5603 }
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5604 }
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5605
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5606 return retval;
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5607 }
3429c956de6f extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 9562
diff changeset
5608
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1940
diff changeset
5609 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
5610 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5611 @deftypefn {} {@var{y} =} linspace (@var{start}, @var{end})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5612 @deftypefnx {} {@var{y} =} linspace (@var{start}, @var{end}, @var{n})
24504
5188d936c79a doc: Documentation fixes for linspace, logspace, lookup (bug #52785).
Rik <rik@octave.org>
parents: 24440
diff changeset
5613 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
5614 and @var{end}.
5188d936c79a doc: Documentation fixes for linspace, logspace, lookup (bug #52785).
Rik <rik@octave.org>
parents: 24440
diff changeset
5615
31923
073cc98750c6 doc: Improve documentation for linspace and logspace functions.
Rik <rik@octave.org>
parents: 31706
diff changeset
5616 If the number of elements @var{n} is greater than one, then the endpoints
073cc98750c6 doc: Improve documentation for linspace and logspace functions.
Rik <rik@octave.org>
parents: 31706
diff changeset
5617 @var{start} and @var{end} are always included in the range. If @var{start} is
073cc98750c6 doc: Improve documentation for linspace and logspace functions.
Rik <rik@octave.org>
parents: 31706
diff changeset
5618 greater than @var{end}, the elements are stored in decreasing order. If the
073cc98750c6 doc: Improve documentation for linspace and logspace functions.
Rik <rik@octave.org>
parents: 31706
diff changeset
5619 number of points @var{n} is not specified, a value of 100 is used.
24504
5188d936c79a doc: Documentation fixes for linspace, logspace, lookup (bug #52785).
Rik <rik@octave.org>
parents: 24440
diff changeset
5620
5188d936c79a doc: Documentation fixes for linspace, logspace, lookup (bug #52785).
Rik <rik@octave.org>
parents: 24440
diff changeset
5621 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
5622 @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
5623 @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
5624 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
5625 @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
5626
31923
073cc98750c6 doc: Improve documentation for linspace and logspace functions.
Rik <rik@octave.org>
parents: 31706
diff changeset
5627 Programming Notes: For compatibility with @sc{matlab}, return the second
073cc98750c6 doc: Improve documentation for linspace and logspace functions.
Rik <rik@octave.org>
parents: 31706
diff changeset
5628 argument (@var{end}) when a single value (@var{n} = 1) is requested. If
073cc98750c6 doc: Improve documentation for linspace and logspace functions.
Rik <rik@octave.org>
parents: 31706
diff changeset
5629 @var{n} is not an integer then @code{floor (@var{n})} is used to round the
073cc98750c6 doc: Improve documentation for linspace and logspace functions.
Rik <rik@octave.org>
parents: 31706
diff changeset
5630 number of elements. If @var{n} is zero or negative then an empty 1x0 matrix
073cc98750c6 doc: Improve documentation for linspace and logspace functions.
Rik <rik@octave.org>
parents: 31706
diff changeset
5631 is returned.
24504
5188d936c79a doc: Documentation fixes for linspace, logspace, lookup (bug #52785).
Rik <rik@octave.org>
parents: 24440
diff changeset
5632 @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
5633 @end deftypefn */)
1100
3b6f6c5217e7 [project @ 1995-02-14 01:45:09 by jwe]
jwe
parents: 1032
diff changeset
5634 {
3b6f6c5217e7 [project @ 1995-02-14 01:45:09 by jwe]
jwe
parents: 1032
diff changeset
5635 int nargin = args.length ();
3b6f6c5217e7 [project @ 1995-02-14 01:45:09 by jwe]
jwe
parents: 1032
diff changeset
5636
1940
1b193e313c56 [project @ 1996-02-13 16:28:47 by jwe]
jwe
parents: 1884
diff changeset
5637 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
5638 print_usage ();
1940
1b193e313c56 [project @ 1996-02-13 16:28:47 by jwe]
jwe
parents: 1884
diff changeset
5639
6133
e0065af38cf4 [project @ 2006-11-02 03:33:50 by jwe]
jwe
parents: 5991
diff changeset
5640 octave_idx_type npoints = 100;
1100
3b6f6c5217e7 [project @ 1995-02-14 01:45:09 by jwe]
jwe
parents: 1032
diff changeset
5641 if (nargin == 3)
16077
39129305b914 provide some undocumented matlab behavior for linspace (bug #38151)
John W. Eaton <jwe@octave.org>
parents: 15623
diff changeset
5642 {
39129305b914 provide some undocumented matlab behavior for linspace (bug #38151)
John W. Eaton <jwe@octave.org>
parents: 15623
diff changeset
5643 // 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
5644 // 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
5645 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
5646
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23585
diff changeset
5647 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
5648 npoints = 1;
20466
16b9ec39ff46 Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents: 20405
diff changeset
5649 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
5650 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
5651 else
20573
32a0bf9906c1 linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents: 20562
diff changeset
5652 // 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
5653 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
5654 }
1100
3b6f6c5217e7 [project @ 1995-02-14 01:45:09 by jwe]
jwe
parents: 1032
diff changeset
5655
20573
32a0bf9906c1 linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents: 20562
diff changeset
5656 octave_value arg_1 = args(0);
32a0bf9906c1 linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents: 20562
diff changeset
5657 octave_value arg_2 = args(1);
32a0bf9906c1 linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents: 20562
diff changeset
5658
32a0bf9906c1 linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents: 20562
diff changeset
5659 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
5660 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
5661 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
5662 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
5663
32a0bf9906c1 linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents: 20562
diff changeset
5664 if (! isvector1 || ! isvector2)
24535
22a2bc91cc7f Add more BIST tests for linspace.
Rik <rik@octave.org>
parents: 24534
diff changeset
5665 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
5666
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5667 octave_value retval;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5668
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5669 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
5670 {
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
5671 if (arg_1.iscomplex () || arg_2.iscomplex ())
20573
32a0bf9906c1 linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents: 20562
diff changeset
5672 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
5673 else
20573
32a0bf9906c1 linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents: 20562
diff changeset
5674 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
5675 }
4732
b484cdca27be [project @ 2004-02-04 04:32:48 by jwe]
jwe
parents: 4685
diff changeset
5676 else
20573
32a0bf9906c1 linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents: 20562
diff changeset
5677 {
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
5678 if (arg_1.iscomplex () || arg_2.iscomplex ())
20573
32a0bf9906c1 linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents: 20562
diff changeset
5679 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
5680 else
32a0bf9906c1 linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents: 20562
diff changeset
5681 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
5682 }
1100
3b6f6c5217e7 [project @ 1995-02-14 01:45:09 by jwe]
jwe
parents: 1032
diff changeset
5683
3b6f6c5217e7 [project @ 1995-02-14 01:45:09 by jwe]
jwe
parents: 1032
diff changeset
5684 return retval;
3b6f6c5217e7 [project @ 1995-02-14 01:45:09 by jwe]
jwe
parents: 1032
diff changeset
5685 }
3b6f6c5217e7 [project @ 1995-02-14 01:45:09 by jwe]
jwe
parents: 1032
diff changeset
5686
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5687 /*
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5688 %!test
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5689 %! 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
5690 %! 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
5691 %! 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
5692 %! 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
5693 %! 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
5694 %! 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
5695 %! 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
5696 %! 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
5697 %! 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
5698
20466
16b9ec39ff46 Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents: 20405
diff changeset
5699 ## Test complex values
16b9ec39ff46 Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents: 20405
diff changeset
5700 %!test
16b9ec39ff46 Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents: 20405
diff changeset
5701 %! 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
5702 %! 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
5703 %! assert (obs, exp);
16b9ec39ff46 Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents: 20405
diff changeset
5704
24535
22a2bc91cc7f Add more BIST tests for linspace.
Rik <rik@octave.org>
parents: 24534
diff changeset
5705 ## 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
5706 %!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
5707 %! [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
5708 %!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
5709 %! [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
5710 %!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
5711 %! [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
5712 %!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
5713 %! [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
5714 %!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
5715 %! [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
5716 %!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
5717 %! [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
5718
20466
16b9ec39ff46 Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents: 20405
diff changeset
5719 ## Test class of output
16b9ec39ff46 Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents: 20405
diff changeset
5720 %!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
5721 %!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
5722 %!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
5723
27435
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5724 ## Test symmetry
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5725 %!test <*56659>
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5726 %! x = linspace (-1, 1, 10);
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5727 %! assert (all (x == -fliplr (x)));
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5728 %! x = linspace (-1, 1, 11);
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5729 %! assert (all (x == -fliplr (x)));
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5730
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5731 %!test <*56659>
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5732 %! x = linspace (-1-1i, 1+1i, 10);
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5733 %! assert (all (x == -fliplr (x)));
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5734 %! x = linspace (-1-1i, 1+1i, 11);
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5735 %! assert (all (x == -fliplr (x)));
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5736
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5737 %!test <*56659>
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5738 %! x = linspace (single (-1), 1, 10);
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5739 %! assert (all (x == -fliplr (x)));
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5740 %! x = linspace (single (-1), 1, 11);
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5741 %! assert (all (x == -fliplr (x)));
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5742
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5743 %!test <*56659>
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5744 %! x = linspace (single (-1-1i), 1+1i, 10);
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5745 %! assert (all (x == -fliplr (x)));
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5746 %! x = linspace (single (-1-1i), 1+1i, 11);
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5747 %! assert (all (x == -fliplr (x)));
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5748
20466
16b9ec39ff46 Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents: 20405
diff changeset
5749 ## 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
5750 %!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
5751 %!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
5752 %!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
5753 %!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
5754 %!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
5755 %!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
5756 %!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
5757 %!assert (linspace (10, 20, 2.1), [10 20])
32a0bf9906c1 linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents: 20562
diff changeset
5758 %!assert (linspace (10, 20, 2.9), [10 20])
25237
ca022a8c4015 linspace: handle ranges with equal Inf endpoints (bug #53489)
Maor Shutman <maorus12@gmail.com>
parents: 25103
diff changeset
5759 %!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
5760 %!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
5761 %!assert (linspace (-Inf, Inf, 3), [-Inf, 0, Inf])
31927
fef004fa8575 Improve Matlab compatibility of linspace for Inf endpoints.
Rik <rik@octave.org>
parents: 31924
diff changeset
5762 ## Octave prefers to return NaN which indicates failure of algorithm.
fef004fa8575 Improve Matlab compatibility of linspace for Inf endpoints.
Rik <rik@octave.org>
parents: 31924
diff changeset
5763 %!assert (linspace (-Inf, Inf, 4), [-Inf, NaN, NaN, Inf])
fef004fa8575 Improve Matlab compatibility of linspace for Inf endpoints.
Rik <rik@octave.org>
parents: 31924
diff changeset
5764 %!assert (linspace (-Inf, 0, 3), [-Inf, NaN, 0])
fef004fa8575 Improve Matlab compatibility of linspace for Inf endpoints.
Rik <rik@octave.org>
parents: 31924
diff changeset
5765 %!assert (linspace (-Inf, 0, 4), [-Inf, NaN, NaN, 0])
25237
ca022a8c4015 linspace: handle ranges with equal Inf endpoints (bug #53489)
Maor Shutman <maorus12@gmail.com>
parents: 25103
diff changeset
5766 %!assert (linspace (Inf + 1i, Inf + 1i, 3), [Inf + 1i, Inf + 1i, Inf + 1i])
31927
fef004fa8575 Improve Matlab compatibility of linspace for Inf endpoints.
Rik <rik@octave.org>
parents: 31924
diff changeset
5767 %!assert (linspace (-Inf - 1i, Inf + 1i, 3), [-Inf - 1i, 0 + 0i, Inf + 1i])
fef004fa8575 Improve Matlab compatibility of linspace for Inf endpoints.
Rik <rik@octave.org>
parents: 31924
diff changeset
5768 %!assert (linspace (-Inf - 1i, Inf + 2i, 3), [-Inf - 1i, NaN + 0.5i, Inf + 2i])
fef004fa8575 Improve Matlab compatibility of linspace for Inf endpoints.
Rik <rik@octave.org>
parents: 31924
diff changeset
5769 %!assert (linspace (-Inf - 3i, Inf + 0i, 4),
fef004fa8575 Improve Matlab compatibility of linspace for Inf endpoints.
Rik <rik@octave.org>
parents: 31924
diff changeset
5770 %! [-Inf - 3i, NaN - 2i, NaN - 1i, Inf + 0i])
fef004fa8575 Improve Matlab compatibility of linspace for Inf endpoints.
Rik <rik@octave.org>
parents: 31924
diff changeset
5771 %!assert (linspace (complex (-1, -Inf), complex (1, Inf), 3),
fef004fa8575 Improve Matlab compatibility of linspace for Inf endpoints.
Rik <rik@octave.org>
parents: 31924
diff changeset
5772 %! [complex(-1, -Inf), 0 + 0i, complex(1, Inf)])
fef004fa8575 Improve Matlab compatibility of linspace for Inf endpoints.
Rik <rik@octave.org>
parents: 31924
diff changeset
5773 %!assert (linspace (complex (-1, -Inf), complex (2, Inf), 3),
fef004fa8575 Improve Matlab compatibility of linspace for Inf endpoints.
Rik <rik@octave.org>
parents: 31924
diff changeset
5774 %! [complex(-1, -Inf), complex(0.5, NaN), complex(2, Inf)])
fef004fa8575 Improve Matlab compatibility of linspace for Inf endpoints.
Rik <rik@octave.org>
parents: 31924
diff changeset
5775 %!assert (linspace (complex (-3, -Inf), complex (0, Inf), 4),
fef004fa8575 Improve Matlab compatibility of linspace for Inf endpoints.
Rik <rik@octave.org>
parents: 31924
diff changeset
5776 %! [complex(-3, -Inf), complex(-2, NaN), complex(-1, NaN), complex(0, Inf)])
27435
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5777
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5778 ## 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
5779 ## Inf/-Inf endpoints. See bug #56933. This was dubbed "Won't Fix"
31927
fef004fa8575 Improve Matlab compatibility of linspace for Inf endpoints.
Rik <rik@octave.org>
parents: 31924
diff changeset
5780 ## as Octave prefers to return NaN for some of these conditions to
fef004fa8575 Improve Matlab compatibility of linspace for Inf endpoints.
Rik <rik@octave.org>
parents: 31924
diff changeset
5781 ## better reflect that the algorithm has failed. If the behavior in
fef004fa8575 Improve Matlab compatibility of linspace for Inf endpoints.
Rik <rik@octave.org>
parents: 31924
diff changeset
5782 ## the future is made compatible these tests can be re-instated.
27435
a8a5d2e8807f Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents: 27325
diff changeset
5783 ##%!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
5784 ##%!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
5785 ##%!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
5786 ##%!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
5787 ##%!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
5788 ##%!assert <56933> (linspace (Inf, 0, 4), [Inf, NaN, NaN, 0])
31927
fef004fa8575 Improve Matlab compatibility of linspace for Inf endpoints.
Rik <rik@octave.org>
parents: 31924
diff changeset
5789 ##%!assert (1 ./ linspace (-0, 0, 4), [-Inf, Inf, Inf, Inf])
fef004fa8575 Improve Matlab compatibility of linspace for Inf endpoints.
Rik <rik@octave.org>
parents: 31924
diff changeset
5790
fef004fa8575 Improve Matlab compatibility of linspace for Inf endpoints.
Rik <rik@octave.org>
parents: 31924
diff changeset
5791 ## Test input validation
fef004fa8575 Improve Matlab compatibility of linspace for Inf endpoints.
Rik <rik@octave.org>
parents: 31924
diff changeset
5792 %!error <Invalid call> linspace ()
fef004fa8575 Improve Matlab compatibility of linspace for Inf endpoints.
Rik <rik@octave.org>
parents: 31924
diff changeset
5793 %!error <Invalid call> 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
5794 %!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
5795 %!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
5796 %!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
5797 %!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
5798 */
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
5799
20726
25d676f9619c Preface error() messages with name of function when possible.
Rik <rik@octave.org>
parents: 20720
diff changeset
5800 // 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
5801 // 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
5802
5731
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
5803 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
5804 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5805 @deftypefn {} {@var{B} =} resize (@var{A}, @var{m})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5806 @deftypefnx {} {@var{B} =} resize (@var{A}, @var{m}, @var{n}, @dots{})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5807 @deftypefnx {} {@var{B} =} resize (@var{A}, [@var{m} @var{n} @dots{}])
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5808 Resize @var{A} cutting off elements as necessary.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5809
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5810 In the result, element with certain indices is equal to the corresponding
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5811 element of @var{A} if the indices are within the bounds of @var{A}; otherwise,
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5812 the element is set to zero.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5813
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5814 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
5815
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5816 @example
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5817 B = resize (A, dv)
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5818 @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
5819
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5820 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5821 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
5822
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5823 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5824 @group
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5825 B = zeros (dv, class (A));
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5826 sz = min (dv, size (A));
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5827 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
5828 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
5829 endfor
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5830 B(idx@{:@}) = A(idx@{:@});
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5831 @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
5832 @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
5833
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5834 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5835 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
5836
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5837 If only @var{m} is supplied, and it is a scalar, the dimension of the result is
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5838 @var{m}-by-@var{m}. If @var{m}, @var{n}, @dots{} are all scalars, then the
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5839 dimensions of the result are @var{m}-by-@var{n}-by-@dots{}. If given a vector
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5840 as input, then the dimensions of the result are given by the elements of that
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5841 vector.
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5842
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5843 An object can be resized to more dimensions than it has; in such case the
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5844 missing dimensions are assumed to be 1. Resizing an object to fewer dimensions
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5845 is not possible.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5846 @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
5847 @end deftypefn */)
5731
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
5848 {
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
5849 int nargin = args.length ();
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
5850
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5851 if (nargin < 2)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5852 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5853
5731
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
5854 octave_value retval;
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
5855
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
5856 if (nargin == 2)
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
5857 {
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
5858 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
5859 int ndim = vec.numel ();
5731
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
5860 if (ndim == 1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5861 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5862 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
5863 retval = args(0);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5864 retval = retval.resize (dim_vector (m, m), true);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5865 }
5731
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
5866 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5867 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5868 dim_vector dv;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5869 dv.resize (ndim);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5870 for (int i = 0; i < ndim; i++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5871 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
5872 retval = args(0);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5873 retval = retval.resize (dv, true);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5874 }
5731
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
5875 }
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5876 else
5731
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
5877 {
8799
f6dc6eb57045 improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 8780
diff changeset
5878 dim_vector dv;
f6dc6eb57045 improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 8780
diff changeset
5879 dv.resize (nargin - 1);
f6dc6eb57045 improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 8780
diff changeset
5880 for (octave_idx_type i = 1; i < nargin; i++)
f6dc6eb57045 improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents: 8780
diff changeset
5881 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
5882
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5883 retval = args(0);
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5884 retval = retval.resize (dv, true);
5731
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
5885 }
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5886
5731
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
5887 return retval;
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
5888 }
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
5889
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
5890 // FIXME: should use octave_idx_type for dimensions.
5734
a7d2c47371d2 [project @ 2006-04-04 18:29:13 by jwe]
jwe
parents: 5731
diff changeset
5891
4567
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
5892 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
5893 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5894 @deftypefn {} {@var{B} =} reshape (@var{A}, @var{m}, @var{n}, @dots{})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5895 @deftypefnx {} {@var{B} =} reshape (@var{A}, [@var{m} @var{n} @dots{}])
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5896 @deftypefnx {} {@var{B} =} reshape (@var{A}, @dots{}, [], @dots{})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
5897 @deftypefnx {} {@var{B} =} reshape (@var{A}, @var{size})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5898 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
5899 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
5900
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5901 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
5902 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
5903
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5904 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
5905 matrix.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5906
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5907 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5908 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5909 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
5910 @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
5911 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
5912 @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
5913 @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
5914
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5915 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5916 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
5917 (@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
5918 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
5919
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
5920 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
5921 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
5922 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
5923 @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
5924 @end deftypefn */)
4567
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
5925 {
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
5926 int nargin = args.length ();
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
5927
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5928 if (nargin < 2)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5929 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5930
4567
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
5931 octave_value retval;
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
5932
10693
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
5933 dim_vector new_dims;
4567
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
5934
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
5935 if (nargin == 2)
10693
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
5936 {
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
5937 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
5938
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20218
diff changeset
5939 if (new_size.numel () < 2)
20893
384ff5aa9437 2015 Code Sprint: Eliminate useless return statements after error ().
Rik <rik@octave.org>
parents: 20884
diff changeset
5940 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
5941
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20218
diff changeset
5942 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
5943
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20218
diff changeset
5944 for (octave_idx_type i = 0; i < new_size.numel (); i++)
10693
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
5945 {
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
5946 if (new_size(i) < 0)
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5947 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
5948
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
5949 new_dims(i) = new_size(i);
10693
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
5950 }
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
5951 }
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
5952 else
4567
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
5953 {
10693
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
5954 new_dims = dim_vector::alloc (nargin-1);
5013
1eb9ce5c0152 [project @ 2004-09-21 22:18:07 by jwe]
jwe
parents: 4986
diff changeset
5955 int empty_dim = -1;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
5956
4567
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
5957 for (int i = 1; i < nargin; i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5958 {
23577
80c42f4cca13 maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents: 23576
diff changeset
5959 if (args(i).isempty ())
10693
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
5960 {
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
5961 if (empty_dim > 0)
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5962 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
5963
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
5964 empty_dim = i;
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
5965 new_dims(i-1) = 1;
10693
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
5966 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5967 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5968 {
10693
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
5969 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
5970
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5971 if (new_dims(i-1) < 0)
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
5972 error ("reshape: SIZE must be non-negative");
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5973 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5974 }
5013
1eb9ce5c0152 [project @ 2004-09-21 22:18:07 by jwe]
jwe
parents: 4986
diff changeset
5975
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5976 if (empty_dim > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5977 {
10693
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
5978 octave_idx_type nel = new_dims.numel ();
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5979
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5980 if (nel == 0)
10693
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
5981 new_dims(empty_dim-1) = 0;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5982 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5983 {
10693
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
5984 octave_idx_type a_nel = args(0).numel ();
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
5985 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
5986
10693
d95a6e491a6c improve reshape
Jaroslav Hajek <highegg@gmail.com>
parents: 10687
diff changeset
5987 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
5988 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
5989 "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
5990 nel);
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
5991
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
5992 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
5993 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
5994 }
4567
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
5995 }
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
5996
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
5997 retval = args(0).reshape (new_dims);
4567
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
5998
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
5999 return retval;
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
6000 }
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
6001
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
6002 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6003 %!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
6004 %!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
6005 %!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
6006 %!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
6007
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6008 %!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
6009 %!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
6010 %!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
6011 %!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
6012
32045
f18da620ab4d Fix floating point exception when Sparse array reshaped to 0x0 (bug #64080)
Rik <rik@octave.org>
parents: 31923
diff changeset
6013 %!assert <*64080> (size (reshape (sparse (0, 1), 0, 0)), [0, 0])
f18da620ab4d Fix floating point exception when Sparse array reshaped to 0x0 (bug #64080)
Rik <rik@octave.org>
parents: 31923
diff changeset
6014
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
6015 %!test
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
6016 %! s.a = 1;
17915
56d2b6838405 Issue an error if reshape called with just a single dimension.
Rik <rik@octave.org>
parents: 17843
diff changeset
6017 %! 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
6018
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6019 %!error reshape ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6020 %!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
6021 %!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
6022 %!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
6023 %!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
6024 %!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
6025 %!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
6026 */
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
6027
10694
d97165928d05 implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents: 10693
diff changeset
6028 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
6029 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
6030 @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
6031 @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
6032 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
6033 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
6034
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6035 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
6036
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6037 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
6038 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
6039 @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
6040 @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
6041 @end deftypefn */)
10694
d97165928d05 implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents: 10693
diff changeset
6042 {
11402
a9a3ee461b83 Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents: 11357
diff changeset
6043 int nargin = args.length ();
a9a3ee461b83 Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents: 11357
diff changeset
6044
a9a3ee461b83 Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents: 11357
diff changeset
6045 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
6046 print_usage ();
11402
a9a3ee461b83 Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents: 11357
diff changeset
6047
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6048 int dim = 1;
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
6049 if (nargin == 2)
11402
a9a3ee461b83 Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents: 11357
diff changeset
6050 {
a9a3ee461b83 Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents: 11357
diff changeset
6051 dim = args(1).idx_type_value ();
a9a3ee461b83 Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents: 11357
diff changeset
6052
a9a3ee461b83 Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents: 11357
diff changeset
6053 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
6054 error ("vec: DIM must be greater than zero");
11402
a9a3ee461b83 Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents: 11357
diff changeset
6055 }
a9a3ee461b83 Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents: 11357
diff changeset
6056
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
6057 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
6058 octave_value arg = args(0);
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6059
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6060 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
6061
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
6062 if (dim > 1)
10694
d97165928d05 implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents: 10693
diff changeset
6063 {
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
6064 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
6065
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
6066 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
6067 new_dims(i) = 1;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
6068
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
6069 new_dims(dim-1) = retval.numel ();
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
6070
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
6071 retval = retval.reshape (new_dims);
10694
d97165928d05 implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents: 10693
diff changeset
6072 }
d97165928d05 implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents: 10693
diff changeset
6073
d97165928d05 implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents: 10693
diff changeset
6074 return retval;
d97165928d05 implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents: 10693
diff changeset
6075 }
d97165928d05 implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents: 10693
diff changeset
6076
d97165928d05 implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents: 10693
diff changeset
6077 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6078 %!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
6079 %!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
6080 %!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
6081 %!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
6082 %!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
6083 %!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
6084 %!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
6085 %!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
6086
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6087 %!error vec ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6088 %!error vec (1, 2, 3)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6089 %!error vec ([1, 2; 3, 4], 0)
10694
d97165928d05 implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents: 10693
diff changeset
6090 */
d97165928d05 implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents: 10693
diff changeset
6091
4532
01ee68d18069 [project @ 2003-10-10 00:49:54 by jwe]
jwe
parents: 4516
diff changeset
6092 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
6093 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6094 @deftypefn {} {@var{B} =} squeeze (@var{A})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6095 Remove singleton dimensions from @var{A} and return the result.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
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 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
6098 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
6099 @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
6100 @end deftypefn */)
4532
01ee68d18069 [project @ 2003-10-10 00:49:54 by jwe]
jwe
parents: 4516
diff changeset
6101 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6102 if (args.length () != 1)
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
6103 print_usage ();
4532
01ee68d18069 [project @ 2003-10-10 00:49:54 by jwe]
jwe
parents: 4516
diff changeset
6104
21127
df7891224709 maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents: 21121
diff changeset
6105 return ovl (args(0).squeeze ());
4532
01ee68d18069 [project @ 2003-10-10 00:49:54 by jwe]
jwe
parents: 4516
diff changeset
6106 }
01ee68d18069 [project @ 2003-10-10 00:49:54 by jwe]
jwe
parents: 4516
diff changeset
6107
8458
d254a21e0120 reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents: 8433
diff changeset
6108 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
6109 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
6110 @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
6111 Return a full storage matrix from a sparse, diagonal, or permutation matrix,
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6112 or from a range.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6113 @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
6114 @end deftypefn */)
8458
d254a21e0120 reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents: 8433
diff changeset
6115 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6116 if (args.length () != 1)
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
6117 print_usage ();
8458
d254a21e0120 reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents: 8433
diff changeset
6118
21127
df7891224709 maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents: 21121
diff changeset
6119 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
6120 }
d254a21e0120 reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents: 8433
diff changeset
6121
6945
6bbf56a9718a [project @ 2007-10-02 20:47:22 by jwe]
jwe
parents: 6887
diff changeset
6122 // Compute various norms of the vector X.
6bbf56a9718a [project @ 2007-10-02 20:47:22 by jwe]
jwe
parents: 6887
diff changeset
6123
6953
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
6124 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
6125 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6126 @deftypefn {} {@var{n} =} norm (@var{A})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6127 @deftypefnx {} {@var{n} =} norm (@var{A}, @var{p})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6128 @deftypefnx {} {@var{n} =} norm (@var{A}, @var{p}, @var{opt})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6129 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
6130
22827
c3d3a81ad986 doc: Update documentation for norm, normest, normest1, condest.
Rik <rik@octave.org>
parents: 22791
diff changeset
6131 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
6132
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6133 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
6134
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6135 @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
6136 @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
6137 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
6138
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6139 @item @var{p} = @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
6140 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
6141
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6142 @item @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
6143 @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
6144 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
6145
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6146 @item @var{p} = @qcode{"fro"}
25003
2365c2661b3c doc: Spellcheck documentation ahead of 4.4 release.
Rik <rik@octave.org>
parents: 24859
diff changeset
6147 @cindex @nospell{Frobenius} norm
2365c2661b3c doc: Spellcheck documentation ahead of 4.4 release.
Rik <rik@octave.org>
parents: 24859
diff changeset
6148 @nospell{Frobenius} norm of @var{A},
2365c2661b3c doc: Spellcheck documentation ahead of 4.4 release.
Rik <rik@octave.org>
parents: 24859
diff changeset
6149 @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
6150
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6151 @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
6152 @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
6153 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
6154 @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
6155
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6156 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
6157
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6158 @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
6159 @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
6160 @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
6161
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6162 @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
6163 @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
6164
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6165 @item @var{p} = @qcode{"fro"}
25003
2365c2661b3c doc: Spellcheck documentation ahead of 4.4 release.
Rik <rik@octave.org>
parents: 24859
diff changeset
6166 @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
6167
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6168 @item @var{p} = 0
22827
c3d3a81ad986 doc: Update documentation for norm, normest, normest1, condest.
Rik <rik@octave.org>
parents: 22791
diff changeset
6169 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
6170
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6171 @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
6172 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
6173
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6174 @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
6175 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
6176 @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
6177
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6178 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
6179 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
6180 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
6181 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
6182 @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
6183 @end deftypefn */)
6508
184ab67c3bc1 [project @ 2007-04-07 00:43:09 by jwe]
jwe
parents: 6401
diff changeset
6184 {
184ab67c3bc1 [project @ 2007-04-07 00:43:09 by jwe]
jwe
parents: 6401
diff changeset
6185 int nargin = args.length ();
184ab67c3bc1 [project @ 2007-04-07 00:43:09 by jwe]
jwe
parents: 6401
diff changeset
6186
22789
bedfedcd878e norm: fix error in input argument validation leading to segfault (bug #49634)
Mike Miller <mtmiller@octave.org>
parents: 22749
diff changeset
6187 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
6188 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6189
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6190 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
6191
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6192 if (x_arg.ndims () != 2)
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6193 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
6194
23147
eb5a162c1342 Accept case-insensitive string value for p-value input to norm (bug #50195);
Rik <rik@octave.org>
parents: 23141
diff changeset
6195 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
6196 if (nargin > 1 && args(nargin-1).is_string ())
6508
184ab67c3bc1 [project @ 2007-04-07 00:43:09 by jwe]
jwe
parents: 6401
diff changeset
6197 {
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6198 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
6199 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
6200 if (str == "cols" || str == "columns")
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6201 strflag = sfcols;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6202 else if (str == "rows")
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6203 strflag = sfrows;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6204 else if (str == "fro")
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6205 strflag = sffrob;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6206 else if (str == "inf")
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6207 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
6208 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
6209 strflag = sfneginf;
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6210 else
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6211 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
6212
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6213 // 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
6214 nargin--;
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6215 }
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6216
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6217 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
6218
23577
80c42f4cca13 maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents: 23576
diff changeset
6219 if (p_arg.isempty ())
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6220 p_arg = octave_value (2);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6221 else if (p_arg.is_string ())
6508
184ab67c3bc1 [project @ 2007-04-07 00:43:09 by jwe]
jwe
parents: 6401
diff changeset
6222 {
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6223 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
6224 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
6225 if (strflag != sfcols && strflag != sfrows)
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
6226 error ("norm: invalid combination of options");
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
6227
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
6228 if (str == "cols" || str == "columns" || str == "rows")
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
6229 error ("norm: invalid combination of options");
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
6230
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
6231 if (str == "fro")
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
6232 p_arg = octave_value (2);
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
6233 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
6234 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
6235 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
6236 p_arg = -numeric_limits<double>::Inf ();
6508
184ab67c3bc1 [project @ 2007-04-07 00:43:09 by jwe]
jwe
parents: 6401
diff changeset
6237 else
20980
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
6238 error ("norm: unrecognized option: %s", str.c_str ());
6508
184ab67c3bc1 [project @ 2007-04-07 00:43:09 by jwe]
jwe
parents: 6401
diff changeset
6239 }
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6240 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
6241 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
6242
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6243 octave_value retval;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6244
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6245 switch (strflag)
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6246 {
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6247 case sfmatrix:
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6248 retval = xnorm (x_arg, p_arg);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6249 break;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6250
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6251 case sfcols:
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6252 retval = xcolnorms (x_arg, p_arg);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6253 break;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6254
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6255 case sfrows:
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6256 retval = xrownorms (x_arg, p_arg);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6257 break;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6258
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6259 case sffrob:
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6260 retval = xfrobnorm (x_arg);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6261 break;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6262
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6263 case sfinf:
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
6264 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
6265 break;
23147
eb5a162c1342 Accept case-insensitive string value for p-value input to norm (bug #50195);
Rik <rik@octave.org>
parents: 23141
diff changeset
6266
eb5a162c1342 Accept case-insensitive string value for p-value input to norm (bug #50195);
Rik <rik@octave.org>
parents: 23141
diff changeset
6267 case sfneginf:
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
6268 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
6269 break;
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6270 }
6508
184ab67c3bc1 [project @ 2007-04-07 00:43:09 by jwe]
jwe
parents: 6401
diff changeset
6271
184ab67c3bc1 [project @ 2007-04-07 00:43:09 by jwe]
jwe
parents: 6401
diff changeset
6272 return retval;
184ab67c3bc1 [project @ 2007-04-07 00:43:09 by jwe]
jwe
parents: 6401
diff changeset
6273 }
184ab67c3bc1 [project @ 2007-04-07 00:43:09 by jwe]
jwe
parents: 6401
diff changeset
6274
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
6275 /*
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
6276 %!shared x
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
6277 %! 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
6278 %!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
6279 %!assert (norm (x,1), 20)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6280 %!assert (norm (x,2), 10)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6281 %!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
6282 %!assert (norm (x,Inf), 7)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6283 %!assert (norm (x,-Inf), 1)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6284 %!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
6285 %!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
6286 %!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
6287 %!assert (norm (x), 10)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6288 %!assert (norm ([1e200, 1]), 1e200)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6289 %!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
6290 %!shared m
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
6291 %! m = magic (4);
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6292 %!assert (norm (m,1), 34)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6293 %!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
6294 %!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
6295 %!assert (norm (m,Inf), 34)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6296 %!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
6297 %!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
6298 %! 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
6299 %! 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
6300 %! fhi = 1e+300;
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6301 %!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
6302 %!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
6303
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
6304 %!shared x
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6305 %! 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
6306 %!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
6307 %!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
6308 %!assert (norm (x,2), single (10))
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
6309 %!assert (norm (x,3), single (8.24257059961711), -4* eps ("single"))
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6310 %!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
6311 %!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
6312 %!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
6313 %!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
6314 %!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
6315 %!assert (norm (x), single (10))
18676
5bd1ca29c5f0 Clean up questionable code bits identified by clang sanitize.
Rik <rik@octave.org>
parents: 18212
diff changeset
6316 %!assert (norm (single ([1e38, 1])), single (1e38))
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
6317 %!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
6318 %!shared m
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6319 %! m = single (magic (4));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6320 %!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
6321 %!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
6322 %!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
6323 %!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
6324 %!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
6325 %!shared m2, flo, fhi
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6326 %! 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
6327 %! flo = single (1e-300);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6328 %! fhi = single (1e+300);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6329 %!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
6330 %!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
6331
23141
bfa4ad642fa0 Disallow p-norm of -Inf for matrices (bug #50194).
Rik <rik@octave.org>
parents: 23127
diff changeset
6332 ## Hamming norm (p == 0)
bfa4ad642fa0 Disallow p-norm of -Inf for matrices (bug #50194).
Rik <rik@octave.org>
parents: 23127
diff changeset
6333 %!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
6334
17115
00985134145e norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents: 16892
diff changeset
6335 %!shared q
00985134145e norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents: 16892
diff changeset
6336 %! q = rand (1e3, 3);
21317
a4faec57f4c8 maint: remove semicolon after %!assert tests to follow Octave conventions.
Rik <rik@octave.org>
parents: 21301
diff changeset
6337 %!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
6338 %!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
6339 %!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
6340 %!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
6341 %!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
6342 %!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
6343 %!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
6344 %!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
6345 %!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
6346
22489
93ea313301f9 test: Add bug ids (<#####>) to BIST tests.
Rik <rik@octave.org>
parents: 22440
diff changeset
6347 %!test <30631>
93ea313301f9 test: Add bug ids (<#####>) to BIST tests.
Rik <rik@octave.org>
parents: 22440
diff changeset
6348 %! ## 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
6349 %! 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
6350 %! 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
6351 %! 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
6352
bedfedcd878e norm: fix error in input argument validation leading to segfault (bug #49634)
Mike Miller <mtmiller@octave.org>
parents: 22749
diff changeset
6353 ## 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
6354 %!error norm ()
bedfedcd878e norm: fix error in input argument validation leading to segfault (bug #49634)
Mike Miller <mtmiller@octave.org>
parents: 22749
diff changeset
6355 %!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
6356 %!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
6357 %!error <unrecognized option> norm (1, "rows", "invalid")
22791
da106618264a norm: fix input validation tests
Mike Miller <mtmiller@octave.org>
parents: 22789
diff changeset
6358 %!error <unrecognized option> norm (1, "invalid", "rows")
da106618264a norm: fix input validation tests
Mike Miller <mtmiller@octave.org>
parents: 22789
diff changeset
6359 %!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
6360 %!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
6361 %!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
6362 */
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
6363
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6364 static octave_value
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6365 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
6366 const octave_value_list& args)
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6367 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6368 if (args.length () != 1)
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6369 print_usage ();
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6370
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
6371 return unary_op (op, args(0));
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6372 }
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6373
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6374 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
6375 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
6376 @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
6377 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
6378
24618
c99163d188df doc: Use @var{} around variables in operator functions such as and, or, uplus.
Rik <rik@octave.org>
parents: 24517
diff changeset
6379 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
6380 @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
6381 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6382 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6383 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
6384 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6385
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6386 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
6387 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6388 @deftypefn {} {@var{B} =} uplus (@var{A})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6389 This function and @w{@tcode{+ @var{A}}} are equivalent.
29514
ec768b0f7dcd doc: Use Texinfo commands to improve transpose() docstring rendering.
Rik <rik@octave.org>
parents: 29358
diff changeset
6390 @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
6391 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6392 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6393 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
6394 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6395
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6396 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
6397 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6398 @deftypefn {} {@var{B} =} uminus (@var{A})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6399 This function and @w{@tcode{- @var{A}}} are equivalent.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6400 @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
6401 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6402 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6403 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
6404 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6405
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6406 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
6407 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6408 @deftypefn {} {@var{B} =} transpose (@var{A})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6409 Return the transpose of @var{A}.
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6410
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6411 This function and @tcode{@var{A}.'@:} are equivalent.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6412 @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
6413 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6414 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6415 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
6416 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6417
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
6418 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6419 %!assert (2.', 2)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6420 %!assert (2i.', 2i)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6421 %!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
6422 %!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
6423 %!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
6424 %!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
6425
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6426 %!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
6427
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6428 %!assert (single (2).', single (2))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6429 %!assert (single (2i).', single (2i))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6430 %!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
6431 %!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
6432 %!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
6433 %!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
6434
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6435 %!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
6436 */
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
6437
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6438 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
6439 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6440 @deftypefn {} {@var{B} =} ctranspose (@var{A})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6441 Return the complex conjugate transpose of @var{A}.
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6442
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6443 This function and @tcode{@var{A}'} are equivalent.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6444 @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
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 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
6448 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6449
7814
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
6450 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6451 %!assert (2', 2)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6452 %!assert (2i', -2i)
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6453 %!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
6454 %!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
6455 %!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
6456 %!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
6457
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6458 %!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
6459
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6460 %!assert (single (2)', single (2))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6461 %!assert (single (2i)', single (-2i))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6462 %!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
6463 %!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
6464 %!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
6465 %!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
6466
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
6467 %!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
6468 */
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
6469
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6470 static octave_value
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6471 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
6472 const octave_value_list& args)
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6473 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6474 if (args.length () != 2)
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6475 print_usage ();
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6476
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
6477 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
6478 }
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6479
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6480 static octave_value
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6481 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
6482 octave_value::assign_op aop,
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6483 const octave_value_list& args)
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6484 {
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6485 int nargin = args.length ();
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6486
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
6487 if (nargin < 2)
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6488 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6489
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6490 octave_value retval;
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6491
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
6492 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
6493 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
6494 else
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6495 {
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
6496 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
6497
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
6498 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
6499 retval.assign (aop, args(i));
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6500 }
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6501
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6502 return retval;
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6503 }
9339
c0b104835d0d allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents: 9329
diff changeset
6504
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6505 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
6506 doc: /* -*- texinfo -*-
31141
9e9f5f1e8ec2 doc: Update plus() function to use inputs A, B.
Rik <rik@octave.org>
parents: 31105
diff changeset
6507 @deftypefn {} {@var{C} =} plus (@var{A}, @var{B})
9e9f5f1e8ec2 doc: Update plus() function to use inputs A, B.
Rik <rik@octave.org>
parents: 31105
diff changeset
6508 @deftypefnx {} {@var{C} =} plus (@var{A1}, @var{A2}, @dots{})
9e9f5f1e8ec2 doc: Update plus() function to use inputs A, B.
Rik <rik@octave.org>
parents: 31105
diff changeset
6509 This function and @w{@tcode{@var{A} + @var{B}}} are equivalent.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6510
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6511 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
6512 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
6513
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6514 @example
31141
9e9f5f1e8ec2 doc: Update plus() function to use inputs A, B.
Rik <rik@octave.org>
parents: 31105
diff changeset
6515 (@dots{}((@var{A1} + @var{A2}) + @var{A3}) + @dots{})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6516 @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
6517
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6518 @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
6519 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6520 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6521 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
6522 octave_value::op_add_eq, args);
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6523 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6524
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
6525 /*
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
6526 %!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
6527 %!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
6528 %!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
6529 %!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
6530
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
6531 ## 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
6532 %!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
6533 %!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
6534 */
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
6535
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6536 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
6537 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6538 @deftypefn {} {@var{C} =} minus (@var{A}, @var{B})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6539 This function and @w{@tcode{@var{A} - @var{B}}} are equivalent.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6540 @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
6541 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6542 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6543 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
6544 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6545
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6546 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
6547 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6548 @deftypefn {} {@var{C} =} mtimes (@var{A}, @var{B})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6549 @deftypefnx {} {@var{C} =} mtimes (@var{A1}, @var{A2}, @dots{})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6550 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
6551
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6552 This function and @w{@tcode{@var{A} * @var{B}}} are equivalent.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6553 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
6554 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
6555
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6556 @example
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6557 (@dots{}((@var{A1} * @var{A2}) * @var{A3}) * @dots{})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6558 @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
6559
31547
212cc32100f5 Add new function 'tensorprod' (patch #10288)
Kasper H. Filtenborg <kasper.filtenborg@gmail.com>
parents: 31375
diff changeset
6560 @seealso{times, plus, minus, rdivide, mrdivide, mldivide, mpower, tensorprod}
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 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6562 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6563 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
6564 octave_value::op_mul_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 (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
6568 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6569 @deftypefn {} {@var{C} =} mrdivide (@var{A}, @var{B})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6570 Return the matrix right division of @var{A} and @var{B}.
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6571
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6572 This function and @w{@tcode{@var{A} / @var{B}}} are equivalent.
29825
290eff7148bb mrdivide, mldivide: Document that functions might return minimum norm solutions (bug #60839).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29817
diff changeset
6573
290eff7148bb mrdivide, mldivide: Document that functions might return minimum norm solutions (bug #60839).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29817
diff changeset
6574 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
6575 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
6576 @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
6577 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6578 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6579 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
6580 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6581
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6582 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
6583 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6584 @deftypefn {} {@var{C} =} mpower (@var{A}, @var{B})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6585 Return the matrix power operation of @var{A} raised to the @var{B} power.
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6586
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6587 This function and @w{@tcode{@var{A} ^ @var{B}}} are equivalent.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6588 @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
6589 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6590 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6591 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
6592 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6593
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6594 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
6595 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6596 @deftypefn {} {@var{C} =} mldivide (@var{A}, @var{B})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6597 Return the matrix left division of @var{A} and @var{B}.
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6598
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6599 This function and @w{@tcode{@var{A} @backslashchar{} @var{B}}} are equivalent.
29825
290eff7148bb mrdivide, mldivide: Document that functions might return minimum norm solutions (bug #60839).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29817
diff changeset
6600
290eff7148bb mrdivide, mldivide: Document that functions might return minimum norm solutions (bug #60839).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29817
diff changeset
6601 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
6602 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
6603 @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
6604 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6605 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6606 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
6607 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6608
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6609 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
6610 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6611 @deftypefn {} {@var{TF} =} lt (@var{A}, @var{B})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6612 This function is equivalent to @w{@code{@var{A} < @var{B}}}.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6613 @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
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_op_defun_body (octave_value::op_lt, args);
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6617 }
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 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
6620 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6621 @deftypefn {} {@var{TF} =} le (@var{A}, @var{B})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6622 This function is equivalent to @w{@code{@var{A} <= @var{B}}}.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6623 @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
6624 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6625 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6626 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
6627 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6628
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6629 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
6630 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6631 @deftypefn {} {@var{TF} =} eq (@var{A}, @var{B})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6632 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
6633
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6634 This function is equivalent to @w{@code{@var{A} == @var{B}}}.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6635 @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
6636 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6637 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6638 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
6639 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6640
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6641 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
6642 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6643 @deftypefn {} {@var{TF} =} ge (@var{A}, @var{B})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6644 This function is equivalent to @w{@code{@var{A} >= @var{B}}}.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6645 @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
6646 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6647 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6648 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
6649 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6650
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6651 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
6652 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6653 @deftypefn {} {@var{TF} =} gt (@var{A}, @var{B})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6654 This function is equivalent to @w{@code{@var{A} > @var{B}}}.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6655 @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
6656 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6657 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6658 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
6659 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6660
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6661 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
6662 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6663 @deftypefn {} {@var{TF} =} ne (@var{A}, @var{B})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6664 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
6665
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6666 This function is equivalent to @w{@code{@var{A} != @var{B}}}.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6667 @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
6668 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6669 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6670 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
6671 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6672
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6673 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
6674 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6675 @deftypefn {} {@var{C} =} times (@var{A}, @var{B})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6676 @deftypefnx {} {@var{C} =} times (@var{A1}, @var{A2}, @dots{})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6677 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
6678
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6679 This function and @w{@tcode{@var{A} .* @var{B}}} are equivalent.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6680 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
6681 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
6682
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6683 @example
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6684 (@dots{}((@var{A1} .* @var{A2}) .* @var{A3}) .* @dots{})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6685 @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
6686
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6687 @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
6688 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6689 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6690 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
6691 octave_value::op_el_mul_eq, args);
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6692 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6693
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6694 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
6695 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6696 @deftypefn {} {@var{C} =} rdivide (@var{A}, @var{B})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6697 Return the element-by-element right division of @var{A} and @var{B}.
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6698
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6699 This function and @w{@tcode{@var{A} ./ @var{B}}} are equivalent.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6700 @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
6701 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6702 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6703 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
6704 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6705
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6706 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
6707 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6708 @deftypefn {} {@var{C} =} power (@var{A}, @var{B})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6709 Return the element-by-element operation of @var{A} raised to the
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6710 @var{B} power.
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6711
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6712 This function and @w{@tcode{@var{A} .^ @var{B}}} are equivalent.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6713
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6714 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
6715 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
6716 @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
6717
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6718 @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
6719 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6720 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6721 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
6722 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6723
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6724 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
6725 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6726 @deftypefn {} {@var{C} =} ldivide (@var{A}, @var{B})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6727 Return the element-by-element left division of @var{A} and @var{B}.
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6728
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6729 This function and @w{@tcode{@var{A} .@backslashchar{} @var{B}}} are
24618
c99163d188df doc: Use @var{} around variables in operator functions such as and, or, uplus.
Rik <rik@octave.org>
parents: 24517
diff changeset
6730 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
6731 @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
6732 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6733 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6734 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
6735 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6736
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6737 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
6738 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6739 @deftypefn {} {@var{TF} =} and (@var{x}, @var{y})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6740 @deftypefnx {} {@var{TF} =} and (@var{x1}, @var{x2}, @dots{})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6741 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
6742
24618
c99163d188df doc: Use @var{} around variables in operator functions such as and, or, uplus.
Rik <rik@octave.org>
parents: 24517
diff changeset
6743 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
6744 @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
6745 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
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
24618
c99163d188df doc: Use @var{} around variables in operator functions such as and, or, uplus.
Rik <rik@octave.org>
parents: 24517
diff changeset
6748 (@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
6749 @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
6750
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6751 @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
6752 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6753 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6754 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
6755 octave_value::op_el_and_eq, args);
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6756 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6757
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6758 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
6759 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6760 @deftypefn {} {@var{TF} =} or (@var{x}, @var{y})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
6761 @deftypefnx {} {@var{TF} =} or (@var{x1}, @var{x2}, @dots{})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6762 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
6763
24618
c99163d188df doc: Use @var{} around variables in operator functions such as and, or, uplus.
Rik <rik@octave.org>
parents: 24517
diff changeset
6764 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
6765 @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
6766 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
6767
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6768 @example
24618
c99163d188df doc: Use @var{} around variables in operator functions such as and, or, uplus.
Rik <rik@octave.org>
parents: 24517
diff changeset
6769 (@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
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 @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
6773 @end deftypefn */)
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6774 {
9555
76ecc571879e improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 9517
diff changeset
6775 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
6776 octave_value::op_el_or_eq, args);
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6777 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
6778
19749
c913247c85a8 make colon function work (bug #44290)
John W. Eaton <jwe@octave.org>
parents: 19743
diff changeset
6779 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
6780 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
6781 @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
6782 @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
6783 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
6784 @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
6785
24618
c99163d188df doc: Use @var{} around variables in operator functions such as and, or, uplus.
Rik <rik@octave.org>
parents: 24517
diff changeset
6786 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
6787 @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
6788 @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
6789 @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
6790 @end deftypefn */)
19749
c913247c85a8 make colon function work (bug #44290)
John W. Eaton <jwe@octave.org>
parents: 19743
diff changeset
6791 {
c913247c85a8 make colon function work (bug #44290)
John W. Eaton <jwe@octave.org>
parents: 19743
diff changeset
6792 int nargin = args.length ();
c913247c85a8 make colon function work (bug #44290)
John W. Eaton <jwe@octave.org>
parents: 19743
diff changeset
6793
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6794 if (nargin < 2 || nargin > 3)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6795 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6796
28631
70cdf8de553d move non-member octave_value operator functions to octave namespace
John W. Eaton <jwe@octave.org>
parents: 28115
diff changeset
6797 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
6798 ? 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
6799 : 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
6800 }
c913247c85a8 make colon function work (bug #44290)
John W. Eaton <jwe@octave.org>
parents: 19743
diff changeset
6801
7065
97db94ae2cf0 [project @ 2007-10-25 05:50:55 by jwe]
jwe
parents: 7045
diff changeset
6802 static double tic_toc_timestamp = -1.0;
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6803
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6804 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
6805 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
6806 @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
6807 @deftypefnx {} {@var{id} =} tic ()
25017
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6808 Initialize 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 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
6811 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
6812 set.
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6813
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6814 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
6815 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
6816 @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
6817 timer, rather than the default internal timer.
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6818
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6819 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
6820
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6821 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6822 @group
25017
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6823 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
6824 # many computations later@dots{}
25017
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6825 elapsed_time = toc;
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6826 @end group
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6827 @end example
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6828
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6829 Example 2 : mixed timer id and internal timer
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6830
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6831 @example
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6832 @group
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6833 tic;
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6834 pause (1);
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6835 toc
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6836 @result{} Elapsed time is 1.0089 seconds.
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6837 id = tic;
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6838 pause (2);
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6839 toc (id)
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6840 @result{} Elapsed time is 2.01142 seconds.
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6841 toc
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6842 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
6843 @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
6844 @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
6845
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6846 @noindent
25017
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6847 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
6848
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6849 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
6850 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
6851 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
6852 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
6853 @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
6854 @end deftypefn */)
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6855 {
20819
f428cbe7576f eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents: 20816
diff changeset
6856 if (args.length () != 0)
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6857 warning ("tic: ignoring extra arguments");
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6858
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6859 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
6860 sys::time now;
7065
97db94ae2cf0 [project @ 2007-10-25 05:50:55 by jwe]
jwe
parents: 7045
diff changeset
6861 double tmp = now.double_value ();
97db94ae2cf0 [project @ 2007-10-25 05:50:55 by jwe]
jwe
parents: 7045
diff changeset
6862
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6863 if (nargout > 0)
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 double ip = 0.0;
23639
b488e958d024 Use modf, pow from C++ std library.
Rik <rik@octave.org>
parents: 23625
diff changeset
6866 double frac = std::modf (tmp, &ip);
14635
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
6867 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
6868 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
6869 retval = octave_uint64 (microsecs);
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
6870 }
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6871 else
7065
97db94ae2cf0 [project @ 2007-10-25 05:50:55 by jwe]
jwe
parents: 7045
diff changeset
6872 tic_toc_timestamp = tmp;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
6873
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6874 return retval;
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6875 }
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6876
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6877 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
6878 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
6879 @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
6880 @deftypefnx {} {} toc (@var{id})
25017
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6881 @deftypefnx {} {@var{elapsed_time} =} toc (@dots{})
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6882 Measure elapsed time on a wall-clock timer.
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6883
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6884 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
6885 since the last call to @code{tic}.
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6886
66c35303d272 doc: Redo documentation for tic and toc.
Rik <rik@octave.org>
parents: 25003
diff changeset
6887 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
6888 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
6889
30377
26f2daafa270 doc: Use consistent styling for @ref, @xref, @pxref statements.
Rik <rik@octave.org>
parents: 30329
diff changeset
6890 @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
6891
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6892 @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
6893 @end deftypefn */)
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 int nargin = args.length ();
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6896
14635
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
6897 if (nargin > 1)
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
6898 print_usage ();
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6899
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6900 double start_time = tic_toc_timestamp;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6901
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6902 if (nargin == 1)
7065
97db94ae2cf0 [project @ 2007-10-25 05:50:55 by jwe]
jwe
parents: 7045
diff changeset
6903 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6904 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
6905
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6906 uint64_t val = id.value ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6907
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6908 start_time
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6909 = (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
6910 + 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
6911 / CLOCKS_PER_SEC);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6912
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6913 // 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
6914 // 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
6915 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
6916
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
6917 if (start_time < 0)
28919
7bc983bc2cbd maint: Prepend name of function to error() messages.
Rik <rik@octave.org>
parents: 28915
diff changeset
6918 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
6919
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
6920 sys::time now;
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6921
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6922 double etime = now.double_value () - start_time;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6923
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6924 octave_value retval;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6925 if (nargout > 0)
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6926 retval = etime;
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6927 else
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
6928 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
6929
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6930 return retval;
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6931 }
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6932
14635
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
6933 /*
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
6934 %!shared id
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
6935 %! id = tic ();
14849
f6d3d5b0bd42 test: Use Octave coding conventions for tests for line() and toc().
Rik <octave@nomad.inbox5.com>
parents: 14846
diff changeset
6936 %!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
6937 %!assert (isa (toc (id), "double"))
14635
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
6938 */
f8d5095fa90d improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents: 14615
diff changeset
6939
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6940 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
6941 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
6942 @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
6943 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
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 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
6946 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
6947 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
6948 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
6949
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6950 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
6951 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
6952
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6953 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
6954 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
6955 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
6956 @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
6957 @end deftypefn */)
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6958 {
21078
49852ff04747 maint: Remove unnecessary declarations of retval.
Rik <rik@octave.org>
parents: 21062
diff changeset
6959 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
6960 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
6961
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
6962 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
6963
f0c5dd1ea2b9 hide sys/time.h, sys/times.h, and sys/resource.h headers
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
6964 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
6965 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
6966
f0c5dd1ea2b9 hide sys/time.h, sys/times.h, and sys/resource.h headers
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
6967 return ovl (usr + sys, usr, sys);
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6968 }
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
6969
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
6970 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
6971 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
6972 @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
6973 @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
6974 @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
6975 @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
6976 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
6977
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6978 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
6979
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6980 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
6981
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6982 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6983 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6984 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
6985 @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
6986 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
6987 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
6988 @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
6989 @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
6990
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6991 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
6992 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
6993 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
6994 @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
6995
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
6996 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
6997 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
6998 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
6999
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7000 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7001 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7002 [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
7003 @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
7004 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
7005 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
7006 @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
7007 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
7008 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
7009 @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
7010 @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
7011
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7012 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
7013 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
7014
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7015 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
7016 (@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
7017 (@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
7018
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7019 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7020 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7021 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
7022 @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
7023 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
7024 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
7025 @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
7026 @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
7027
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7028 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
7029 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
7030
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7031 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
7032 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
7033 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
7034
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7035 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
7036 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
7037 @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
7038 @end deftypefn */)
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7039 {
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7040 int nargin = args.length ();
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7041
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7042 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
7043 print_usage ();
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7044
20884
f1b2a2dbc0e1 2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents: 20853
diff changeset
7045 sortmode smode = ASCENDING;
f1b2a2dbc0e1 2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents: 20853
diff changeset
7046 bool return_idx = (nargout > 1);
20921
4d3daf7e43f3 eliminate trailing whitespace in source files
John W. Eaton <jwe@octave.org>
parents: 20918
diff changeset
7047 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
7048 octave_value arg = args(0);
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7049
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7050 int dim = 0;
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7051 if (nargin > 1)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7052 {
20884
f1b2a2dbc0e1 2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents: 20853
diff changeset
7053 if (have_sortmode)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
7054 {
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
7055 std::string mode = args(1).string_value ();
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
7056 if (mode == "ascend")
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
7057 smode = ASCENDING;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
7058 else if (mode == "descend")
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
7059 smode = DESCENDING;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
7060 else
23803
90689bdbe048 Use C++11 raw string literals to avoid escaping double quotes.
Rik <rik@octave.org>
parents: 23748
diff changeset
7061 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
7062 }
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7063 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
7064 dim = args(1).nint_value () - 1;
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7065 }
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7066
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7067 if (nargin > 2)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7068 {
20884
f1b2a2dbc0e1 2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents: 20853
diff changeset
7069 if (have_sortmode)
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7070 error ("sort: DIM must be a valid dimension");
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7071
20700
68e3a747ca02 rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents: 20652
diff changeset
7072 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
7073
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7074 if (mode == "ascend")
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
7075 smode = ASCENDING;
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7076 else if (mode == "descend")
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
7077 smode = DESCENDING;
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7078 else
23803
90689bdbe048 Use C++11 raw string literals to avoid escaping double quotes.
Rik <rik@octave.org>
parents: 23748
diff changeset
7079 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
7080 }
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7081
10285
22a7913bbeb5 optimize return values of find and sort
Jaroslav Hajek <highegg@gmail.com>
parents: 10277
diff changeset
7082 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
7083 if (nargin == 1 || have_sortmode)
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7084 {
10285
22a7913bbeb5 optimize return values of find and sort
Jaroslav Hajek <highegg@gmail.com>
parents: 10277
diff changeset
7085 dim = dv.first_non_singleton ();
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7086 }
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7087 else
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7088 {
10703
5eb420d92307 fix sort and nth_element when trailing singleton dim is specified
Jaroslav Hajek <highegg@gmail.com>
parents: 10695
diff changeset
7089 if (dim < 0)
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7090 error ("sort: DIM must be a valid dimension");
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7091 }
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7092
20884
f1b2a2dbc0e1 2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents: 20853
diff changeset
7093 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
7094
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7095 if (return_idx)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7096 {
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7097 Array<octave_idx_type> sidx;
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7098
20884
f1b2a2dbc0e1 2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents: 20853
diff changeset
7099 // 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
7100 // 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
7101 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
7102 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
7103 }
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7104 else
20884
f1b2a2dbc0e1 2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents: 20853
diff changeset
7105 retval = ovl (arg.sort (dim, smode));
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7106
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7107 return retval;
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7108 }
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7109
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7110 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7111 ## Double
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7112 %!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
7113 %!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
7114 %!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
7115 %!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
7116 %!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
7117 %!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
7118 %!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
7119 %!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
7120 %!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
7121 %!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
7122 %!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
7123 %!assert (sort (1), 1)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7124
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7125 %!test
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7126 %! [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
7127 %! 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
7128 %! 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
7129
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7130 ## Complex
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7131 %!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
7132 %!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
7133 %!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
7134 %!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
7135 %!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
7136 %!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
7137 %!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
7138 %!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
7139 %!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
7140 %!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
7141 %!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
7142 %!assert (sort (1i), 1i)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7143
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7144 %!test
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7145 %! [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
7146 %! 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
7147 %! 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
7148
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7149 ## Single
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7150 %!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
7151 %!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
7152 %! 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
7153 %!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
7154 %! 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
7155 %!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
7156 %! 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
7157 %!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
7158 %! 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
7159 %!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
7160 %! 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
7161 %!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
7162 %! 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
7163 %!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
7164 %! 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
7165 %!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
7166 %! 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
7167 %!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
7168 %! 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
7169 %!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
7170 %! 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
7171 %!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
7172
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
7173 %!test
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7174 %! [v, i] = sort (single ([NaN, 1, -1, Inf, 1]));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7175 %! 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
7176 %! 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
7177
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7178 ## Single Complex
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7179 %!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
7180 %!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
7181 %! 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
7182 %!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
7183 %! 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
7184 %!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
7185 %! 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
7186 %!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
7187 %! 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
7188 %!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
7189 %! 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
7190 %!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
7191 %! 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
7192 %!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
7193 %! 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
7194 %!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
7195 %! 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
7196 %!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
7197 %! 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
7198 %!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
7199 %! 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
7200 %!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
7201
87865ed7405f Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents: 7795
diff changeset
7202 %!test
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7203 %! [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
7204 %! 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
7205 %! 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
7206
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7207 ## Bool
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7208 %!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
7209 %!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
7210 %!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
7211 %!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
7212 %!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
7213 %! [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
7214 %!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
7215 %! [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
7216 %!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
7217 %! [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
7218 %!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
7219 %! [true, true, false, false])
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7220 %!assert (sort (true), true)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7221
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7222 %!test
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7223 %! [v, i] = sort ([true, false, true, false]);
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7224 %! 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
7225 %! 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
7226
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7227 ## Sparse Double
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7228 %!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
7229 %! 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
7230 %!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
7231 %! 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
7232 %!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
7233 %! 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
7234 %!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
7235 %! 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
7236 %!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
7237 %! 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
7238 %!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
7239 %! 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
7240 %!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
7241 %! 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
7242 %!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
7243 %! sparse ([NaN, Inf, 2, 1, 0, 0, -1]))
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7244
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7245 %!shared a
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7246 %! a = randn (10, 10);
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7247 %! a(a < 0) = 0;
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7248 %!assert (sort (sparse (a)), sparse (sort (a)))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7249 %!assert (sort (sparse (a), 1), sparse (sort (a, 1)))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7250 %!assert (sort (sparse (a), 2), sparse (sort (a, 2)))
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);
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7253 %! [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
7254 %! assert (vs, sparse (v));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7255 %! assert (is, i);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7256
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7257 ## Sparse Complex
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7258 %!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
7259 %! 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
7260 %!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
7261 %! 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
7262 %!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
7263 %! 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
7264 %!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
7265 %! 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
7266 %!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
7267 %! 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
7268 %!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
7269 %! 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
7270 %!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
7271 %! 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
7272 %!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
7273 %! sparse ([NaN, Inf, 2, -1, 1i, 0, 0]))
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7274
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7275 %!shared a
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
7276 %! a = randn (10, 10);
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7277 %! a(a < 0) = 0;
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7278 %! a = 1i * a;
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7279 %!assert (sort (sparse (a)), sparse (sort (a)))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7280 %!assert (sort (sparse (a), 1), sparse (sort (a, 1)))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7281 %!assert (sort (sparse (a), 2), sparse (sort (a, 2)))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7282 %!test
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7283 %! [v, i] = sort (a);
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7284 %! [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
7285 %! assert (vs, sparse (v));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7286 %! assert (is, i);
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7287
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7288 ## Sparse Bool
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30329
diff changeset
7289 %!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
7290 %! 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
7291 %!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
7292 %! 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
7293 %!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
7294 %! 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
7295 %!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
7296 %! 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
7297 %!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
7298 %! 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
7299 %!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
7300 %! 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
7301 %!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
7302 %! 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
7303 %!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
7304 %! sparse ([true, true, false, false]))
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7305
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7306 %!test
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7307 %! [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
7308 %! 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
7309 %! 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
7310
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7311 ## Cell string array
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7312 %!shared a, b, c
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7313 %! a = {"Alice", "Cecile", "Eric", "Barry", "David"};
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7314 %! b = {"Alice", "Barry", "Cecile", "David", "Eric"};
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7315 %! 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
7316 %!assert (sort (a), b)
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7317 %!assert (sort (a, 1), a)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7318 %!assert (sort (a, 2), b)
10707
69c5f5ec55d7 fix invalid sort tests
Jaroslav Hajek <highegg@gmail.com>
parents: 10703
diff changeset
7319 %!assert (sort (a, 3), a)
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7320 %!assert (sort (a, "ascend"), b)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7321 %!assert (sort (a, 2, "ascend"), b)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7322 %!assert (sort (a, "descend"), c)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7323 %!assert (sort (a, 2, "descend"), c)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7324
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7325 %!test
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7326 %! [v, i] = sort (a);
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7327 %! 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
7328
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7329 %!error sort ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7330 %!error sort (1, 2, 3, 4)
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7331 */
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
7332
30891
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7333 // Sort the rows of the matrix @var{a} according to the order
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7334 // specified by @var{mode}, which can either be 'ascend' or 'descend'
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7335 // and return the index vector corresponding to the sort order.
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7336 //
30892
1a3cc2811090 doc: Update documentation for __sort_rows_idx__.
Rik <rik@octave.org>
parents: 30891
diff changeset
7337 // FIXME: This function does not yet support sparse matrices.
1a3cc2811090 doc: Update documentation for __sort_rows_idx__.
Rik <rik@octave.org>
parents: 30891
diff changeset
7338
30891
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7339 DEFUN (__sort_rows_idx__, args, ,
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7340 doc: /* -*- texinfo -*-
30892
1a3cc2811090 doc: Update documentation for __sort_rows_idx__.
Rik <rik@octave.org>
parents: 30891
diff changeset
7341 @deftypefn {} {@var{idx} =} __sort_rows_idx__ (@var{A}, @var{mode})
1a3cc2811090 doc: Update documentation for __sort_rows_idx__.
Rik <rik@octave.org>
parents: 30891
diff changeset
7342 Called internally from @file{sortrows.m}.
30891
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7343 @end deftypefn */)
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7344 {
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7345 int nargin = args.length ();
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7346
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7347 if (nargin < 1 || nargin > 2)
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7348 print_usage ();
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7349
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7350 if (nargin == 2 && ! args(1).is_string ())
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7351 error ("__sort_rows_idx__: second argument must be a string");
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7352
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7353 sortmode smode = ASCENDING;
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7354 if (nargin > 1)
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7355 {
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7356 std::string mode = args(1).string_value ();
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7357 if (mode == "ascend")
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7358 smode = ASCENDING;
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7359 else if (mode == "descend")
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7360 smode = DESCENDING;
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7361 else
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7362 error (R"(__sort_rows_idx__: MODE must be either "ascend" or "descend")");
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7363 }
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7364
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7365 octave_value arg = args(0);
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7366
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7367 if (arg.issparse ())
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7368 error ("__sort_rows_idx__: sparse matrices not yet supported");
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7369
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7370 if (arg.ndims () != 2)
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7371 error ("__sort_rows_idx__: needs a 2-D object");
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7372
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7373 Array<octave_idx_type> idx = arg.sort_rows_idx (smode);
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7374
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7375 // This cannot be ovl(), relies on special overloaded octave_value call.
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7376 return octave_value (idx, true, true);
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7377 }
79b3c0b5c265 maint: Backed out changeset 3a15bf04cb7f (__sort_rows_idx__ is used).
Rik <rik@octave.org>
parents: 30889
diff changeset
7378
9765
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7379 static sortmode
20720
7c21b151b8b4 build: Fix warning messages from compiler.
Rik <rik@octave.org>
parents: 20711
diff changeset
7380 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
7381 {
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
7382 // 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
7383 // about possibly using sortmode uninitialized.
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
7384 // 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
7385 sortmode smode = UNSORTED;
9765
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7386
20711
7b608fadc663 Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents: 20704
diff changeset
7387 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
7388
25484
b7db401e1a99 Use "ascend"/"descend" for issorted direction (bug #54147).
Rik <rik@octave.org>
parents: 25473
diff changeset
7389 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
7390 smode = ASCENDING;
25484
b7db401e1a99 Use "ascend"/"descend" for issorted direction (bug #54147).
Rik <rik@octave.org>
parents: 25473
diff changeset
7391 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
7392 smode = DESCENDING;
ba2b07c13913 use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents: 20574
diff changeset
7393 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
7394 smode = UNSORTED;
9765
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7395 else
25484
b7db401e1a99 Use "ascend"/"descend" for issorted direction (bug #54147).
Rik <rik@octave.org>
parents: 25473
diff changeset
7396 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
7397
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7398 return smode;
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7399 }
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7400
8721
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
7401 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
7402 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
7403 @deftypefn {} {@var{tf} =} issorted (@var{A})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
7404 @deftypefnx {} {@var{tf} =} issorted (@var{A}, @var{mode})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
7405 @deftypefnx {} {@var{tf} =} issorted (@var{A}, "rows", @var{mode})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
7406 Return true if the vector @var{A} is sorted according to @var{mode}, which
30594
0cb3f48da9da doc: clarifies issorted only operates on vectors (bug #61765)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents: 30565
diff changeset
7407 may be either @qcode{"ascend"}, @qcode{"descend"}, or @qcode{"either"}.
27034
df32e0cf0992 doc: Fix names of options in issorted (bug #56087).
Rik <rik@octave.org>
parents: 26376
diff changeset
7408
df32e0cf0992 doc: Fix names of options in issorted (bug #56087).
Rik <rik@octave.org>
parents: 26376
diff changeset
7409 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
7410 manner as @code{sort}.
df32e0cf0992 doc: Fix names of options in issorted (bug #56087).
Rik <rik@octave.org>
parents: 26376
diff changeset
7411
30594
0cb3f48da9da doc: clarifies issorted only operates on vectors (bug #61765)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents: 30565
diff changeset
7412 If the optional argument @qcode{"rows"} is supplied, check whether the matrix
0cb3f48da9da doc: clarifies issorted only operates on vectors (bug #61765)
Nicholas R. Jankowski <jankowski.nicholas@gmail.com>
parents: 30565
diff changeset
7413 is sorted by rows as output by the function @code{sortrows} (with no options).
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7414
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7415 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
7416 @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
7417 @end deftypefn */)
8721
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
7418 {
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
7419 int nargin = args.length ();
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
7420
9765
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7421 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
7422 print_usage ();
9765
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7423
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7424 bool by_rows = false;
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7425
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7426 sortmode smode = ASCENDING;
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7427
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7428 if (nargin > 1)
8721
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
7429 {
9765
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7430 if (nargin == 3)
20720
7c21b151b8b4 build: Fix warning messages from compiler.
Rik <rik@octave.org>
parents: 20711
diff changeset
7431 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
7432
20700
68e3a747ca02 rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents: 20652
diff changeset
7433 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
7434 if (tmp == "rows")
ba2b07c13913 use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents: 20574
diff changeset
7435 by_rows = true;
9765
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7436 else
20720
7c21b151b8b4 build: Fix warning messages from compiler.
Rik <rik@octave.org>
parents: 20711
diff changeset
7437 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
7438 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
7439
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7440 octave_value retval;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7441
9765
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7442 octave_value arg = args(0);
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7443
25850
153495e05477 issorted: return true on an empty array (bug #54599)
Mike Miller <mtmiller@octave.org>
parents: 25646
diff changeset
7444 if (arg.isempty ())
153495e05477 issorted: return true on an empty array (bug #54599)
Mike Miller <mtmiller@octave.org>
parents: 25646
diff changeset
7445 retval = true;
153495e05477 issorted: return true on an empty array (bug #54599)
Mike Miller <mtmiller@octave.org>
parents: 25646
diff changeset
7446 else if (by_rows)
9765
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7447 {
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
7448 if (arg.issparse ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10303
diff changeset
7449 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
7450
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7451 if (arg.ndims () != 2)
21014
b9d4c3615e89 maint: Capitalize D for dimension in messages and comments.
Rik <rik@octave.org>
parents: 20980
diff changeset
7452 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
7453
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7454 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
7455 }
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7456 else
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7457 {
23592
80e3bfb7bd5a maint: Deprecate is_vector and replace with isvector.
Rik <rik@octave.org>
parents: 23588
diff changeset
7458 if (! arg.dims ().isvector ())
8721
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
7459 error ("issorted: needs a vector");
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7460
23588
0549061d35b9 maint: Deprecate is_sorted and replace with issorted.
Rik <rik@octave.org>
parents: 23587
diff changeset
7461 retval = args(0).issorted (smode) != UNSORTED;
8721
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
7462 }
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
7463
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
7464 return retval;
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
7465 }
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
7466
9765
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7467 /*
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7468 %!shared sm, um, sv, uv
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7469 %! sm = [1, 2; 3, 4];
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7470 %! um = [3, 1; 2, 4];
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7471 %! sv = [1, 2, 3, 4];
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7472 %! uv = [2, 1, 4, 3];
20809
9e9892519a7c Add more BIST tests for issorted.
Rik <rik@octave.org>
parents: 20806
diff changeset
7473
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7474 %!assert (issorted (sm, "rows"))
20809
9e9892519a7c Add more BIST tests for issorted.
Rik <rik@octave.org>
parents: 20806
diff changeset
7475 %!assert (! issorted (um, "rows"))
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7476 %!assert (issorted (sv))
20809
9e9892519a7c Add more BIST tests for issorted.
Rik <rik@octave.org>
parents: 20806
diff changeset
7477 %!assert (! issorted (uv))
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7478 %!assert (issorted (sv'))
20809
9e9892519a7c Add more BIST tests for issorted.
Rik <rik@octave.org>
parents: 20806
diff changeset
7479 %!assert (! issorted (uv'))
25484
b7db401e1a99 Use "ascend"/"descend" for issorted direction (bug #54147).
Rik <rik@octave.org>
parents: 25473
diff changeset
7480 %!assert (issorted (sm, "rows", "ascend"))
b7db401e1a99 Use "ascend"/"descend" for issorted direction (bug #54147).
Rik <rik@octave.org>
parents: 25473
diff changeset
7481 %!assert (! issorted (um, "rows", "ascend"))
b7db401e1a99 Use "ascend"/"descend" for issorted direction (bug #54147).
Rik <rik@octave.org>
parents: 25473
diff changeset
7482 %!assert (issorted (sv, "ascend"))
b7db401e1a99 Use "ascend"/"descend" for issorted direction (bug #54147).
Rik <rik@octave.org>
parents: 25473
diff changeset
7483 %!assert (! issorted (uv, "ascend"))
b7db401e1a99 Use "ascend"/"descend" for issorted direction (bug #54147).
Rik <rik@octave.org>
parents: 25473
diff changeset
7484 %!assert (issorted (sv', "ascend"))
b7db401e1a99 Use "ascend"/"descend" for issorted direction (bug #54147).
Rik <rik@octave.org>
parents: 25473
diff changeset
7485 %!assert (! issorted (uv', "ascend"))
b7db401e1a99 Use "ascend"/"descend" for issorted direction (bug #54147).
Rik <rik@octave.org>
parents: 25473
diff changeset
7486 %!assert (! issorted (sm, "rows", "descend"))
b7db401e1a99 Use "ascend"/"descend" for issorted direction (bug #54147).
Rik <rik@octave.org>
parents: 25473
diff changeset
7487 %!assert (issorted (flipud (sm), "rows", "descend"))
b7db401e1a99 Use "ascend"/"descend" for issorted direction (bug #54147).
Rik <rik@octave.org>
parents: 25473
diff changeset
7488 %!assert (! issorted (sv, "descend"))
b7db401e1a99 Use "ascend"/"descend" for issorted direction (bug #54147).
Rik <rik@octave.org>
parents: 25473
diff changeset
7489 %!assert (issorted (fliplr (sv), "descend"))
b7db401e1a99 Use "ascend"/"descend" for issorted direction (bug #54147).
Rik <rik@octave.org>
parents: 25473
diff changeset
7490 %!assert (! issorted (sv', "descend"))
b7db401e1a99 Use "ascend"/"descend" for issorted direction (bug #54147).
Rik <rik@octave.org>
parents: 25473
diff changeset
7491 %!assert (issorted (fliplr (sv)', "descend"))
20809
9e9892519a7c Add more BIST tests for issorted.
Rik <rik@octave.org>
parents: 20806
diff changeset
7492 %!assert (! issorted (um, "rows", "either"))
9e9892519a7c Add more BIST tests for issorted.
Rik <rik@octave.org>
parents: 20806
diff changeset
7493 %!assert (! issorted (uv, "either"))
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7494 %!assert (issorted (sm, "rows", "either"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7495 %!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
7496 %!assert (issorted (sv, "either"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7497 %!assert (issorted (fliplr (sv), "either"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7498 %!assert (issorted (sv', "either"))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
7499 %!assert (issorted (fliplr (sv)', "either"))
20809
9e9892519a7c Add more BIST tests for issorted.
Rik <rik@octave.org>
parents: 20806
diff changeset
7500
25850
153495e05477 issorted: return true on an empty array (bug #54599)
Mike Miller <mtmiller@octave.org>
parents: 25646
diff changeset
7501 %!assert (issorted ([]))
153495e05477 issorted: return true on an empty array (bug #54599)
Mike Miller <mtmiller@octave.org>
parents: 25646
diff changeset
7502 %!assert (issorted ([], "rows"))
153495e05477 issorted: return true on an empty array (bug #54599)
Mike Miller <mtmiller@octave.org>
parents: 25646
diff changeset
7503 %!assert (issorted ([], "ascend"))
153495e05477 issorted: return true on an empty array (bug #54599)
Mike Miller <mtmiller@octave.org>
parents: 25646
diff changeset
7504 %!assert (issorted ([], "rows", "ascend"))
153495e05477 issorted: return true on an empty array (bug #54599)
Mike Miller <mtmiller@octave.org>
parents: 25646
diff changeset
7505 %!assert (issorted ([], "descend"))
153495e05477 issorted: return true on an empty array (bug #54599)
Mike Miller <mtmiller@octave.org>
parents: 25646
diff changeset
7506 %!assert (issorted ([], "rows", "descend"))
153495e05477 issorted: return true on an empty array (bug #54599)
Mike Miller <mtmiller@octave.org>
parents: 25646
diff changeset
7507 %!assert (issorted ({}))
153495e05477 issorted: return true on an empty array (bug #54599)
Mike Miller <mtmiller@octave.org>
parents: 25646
diff changeset
7508 %!assert (issorted ({}, "rows"))
153495e05477 issorted: return true on an empty array (bug #54599)
Mike Miller <mtmiller@octave.org>
parents: 25646
diff changeset
7509 %!assert (issorted ({}, "ascend"))
153495e05477 issorted: return true on an empty array (bug #54599)
Mike Miller <mtmiller@octave.org>
parents: 25646
diff changeset
7510 %!assert (issorted ({}, "rows", "ascend"))
153495e05477 issorted: return true on an empty array (bug #54599)
Mike Miller <mtmiller@octave.org>
parents: 25646
diff changeset
7511 %!assert (issorted ({}, "descend"))
153495e05477 issorted: return true on an empty array (bug #54599)
Mike Miller <mtmiller@octave.org>
parents: 25646
diff changeset
7512 %!assert (issorted ({}, "rows", "descend"))
153495e05477 issorted: return true on an empty array (bug #54599)
Mike Miller <mtmiller@octave.org>
parents: 25646
diff changeset
7513 %!assert (issorted (""))
153495e05477 issorted: return true on an empty array (bug #54599)
Mike Miller <mtmiller@octave.org>
parents: 25646
diff changeset
7514 %!assert (issorted ("", "rows"))
153495e05477 issorted: return true on an empty array (bug #54599)
Mike Miller <mtmiller@octave.org>
parents: 25646
diff changeset
7515 %!assert (issorted ("", "ascend"))
153495e05477 issorted: return true on an empty array (bug #54599)
Mike Miller <mtmiller@octave.org>
parents: 25646
diff changeset
7516 %!assert (issorted ("", "rows", "ascend"))
153495e05477 issorted: return true on an empty array (bug #54599)
Mike Miller <mtmiller@octave.org>
parents: 25646
diff changeset
7517 %!assert (issorted ("", "descend"))
153495e05477 issorted: return true on an empty array (bug #54599)
Mike Miller <mtmiller@octave.org>
parents: 25646
diff changeset
7518 %!assert (issorted ("", "rows", "descend"))
20809
9e9892519a7c Add more BIST tests for issorted.
Rik <rik@octave.org>
parents: 20806
diff changeset
7519
9e9892519a7c Add more BIST tests for issorted.
Rik <rik@octave.org>
parents: 20806
diff changeset
7520 ## 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
7521 %!error issorted ()
f1b2a2dbc0e1 2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents: 20853
diff changeset
7522 %!error issorted (1,2,3,4)
20809
9e9892519a7c Add more BIST tests for issorted.
Rik <rik@octave.org>
parents: 20806
diff changeset
7523 %!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
7524 %!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
7525 %!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
7526 %!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
7527 %!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
7528 */
7fc1c8c47b86 issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
7529
9725
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7530 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
7531 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
7532 @deftypefn {} {@var{nel} =} nth_element (@var{x}, @var{n})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
7533 @deftypefnx {} {@var{nel} =} nth_element (@var{x}, @var{n}, @var{dim})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7534 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
7535 @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
7536
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7537 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
7538
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7539 @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
7540 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
7541
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7542 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
7543 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
7544 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
7545
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
7546 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
7547 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
7548 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
7549 @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
7550 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
7551 @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
7552 @end deftypefn */)
9725
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7553 {
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7554 int nargin = args.length ();
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7555
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7556 if (nargin < 2 || nargin > 3)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7557 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7558
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7559 int dim = -1;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7560 if (nargin == 3)
9725
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7561 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7562 dim = args(2).int_value (true) - 1;
9725
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7563 if (dim < 0)
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7564 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
7565 }
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7566
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7567 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
7568 if (dim < 0)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7569 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
7570
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7571 octave_value retval;
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7572
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7573 try
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7574 {
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
7575 idx_vector n = args(1).index_vector ();
9725
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7576
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7577 switch (argx.builtin_type ())
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7578 {
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7579 case btyp_double:
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7580 retval = argx.array_value ().nth_element (n, dim);
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7581 break;
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7582 case btyp_float:
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7583 retval = argx.float_array_value ().nth_element (n, dim);
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7584 break;
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7585 case btyp_complex:
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7586 retval = argx.complex_array_value ().nth_element (n, dim);
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7587 break;
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7588 case btyp_float_complex:
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7589 retval = argx.float_complex_array_value ().nth_element (n, dim);
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7590 break;
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
7591
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
7592 #define MAKE_INT_BRANCH(X) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
7593 case btyp_ ## X: \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
7594 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
7595 break;
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7596
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7597 MAKE_INT_BRANCH (int8);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7598 MAKE_INT_BRANCH (int16);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7599 MAKE_INT_BRANCH (int32);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7600 MAKE_INT_BRANCH (int64);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7601 MAKE_INT_BRANCH (uint8);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7602 MAKE_INT_BRANCH (uint16);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7603 MAKE_INT_BRANCH (uint32);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7604 MAKE_INT_BRANCH (uint64);
21540
ffb4770ba079 Make median preserve discrete types (bug #47515).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21458
diff changeset
7605 MAKE_INT_BRANCH (bool);
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
7606
9725
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7607 #undef MAKE_INT_BRANCH
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
7608
9725
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7609 default:
23575
e95738a119da maint: Deprecate is_cellstr and replace with iscellstr.
Rik <rik@octave.org>
parents: 23573
diff changeset
7610 if (argx.iscellstr ())
9725
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7611 retval = argx.cellstr_value ().nth_element (n, dim);
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7612 else
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21078
diff changeset
7613 err_wrong_type_arg ("nth_element", argx);
9725
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7614 }
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
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 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
7617 {
8f67ad8b3103 maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents: 29117
diff changeset
7618 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
7619 }
9725
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7620
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7621 return retval;
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7622 }
aea3a3a950e1 implement nth_element
Jaroslav Hajek <highegg@gmail.com>
parents: 9723
diff changeset
7623
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
7624 /*
3e93a2a66cdf nth_element: allow sequence of indices to be passed as a vector (bug #51329)
Brad Kennedy <bk@co60.ca>
parents: 23693
diff changeset
7625 %!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
7626 %!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
7627 %!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
7628 %!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
7629
3e93a2a66cdf nth_element: allow sequence of indices to be passed as a vector (bug #51329)
Brad Kennedy <bk@co60.ca>
parents: 23693
diff changeset
7630 %!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
7631
3e93a2a66cdf nth_element: allow sequence of indices to be passed as a vector (bug #51329)
Brad Kennedy <bk@co60.ca>
parents: 23693
diff changeset
7632 %!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
7633 %!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
7634 %!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
7635 %!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
7636 %!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
7637 */
3e93a2a66cdf nth_element: allow sequence of indices to be passed as a vector (bug #51329)
Brad Kennedy <bk@co60.ca>
parents: 23693
diff changeset
7638
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
7639 template <typename NDT>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
7640 static NDT
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
7641 do_accumarray_sum (const idx_vector& idx, const NDT& vals,
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7642 octave_idx_type n = -1)
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7643 {
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7644 typedef typename NDT::element_type T;
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7645 if (n < 0)
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7646 n = idx.extent (0);
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7647 else if (idx.extent (n) > n)
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7648 error ("accumarray: index out of range");
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7649
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
7650 NDT retval (dim_vector (n, 1), T ());
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7651
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7652 if (vals.numel () == 1)
9858
47c5af1868df move idx_add methods to MArrayN
Jaroslav Hajek <highegg@gmail.com>
parents: 9856
diff changeset
7653 retval.idx_add (idx, vals (0));
47c5af1868df move idx_add methods to MArrayN
Jaroslav Hajek <highegg@gmail.com>
parents: 9856
diff changeset
7654 else if (vals.numel () == idx.length (n))
47c5af1868df move idx_add methods to MArrayN
Jaroslav Hajek <highegg@gmail.com>
parents: 9856
diff changeset
7655 retval.idx_add (idx, vals);
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7656 else
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7657 error ("accumarray: dimensions mismatch");
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7658
9858
47c5af1868df move idx_add methods to MArrayN
Jaroslav Hajek <highegg@gmail.com>
parents: 9856
diff changeset
7659 return retval;
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7660 }
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7661
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7662 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
7663 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
7664 @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
7665 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
7666 @end deftypefn */)
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7667 {
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7668 int nargin = args.length ();
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7669
22789
bedfedcd878e norm: fix error in input argument validation leading to segfault (bug #49634)
Mike Miller <mtmiller@octave.org>
parents: 22749
diff changeset
7670 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
7671 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7672
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23585
diff changeset
7673 if (! args(0).isnumeric ())
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7674 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
7675
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7676 octave_value retval;
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7677
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7678 try
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7679 {
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
7680 idx_vector idx = args(0).index_vector ();
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7681 octave_idx_type n = -1;
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7682 if (nargin == 3)
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7683 n = args(2).idx_type_value (true);
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7684
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7685 octave_value vals = args(1);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7686
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7687 if (vals.is_range ())
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7688 {
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
7689 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
7690 if (r.increment () == 0)
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7691 vals = r.base ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7692 }
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7693
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7694 if (vals.is_single_type ())
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7695 {
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
7696 if (vals.iscomplex ())
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7697 retval = do_accumarray_sum (idx,
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7698 vals.float_complex_array_value (),
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7699 n);
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7700 else
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7701 retval = do_accumarray_sum (idx, vals.float_array_value (), n);
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7702 }
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23585
diff changeset
7703 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
7704 {
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
7705 if (vals.iscomplex ())
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7706 retval = do_accumarray_sum (idx,
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7707 vals.complex_array_value (),
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7708 n);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7709 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7710 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
7711 }
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7712 else
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21078
diff changeset
7713 err_wrong_type_arg ("accumarray", vals);
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7714 }
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
7715 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
7716 {
8f67ad8b3103 maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents: 29117
diff changeset
7717 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
7718 }
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7719
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
7720 return retval;
8934
c2099a4d12ea partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
7721 }
8721
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
7722
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
7723 template <typename NDT>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
7724 static NDT
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
7725 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
7726 octave_idx_type n, bool ismin,
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7727 const typename NDT::element_type& zero_val)
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7728 {
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7729 typedef typename NDT::element_type T;
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7730 if (n < 0)
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7731 n = idx.extent (0);
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7732 else if (idx.extent (n) > n)
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7733 error ("accumarray: index out of range");
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7734
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7735 NDT retval (dim_vector (n, 1), zero_val);
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7736
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7737 // 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
7738 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
7739 = ismin ? (&MArray<T>::idx_min) : (&MArray<T>::idx_max);
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7740
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7741 octave_idx_type l = idx.length (n);
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7742 if (vals.numel () == 1)
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7743 (retval.*op) (idx, NDT (dim_vector (l, 1), vals(0)));
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7744 else if (vals.numel () == l)
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7745 (retval.*op) (idx, vals);
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7746 else
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7747 error ("accumarray: dimensions mismatch");
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7748
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7749 return retval;
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7750 }
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 static octave_value_list
30896
c9788d7f6e65 maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents: 30892
diff changeset
7753 do_accumarray_minmax_fcn (const octave_value_list& args,
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7754 bool ismin)
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7755 {
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7756 int nargin = args.length ();
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7757
22789
bedfedcd878e norm: fix error in input argument validation leading to segfault (bug #49634)
Mike Miller <mtmiller@octave.org>
parents: 22749
diff changeset
7758 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
7759 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7760
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23585
diff changeset
7761 if (! args(0).isnumeric ())
20811
5979314bb15a Fix BIST tests for rows.
Rik <rik@octave.org>
parents: 20810
diff changeset
7762 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
7763
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7764 octave_value retval;
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7765
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7766 try
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7767 {
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
7768 idx_vector idx = args(0).index_vector ();
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7769 octave_idx_type n = -1;
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7770 if (nargin == 4)
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7771 n = args(3).idx_type_value (true);
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7772
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7773 octave_value vals = args(1);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7774 octave_value zero = args(2);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7775
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7776 switch (vals.builtin_type ())
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7777 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7778 case btyp_double:
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7779 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
7780 zero.double_value ());
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7781 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7782
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7783 case btyp_float:
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7784 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
7785 ismin, zero.float_value ());
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7786 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7787
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7788 case btyp_complex:
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7789 retval = do_accumarray_minmax (idx, vals.complex_array_value (),
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7790 n, ismin, zero.complex_value ());
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7791 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7792
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7793 case btyp_float_complex:
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7794 retval = do_accumarray_minmax (idx,
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7795 vals.float_complex_array_value (),
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7796 n, ismin,
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7797 zero.float_complex_value ());
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7798 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7799
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
7800 #define MAKE_INT_BRANCH(X) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
7801 case btyp_ ## X: \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
7802 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
7803 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
7804 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7805
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7806 MAKE_INT_BRANCH (int8);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7807 MAKE_INT_BRANCH (int16);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7808 MAKE_INT_BRANCH (int32);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7809 MAKE_INT_BRANCH (int64);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7810 MAKE_INT_BRANCH (uint8);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7811 MAKE_INT_BRANCH (uint16);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7812 MAKE_INT_BRANCH (uint32);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7813 MAKE_INT_BRANCH (uint64);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7814
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7815 #undef MAKE_INT_BRANCH
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7816
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7817 case btyp_bool:
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7818 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
7819 zero.bool_value ());
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7820 break;
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7821
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7822 default:
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21078
diff changeset
7823 err_wrong_type_arg ("accumarray", vals);
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7824 }
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7825 }
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
7826 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
7827 {
30896
c9788d7f6e65 maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents: 30892
diff changeset
7828 error ("do_accumarray_minmax_fcn: invalid index %s", ie.what ());
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7829 }
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7830
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
7831 return retval;
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7832 }
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7833
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7834 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
7835 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
7836 @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
7837 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
7838 @end deftypefn */)
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7839 {
30896
c9788d7f6e65 maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents: 30892
diff changeset
7840 return do_accumarray_minmax_fcn (args, true);
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7841 }
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7842
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7843 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
7844 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
7845 @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
7846 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
7847 @end deftypefn */)
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7848 {
30896
c9788d7f6e65 maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents: 30892
diff changeset
7849 return do_accumarray_minmax_fcn (args, false);
10268
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7850 }
9a16a61ed43d new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents: 10240
diff changeset
7851
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
7852 template <typename NDT>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
7853 static NDT
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
7854 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
7855 int dim = -1, octave_idx_type n = -1)
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7856 {
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7857 typedef typename NDT::element_type T;
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7858 if (n < 0)
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7859 n = idx.extent (0);
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7860 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
7861 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
7862
18100
6a71e5030df5 Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents: 17915
diff changeset
7863 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
7864 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
7865
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7866 if (dim < 0)
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7867 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
7868 else if (dim >= rdv.ndims ())
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7869 rdv.resize (dim+1, 1);
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7870
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7871 rdv(dim) = n;
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7872
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
7873 NDT retval (rdv, T ());
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7874
14113
dac62c415e8b Do more error checking on accumarray and accumdim input.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14100
diff changeset
7875 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
7876 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
7877
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7878 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
7879
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7880 return retval;
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7881 }
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7882
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7883 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
7884 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
7885 @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
7886 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
7887 @end deftypefn */)
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7888 {
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7889 int nargin = args.length ();
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7890
22789
bedfedcd878e norm: fix error in input argument validation leading to segfault (bug #49634)
Mike Miller <mtmiller@octave.org>
parents: 22749
diff changeset
7891 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
7892 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7893
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23585
diff changeset
7894 if (! args(0).isnumeric ())
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7895 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
7896
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7897 octave_value retval;
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
7898
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7899 try
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7900 {
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
7901 idx_vector idx = args(0).index_vector ();
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7902 int dim = -1;
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7903 if (nargin >= 3)
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7904 dim = args(2).int_value () - 1;
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7905
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7906 octave_idx_type n = -1;
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7907 if (nargin == 4)
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7908 n = args(3).idx_type_value (true);
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7909
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7910 octave_value vals = args(1);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7911
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7912 if (vals.is_single_type ())
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7913 {
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
7914 if (vals.iscomplex ())
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7915 retval = do_accumdim_sum (idx,
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7916 vals.float_complex_array_value (),
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7917 dim, n);
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7918 else
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7919 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
7920 dim, n);
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7921 }
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23585
diff changeset
7922 else if (vals.isnumeric () || vals.islogical ())
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7923 {
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
7924 if (vals.iscomplex ())
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7925 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
7926 dim, n);
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7927 else
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7928 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
7929 }
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
7930 else
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21078
diff changeset
7931 err_wrong_type_arg ("accumdim", vals);
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7932 }
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
7933 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
7934 {
8f67ad8b3103 maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents: 29117
diff changeset
7935 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
7936 }
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7937
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
7938 return retval;
10396
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7939 }
a0b51ac0f88a optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents: 10352
diff changeset
7940
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
7941 template <typename NDT>
9473
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7942 static NDT
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7943 do_merge (const Array<bool>& mask,
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7944 const NDT& tval, const NDT& fval)
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7945 {
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7946 typedef typename NDT::element_type T;
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7947 dim_vector dv = mask.dims ();
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7948 NDT retval (dv);
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7949
18100
6a71e5030df5 Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents: 17915
diff changeset
7950 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
7951 bool fscl = fval.numel () == 1;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
7952
21055
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7953 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
7954 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
7955
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7956 T *rv = retval.fortran_vec ();
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7957 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
7958
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7959 const T *tv = tval.data ();
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7960 const T *fv = fval.data ();
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7961 const bool *mv = mask.data ();
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7962
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7963 if (tscl)
9473
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7964 {
21055
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7965 if (fscl)
9473
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7966 {
21055
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7967 T ts = tv[0];
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7968 T fs = fv[0];
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7969 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
7970 rv[i] = (mv[i] ? ts : fs);
9473
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7971 }
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7972 else
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7973 {
21055
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7974 T ts = tv[0];
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7975 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
7976 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
7977 }
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7978 }
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7979 else
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7980 {
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7981 if (fscl)
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7982 {
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7983 T fs = fv[0];
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7984 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
7985 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
7986 }
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7987 else
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7988 {
5e00ed38a58b maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents: 21053
diff changeset
7989 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
7990 rv[i] = (mv[i] ? tv[i] : fv[i]);
9473
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7991 }
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7992 }
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7993
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7994 return retval;
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7995 }
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7996
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
7997 #define MAKE_INT_BRANCH(INTX) \
9473
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
7998 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
7999 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
8000 retval = do_merge (mask, \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
8001 tval.INTX ## _array_value (), \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
8002 fval.INTX ## _array_value ()); \
9473
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
8003 }
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
8004
9505
a321a1c227c8 make ifelse an alias or merge
Jaroslav Hajek <highegg@gmail.com>
parents: 9475
diff changeset
8005 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
8006 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
8007 @deftypefn {} {@var{M} =} merge (@var{mask}, @var{tval}, @var{fval})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
8008 @deftypefnx {} {@var{M} =} ifelse (@var{mask}, @var{tval}, @var{fval})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
8009 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
8010 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
8011
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
8012 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
8013 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
8014 @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
8015 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
8016 @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
8017
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
8018 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
8019 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
8020 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
8021
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
8022 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
8023 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
8024 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
8025 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
8026 @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
8027 @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
8028
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
8029 @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
8030 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
8031 @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
8032 @end deftypefn */)
9473
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
8033 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8034 if (args.length () != 3)
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8035 print_usage ();
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8036
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23585
diff changeset
8037 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
8038 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
8039
9473
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
8040 octave_value retval;
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
8041
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8042 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
8043
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8044 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
8045 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
8046 else
9473
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
8047 {
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8048 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
8049
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8050 octave_value tval = args(1);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8051 octave_value fval = args(2);
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8052
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8053 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
8054 {
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
8055 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
8056 retval = do_merge (mask,
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8057 tval.complex_array_value (),
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8058 fval.complex_array_value ());
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8059 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8060 retval = do_merge (mask,
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8061 tval.array_value (),
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8062 fval.array_value ());
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8063 }
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8064 else if (tval.is_single_type () && fval.is_single_type ())
9473
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
8065 {
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
8066 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
8067 retval = do_merge (mask,
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8068 tval.float_complex_array_value (),
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8069 fval.float_complex_array_value ());
9473
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
8070 else
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8071 retval = do_merge (mask,
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8072 tval.float_array_value (),
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8073 fval.float_array_value ());
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8074 }
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8075 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
8076 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8077 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
8078 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
8079 tval.char_array_value (),
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8080 fval.char_array_value ()),
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8081 sq_string ? '\'' : '"');
9473
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
8082 }
23576
00e518162fda maint: Deprecate is_cell and replace with iscell.
Rik <rik@octave.org>
parents: 23575
diff changeset
8083 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
8084 {
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8085 retval = do_merge (mask,
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8086 tval.cell_value (),
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8087 fval.cell_value ());
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8088 }
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8089
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
8090 MAKE_INT_BRANCH (int8)
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
8091 MAKE_INT_BRANCH (int16)
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
8092 MAKE_INT_BRANCH (int32)
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
8093 MAKE_INT_BRANCH (int64)
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
8094 MAKE_INT_BRANCH (uint8)
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
8095 MAKE_INT_BRANCH (uint16)
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
8096 MAKE_INT_BRANCH (uint32)
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
8097 MAKE_INT_BRANCH (uint64)
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8098
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8099 else
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8100 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
8101 tval.class_name ().c_str (),
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8102 fval.class_name ().c_str ());
9473
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
8103 }
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
8104
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
8105 return retval;
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
8106 }
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
8107
9505
a321a1c227c8 make ifelse an alias or merge
Jaroslav Hajek <highegg@gmail.com>
parents: 9475
diff changeset
8108 DEFALIAS (ifelse, merge);
a321a1c227c8 make ifelse an alias or merge
Jaroslav Hajek <highegg@gmail.com>
parents: 9475
diff changeset
8109
9473
833109a9f37f implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents: 9428
diff changeset
8110 #undef MAKE_INT_BRANCH
8721
e9cb742df9eb imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents: 8527
diff changeset
8111
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
8112 template <typename SparseT>
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8113 static SparseT
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8114 do_sparse_diff (const SparseT& array, octave_idx_type order,
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8115 int dim)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8116 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8117 SparseT retval = array;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8118 if (dim == 1)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8119 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8120 octave_idx_type k = retval.columns ();
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8121 while (order > 0 && k > 0)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8122 {
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
8123 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
8124 retval = SparseT (retval.index (col1, sl1))
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
8125 - SparseT (retval.index (col2, sl2));
30723
08b08b7f05b2 Replace direct calls to C library assert() with Octave specialty functions in libinterp/ (bug #61753)
Arun Giridhar <arungiridhar@gmail.com> and Rik <rik@octave.org>
parents: 30673
diff changeset
8126 error_unless (retval.columns () == k-1);
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8127 order--;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8128 k--;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8129 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8130 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8131 else
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8132 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8133 octave_idx_type k = retval.rows ();
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8134 while (order > 0 && k > 0)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8135 {
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
8136 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
8137 retval = SparseT (retval.index (sl1, col1))
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
8138 - SparseT (retval.index (sl2, col2));
30723
08b08b7f05b2 Replace direct calls to C library assert() with Octave specialty functions in libinterp/ (bug #61753)
Arun Giridhar <arungiridhar@gmail.com> and Rik <rik@octave.org>
parents: 30673
diff changeset
8139 error_unless (retval.rows () == k-1);
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8140 order--;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8141 k--;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8142 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8143 }
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 return retval;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8146 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8147
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8148 static octave_value
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8149 do_diff (const octave_value& array, octave_idx_type order,
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8150 int dim = -1)
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 octave_value retval;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8153
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8154 const dim_vector& dv = array.dims ();
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8155 if (dim == -1)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8156 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8157 dim = array.dims ().first_non_singleton ();
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8158
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21730
diff changeset
8159 // Bother Matlab. This behavior is really wicked.
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8160 if (dv(dim) <= order)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8161 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8162 if (dv(dim) == 1)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8163 retval = array.resize (dim_vector (0, 0));
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8164 else
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8165 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8166 retval = array;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8167 while (order > 0)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8168 {
21660
53728df3e4c9 maint: for clarity, call ndims() rather than length() on dimension vectors.
Rik <rik@octave.org>
parents: 21602
diff changeset
8169 if (dim == dv.ndims ())
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8170 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8171 retval = do_diff (array, order, dim - 1);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8172 order = 0;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8173 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8174 else if (dv(dim) == 1)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8175 dim++;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8176 else
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8177 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8178 retval = do_diff (array, dv(dim) - 1, dim);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8179 order -= dv(dim) - 1;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8180 dim++;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8181 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8182 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8183 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8184
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8185 return retval;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8186 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8187 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8188
23580
2230f9e10fb3 maint: Deprecate is_integer_type and replace with isinteger.
Rik <rik@octave.org>
parents: 23579
diff changeset
8189 if (array.isinteger ())
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8190 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8191 if (array.is_int8_type ())
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8192 retval = array.int8_array_value ().diff (order, dim);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8193 else if (array.is_int16_type ())
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8194 retval = array.int16_array_value ().diff (order, dim);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8195 else if (array.is_int32_type ())
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8196 retval = array.int32_array_value ().diff (order, dim);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8197 else if (array.is_int64_type ())
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8198 retval = array.int64_array_value ().diff (order, dim);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8199 else if (array.is_uint8_type ())
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8200 retval = array.uint8_array_value ().diff (order, dim);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8201 else if (array.is_uint16_type ())
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8202 retval = array.uint16_array_value ().diff (order, dim);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8203 else if (array.is_uint32_type ())
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8204 retval = array.uint32_array_value ().diff (order, dim);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8205 else if (array.is_uint64_type ())
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8206 retval = array.uint64_array_value ().diff (order, dim);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8207 else
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8208 panic_impossible ();
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8209 }
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
8210 else if (array.issparse ())
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8211 {
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
8212 if (array.iscomplex ())
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
8213 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
8214 order, dim);
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8215 else
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8216 retval = do_sparse_diff (array.sparse_matrix_value (), order, dim);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8217 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8218 else if (array.is_single_type ())
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8219 {
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
8220 if (array.iscomplex ())
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8221 retval = array.float_complex_array_value ().diff (order, dim);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8222 else
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8223 retval = array.float_array_value ().diff (order, dim);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8224 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8225 else
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8226 {
23581
c3075ae020e1 maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents: 23580
diff changeset
8227 if (array.iscomplex ())
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8228 retval = array.complex_array_value ().diff (order, dim);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8229 else
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8230 retval = array.array_value ().diff (order, dim);
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8231 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8232
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8233 return retval;
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8234 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8235
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8236 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
8237 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
8238 @deftypefn {} {@var{y} =} diff (@var{x})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
8239 @deftypefnx {} {@var{y} =} diff (@var{x}, @var{k})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
8240 @deftypefnx {} {@var{y} =} diff (@var{x}, @var{k}, @var{dim})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
8241 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
8242 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
8243 @tex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
8244 $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
8245 @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
8246 @ifnottex
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
8247 @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
8248 @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
8249
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
8250 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
8251 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
8252
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
8253 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
8254 @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
8255 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
8256 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
8257 @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
8258 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
8259
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
8260 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
8261 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
8262 @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
8263 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
8264 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
8265 @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
8266 @end deftypefn */)
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8267 {
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8268 int nargin = args.length ();
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8269
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8270 if (nargin < 1 || nargin > 3)
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8271 print_usage ();
20806
20975a6f677a eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20785
diff changeset
8272
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23585
diff changeset
8273 if (! (args(0).isnumeric () || args(0).islogical ()))
10880
92c3e8068f28 allow diff(logical)
Jaroslav Hajek <highegg@gmail.com>
parents: 10846
diff changeset
8274 error ("diff: X must be numeric or logical");
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8275
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
8276 int dim = -1;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
8277 octave_idx_type order = 1;
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
8278 if (nargin > 1)
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8279 {
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
8280 if (args(1).is_scalar_type ())
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
8281 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
8282 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
8283 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
8284 if (order < 0)
20726
25d676f9619c Preface error() messages with name of function when possible.
Rik <rik@octave.org>
parents: 20720
diff changeset
8285 error ("diff: order K must be non-negative");
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8286 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8287
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
8288 if (nargin > 2)
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
8289 {
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
8290 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
8291 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
8292 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
8293
81c2b14c209f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
8294 dim -= 1;
20562
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
8295 }
a05a0432dff4 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20542
diff changeset
8296
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8297 return do_diff (args(0), order, dim);
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8298 }
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8299
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8300 /*
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8301 %!assert (diff ([1, 2, 3, 4]), [1, 1, 1])
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8302 %!assert (diff ([1, 3, 7, 19], 2), [2, 8])
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8303 %!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
8304 %!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
8305 %!assert (isempty (diff (1)))
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
8306
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
8307 %!error diff ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
8308 %!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
8309 %!error diff ("foo")
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14361
diff changeset
8310 %!error diff ([1, 2; 3, 4], -1)
9513
9f870f73ab7d implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents: 9505
diff changeset
8311 */
10799
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8312
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21129
diff changeset
8313 template <typename T>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11575
diff changeset
8314 static Array<T>
10799
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8315 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
8316 {
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8317 Array<T> retval;
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8318
30723
08b08b7f05b2 Replace direct calls to C library assert() with Octave specialty functions in libinterp/ (bug #61753)
Arun Giridhar <arungiridhar@gmail.com> and Rik <rik@octave.org>
parents: 30673
diff changeset
8319 if (rep.ndims () != 2 || rep.rows () != 2)
08b08b7f05b2 Replace direct calls to C library assert() with Octave specialty functions in libinterp/ (bug #61753)
Arun Giridhar <arungiridhar@gmail.com> and Rik <rik@octave.org>
parents: 30673
diff changeset
8320 error ("repelems: R must be a 2-row, N-column matrix of integers");
10799
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8321
18100
6a71e5030df5 Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents: 17915
diff changeset
8322 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
8323 octave_idx_type l = 0;
10799
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8324 for (octave_idx_type i = 0; i < n; i++)
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8325 {
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8326 octave_idx_type k = rep(1, i);
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8327 if (k < 0)
20893
384ff5aa9437 2015 Code Sprint: Eliminate useless return statements after error ().
Rik <rik@octave.org>
parents: 20884
diff changeset
8328 error ("repelems: second row must contain non-negative numbers");
10799
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8329
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8330 l += k;
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8331 }
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8332
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8333 retval.clear (1, l);
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8334 T *dest = retval.fortran_vec ();
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8335 l = 0;
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8336 for (octave_idx_type i = 0; i < n; i++)
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8337 {
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8338 octave_idx_type k = rep(1, i);
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8339 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
8340 dest += k;
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8341 }
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8342
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8343 return retval;
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8344 }
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8345
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8346 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
8347 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30854
diff changeset
8348 @deftypefn {} {@var{y} =} repelems (@var{x}, @var{r})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
8349 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
8350
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
8351 @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
8352 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
8353 @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
8354 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
8355 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
8356 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
8357 returned.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
8358
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
8359 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
8360
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
8361 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
8362 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
8363 y = [];
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
8364 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
8365 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
8366 endfor
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
8367 @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
8368 @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
8369 @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
8370 @end deftypefn */)
10799
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8371 {
20850
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8372 if (args.length () != 2)
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8373 print_usage ();
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8374
10799
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8375 octave_value retval;
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8376
20850
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8377 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
8378
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8379 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
8380 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
8381
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8382 octave_value x = args(0);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8383
27666
3e8faed1b7d8 Remove wrapper template class NoAlias<T> (bug #56752)
Carlo de Falco <carlo.defalco@polimi.it>
parents: 27568
diff changeset
8384 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
8385
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8386 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
8387 {
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8388 octave_idx_type rx = rm(i);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8389 if (static_cast<double> (rx) != rm(i))
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8390 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
8391
27666
3e8faed1b7d8 Remove wrapper template class NoAlias<T> (bug #56752)
Carlo de Falco <carlo.defalco@polimi.it>
parents: 27568
diff changeset
8392 r.xelem (i) = rx;
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8393 }
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8394
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8395 switch (x.builtin_type ())
10799
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8396 {
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
8397 #define BTYP_BRANCH(X, EX) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
8398 case btyp_ ## X: \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
8399 retval = do_repelems (x.EX ## _value (), r); \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
8400 break;
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8401
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8402 BTYP_BRANCH (double, array);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8403 BTYP_BRANCH (float, float_array);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8404 BTYP_BRANCH (complex, complex_array);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8405 BTYP_BRANCH (float_complex, float_complex_array);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8406 BTYP_BRANCH (bool, bool_array);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8407 BTYP_BRANCH (char, char_array);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8408
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8409 BTYP_BRANCH (int8, int8_array);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8410 BTYP_BRANCH (int16, int16_array);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8411 BTYP_BRANCH (int32, int32_array);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8412 BTYP_BRANCH (int64, int64_array);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8413 BTYP_BRANCH (uint8, uint8_array);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8414 BTYP_BRANCH (uint16, uint16_array);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8415 BTYP_BRANCH (uint32, uint32_array);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8416 BTYP_BRANCH (uint64, uint64_array);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8417
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8418 BTYP_BRANCH (cell, cell);
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8419 //BTYP_BRANCH (struct, map);//FIXME
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
8420
10799
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8421 #undef BTYP_BRANCH
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8422
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8423 default:
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21078
diff changeset
8424 err_wrong_type_arg ("repelems", x);
10799
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8425 }
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8426
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8427 return retval;
177f1ad7c7c1 new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents: 10785
diff changeset
8428 }
15050
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
8429
15252
fa0118cb67d9 move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents: 15213
diff changeset
8430 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
8431 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
8432 @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
8433 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
8434 @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
8435
28769
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8436 @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
8437 @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
8438 {
20819
f428cbe7576f eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents: 20816
diff changeset
8439 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
8440 print_usage ();
20850
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8441
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23585
diff changeset
8442 if (! args(0).isnumeric ())
20850
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8443 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
8444
23583
b7747a2c88b2 maint: Deprecate is_sparse_type and replace with issparse.
Rik <rik@octave.org>
parents: 23582
diff changeset
8445 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
8446 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
8447
15050
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
8448 octave_value_list retval;
20918
6f0bd96f93c0 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
8449
23580
2230f9e10fb3 maint: Deprecate is_integer_type and replace with isinteger.
Rik <rik@octave.org>
parents: 23579
diff changeset
8450 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
8451 {
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
8452 #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
8453 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
8454 { \
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
8455 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
8456 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
8457 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
8458 char *out; \
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
8459 if (base64_encode (inc, inlen, &out)) \
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
8460 { \
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
8461 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
8462 ::free (out); \
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
8463 } \
15111
5dd599df36de generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15094
diff changeset
8464 }
20850
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8465
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8466 MAKE_INT_BRANCH(int8)
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8467 else MAKE_INT_BRANCH(int16)
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
8468 else MAKE_INT_BRANCH(int32)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
8469 else MAKE_INT_BRANCH(int64)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
8470 else MAKE_INT_BRANCH(uint8)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
8471 else MAKE_INT_BRANCH(uint16)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
8472 else MAKE_INT_BRANCH(uint32)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
8473 else MAKE_INT_BRANCH(uint64)
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22079
diff changeset
8474
20850
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8475 #undef MAKE_INT_BRANCH
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8476
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
8477 else
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
8478 panic_impossible ();
20850
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8479 }
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8480 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
8481 {
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8482 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
8483 std::size_t inlen;
20850
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8484 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
8485 const char *inc;
23447
db1fdf4384dd maint: Use convention "static_cast<void *>" for casting of pointers.
Rik <rik@octave.org>
parents: 23289
diff changeset
8486 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
8487 char *out;
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
8488 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
8489 {
20850
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8490 retval(0) = octave_value (out);
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8491 ::free (out);
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
8492 }
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
8493 }
20850
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8494 else // double_type
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8495 {
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8496 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
8497 std::size_t inlen;
20850
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8498 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
8499 const char *inc;
23447
db1fdf4384dd maint: Use convention "static_cast<void *>" for casting of pointers.
Rik <rik@octave.org>
parents: 23289
diff changeset
8500 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
8501 char *out;
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
8502 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
8503 {
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8504 retval(0) = octave_value (out);
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8505 ::free (out);
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8506 }
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8507 }
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8508
15052
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
8509 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
8510 }
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
8511
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
8512 /*
21458
348e335c49dd Fix failing BIST tests on big-endian systems
Mike Miller <mtmiller@octave.org>
parents: 21405
diff changeset
8513 %!test
348e335c49dd Fix failing BIST tests on big-endian systems
Mike Miller <mtmiller@octave.org>
parents: 21405
diff changeset
8514 %! ## FIXME: better test for endianness?
348e335c49dd Fix failing BIST tests on big-endian systems
Mike Miller <mtmiller@octave.org>
parents: 21405
diff changeset
8515 %! if (bitunpack (uint16 (1))(1) == 1)
348e335c49dd Fix failing BIST tests on big-endian systems
Mike Miller <mtmiller@octave.org>
parents: 21405
diff changeset
8516 %! expected = "2w9JQA==";
348e335c49dd Fix failing BIST tests on big-endian systems
Mike Miller <mtmiller@octave.org>
parents: 21405
diff changeset
8517 %! else
348e335c49dd Fix failing BIST tests on big-endian systems
Mike Miller <mtmiller@octave.org>
parents: 21405
diff changeset
8518 %! expected = "QEkP2w==";
348e335c49dd Fix failing BIST tests on big-endian systems
Mike Miller <mtmiller@octave.org>
parents: 21405
diff changeset
8519 %! endif
348e335c49dd Fix failing BIST tests on big-endian systems
Mike Miller <mtmiller@octave.org>
parents: 21405
diff changeset
8520 %! assert (base64_encode (single (pi)), expected);
348e335c49dd Fix failing BIST tests on big-endian systems
Mike Miller <mtmiller@octave.org>
parents: 21405
diff changeset
8521
15111
5dd599df36de generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15094
diff changeset
8522 %!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
8523 %!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
8524 %!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
8525 %!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
8526 %!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
8527
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
8528 %!error base64_encode ()
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
8529 %!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
8530 %!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
8531 %!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
8532 %!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
8533 */
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
8534
15252
fa0118cb67d9 move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents: 15213
diff changeset
8535 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
8536 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
8537 @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
8538 @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
8539 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
8540 @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
8541
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21947
diff changeset
8542 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
8543 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
8544 @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
8545 @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
8546 {
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
8547 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
8548
15050
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
8549 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
8550 print_usage ();
20850
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8551
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8552 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
8553
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
8554 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
8555
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8556 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
8557 {
15252
fa0118cb67d9 move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents: 15213
diff changeset
8558 dim_vector dims;
15052
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
8559
27277
db687716fed6 style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents: 27081
diff changeset
8560 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
8561 = 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
8562
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8563 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
8564 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
8565 dims(i) = size(i);
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8566
b36aa3044bca 2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents: 20819
diff changeset
8567 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
8568 }
15052
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
8569
21127
df7891224709 maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents: 21121
diff changeset
8570 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
8571 }
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
8572
abc858bc5165 Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents: 15038
diff changeset
8573 /*
15052
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
8574 %!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
8575 %!
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
8576 %!test
15052
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
8577 %! in = randn (10);
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
8578 %! 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
8579 %! 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
8580 %! assert (outv, in(:).');
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
8581 %! assert (outm, in);
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
8582
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
8583 %!error base64_decode ()
70a1b50bcb45 maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents: 15050
diff changeset
8584 %!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
8585 %!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
8586 %!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
8587 %!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
8588 %!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
8589 */
28769
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8590
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8591 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
8592 doc: /* -*- texinfo -*-
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8593 @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
8594 @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
8595 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
8596 @var{s}.
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8597
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8598 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
8599 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
8600 @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
8601 @end deftypefn */)
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8602 {
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8603 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
8604
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8605 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
8606 print_usage ();
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8607
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8608 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
8609
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29959
diff changeset
8610 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
8611
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8612 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
8613 {
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8614 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
8615
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8616 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
8617 = 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
8618
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8619 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
8620 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
8621 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
8622
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8623 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
8624 }
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8625
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8626 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
8627 }
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8628
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8629 /*
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8630 %!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
8631
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8632 %!test
903fe321649b Add Matlab compatible wrappers for base64_encode and base64_decode.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28715
diff changeset
8633 %! 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
8634 %! 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
8635 %! 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
8636 %! 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
8637 %! 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
8638
28888
06c8e0877864 maint: Backed out changeset 09c071328135.
Rik <rik@octave.org>
parents: 28887
diff changeset
8639 %!error __base64_decode_bytes__ ()
06c8e0877864 maint: Backed out changeset 09c071328135.
Rik <rik@octave.org>
parents: 28887
diff changeset
8640 %!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
8641 %!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
8642 %!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
8643 */
29958
32c3a5805893 move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29955
diff changeset
8644
31605
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 31603
diff changeset
8645 OCTAVE_END_NAMESPACE(octave)