Mercurial > jwe > octave
annotate libinterp/corefcn/data.cc @ 21127:df7891224709
maint: Use "return ovl (...)" in DEFUN macros.
* cellfun.cc, data.cc, debug.cc, defaults.cc, det.cc, dirfns.cc, dlmread.cc,
error.cc, file-io.cc, getrusage.cc, graphics.cc, help.cc, input.cc, inv.cc,
kron.cc, load-path.cc, pager.cc, pinv.cc, rand.cc, strfns.cc, urlwrite.cc,
chol.cc, ov-classdef.cc, ov-struct.cc: Use "return ovl (...)" in DEFUN macros,
rather than "return octave_value (...)".
author | Rik <rik@octave.org> |
---|---|
date | Thu, 21 Jan 2016 09:47:50 -0800 |
parents | f5b17eb2508b |
children | 228b65504557 |
rev | line source |
---|---|
523 | 1 /* |
2 | |
19697
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19597
diff
changeset
|
3 Copyright (C) 1994-2015 John W. Eaton |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
4 Copyright (C) 2009 Jaroslav Hajek |
11523 | 5 Copyright (C) 2009-2010 VZLU Prague |
15050
abc858bc5165
Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15038
diff
changeset
|
6 Copyright (C) 2012 Carlo de Falco |
523 | 7 |
8 This file is part of Octave. | |
9 | |
10 Octave is free software; you can redistribute it and/or modify it | |
11 under the terms of the GNU General Public License as published by the | |
7016 | 12 Free Software Foundation; either version 3 of the License, or (at your |
13 option) any later version. | |
523 | 14 |
15 Octave is distributed in the hope that it will be useful, but WITHOUT | |
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
18 for more details. | |
19 | |
20 You should have received a copy of the GNU General Public License | |
7016 | 21 along with Octave; see the file COPYING. If not, see |
22 <http://www.gnu.org/licenses/>. | |
523 | 23 |
24 */ | |
25 | |
26 #ifdef HAVE_CONFIG_H | |
1192 | 27 #include <config.h> |
523 | 28 #endif |
29 | |
7078 | 30 #include <sys/types.h> |
10302
5669a0b893db
data.cc: include <sys/times.h> and ensure that HZ is defined
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
31 #include <sys/times.h> |
7078 | 32 |
33 #ifdef HAVE_SYS_RESOURCE_H | |
34 #include <sys/resource.h> | |
35 #endif | |
36 | |
2184 | 37 #include <cfloat> |
10303
e4899d6320b6
data.cc: use CLOCKS_PER_SEC instead of HZ
John W. Eaton <jwe@octave.org>
parents:
10302
diff
changeset
|
38 #include <ctime> |
2184 | 39 |
1728 | 40 #include <string> |
41 | |
2184 | 42 #include "lo-ieee.h" |
7231 | 43 #include "lo-math.h" |
15252
fa0118cb67d9
move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents:
15213
diff
changeset
|
44 #include "oct-base64.h" |
10240
fa7b5751730c
use gnulib time, sys_time, and sys_times modules
John W. Eaton <jwe@octave.org>
parents:
10185
diff
changeset
|
45 #include "oct-time.h" |
1755 | 46 #include "str-vec.h" |
4153 | 47 #include "quit.h" |
9658
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
48 #include "mx-base.h" |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
49 #include "oct-binmap.h" |
1755 | 50 |
6953 | 51 #include "Cell.h" |
1352 | 52 #include "defun.h" |
53 #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
|
54 #include "errwarn.h" |
6953 | 55 #include "oct-map.h" |
20940
48b2ad5ee801
maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents:
20923
diff
changeset
|
56 #include "ovl.h" |
2366 | 57 #include "ov.h" |
13294
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
58 #include "ov-class.h" |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7743
diff
changeset
|
59 #include "ov-float.h" |
5476 | 60 #include "ov-complex.h" |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7743
diff
changeset
|
61 #include "ov-flt-complex.h" |
5476 | 62 #include "ov-cx-mat.h" |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7743
diff
changeset
|
63 #include "ov-flt-cx-mat.h" |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7743
diff
changeset
|
64 #include "ov-cx-sparse.h" |
6953 | 65 #include "parse.h" |
66 #include "pt-mat.h" | |
523 | 67 #include "utils.h" |
6953 | 68 #include "variables.h" |
7045 | 69 #include "pager.h" |
8303
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
70 #include "xnorm.h" |
523 | 71 |
10303
e4899d6320b6
data.cc: use CLOCKS_PER_SEC instead of HZ
John W. Eaton <jwe@octave.org>
parents:
10302
diff
changeset
|
72 #if ! defined (CLOCKS_PER_SEC) |
10302
5669a0b893db
data.cc: include <sys/times.h> and ensure that HZ is defined
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
73 #if defined (CLK_TCK) |
10303
e4899d6320b6
data.cc: use CLOCKS_PER_SEC instead of HZ
John W. Eaton <jwe@octave.org>
parents:
10302
diff
changeset
|
74 #define CLOCKS_PER_SEC CLK_TCK |
10302
5669a0b893db
data.cc: include <sys/times.h> and ensure that HZ is defined
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
75 #else |
10303
e4899d6320b6
data.cc: use CLOCKS_PER_SEC instead of HZ
John W. Eaton <jwe@octave.org>
parents:
10302
diff
changeset
|
76 #error "no definition for CLOCKS_PER_SEC!" |
10302
5669a0b893db
data.cc: include <sys/times.h> and ensure that HZ is defined
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
77 #endif |
5669a0b893db
data.cc: include <sys/times.h> and ensure that HZ is defined
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
78 #endif |
5669a0b893db
data.cc: include <sys/times.h> and ensure that HZ is defined
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
79 |
7914
e998e81224b5
Various compilation fixes for MSVC.
John W. Eaton <jwe@octave.org>
parents:
7815
diff
changeset
|
80 #if ! defined (HAVE_HYPOTF) && defined (HAVE__HYPOTF) |
e998e81224b5
Various compilation fixes for MSVC.
John W. Eaton <jwe@octave.org>
parents:
7815
diff
changeset
|
81 #define hypotf _hypotf |
e998e81224b5
Various compilation fixes for MSVC.
John W. Eaton <jwe@octave.org>
parents:
7815
diff
changeset
|
82 #define HAVE_HYPOTF 1 |
e998e81224b5
Various compilation fixes for MSVC.
John W. Eaton <jwe@octave.org>
parents:
7815
diff
changeset
|
83 #endif |
e998e81224b5
Various compilation fixes for MSVC.
John W. Eaton <jwe@octave.org>
parents:
7815
diff
changeset
|
84 |
20652
7a8096f8df5d
more cleanup of indexing exceptions
John W. Eaton <jwe@octave.org>
parents:
20651
diff
changeset
|
85 static void |
7a8096f8df5d
more cleanup of indexing exceptions
John W. Eaton <jwe@octave.org>
parents:
20651
diff
changeset
|
86 index_error (const char *fmt, const std::string& idx, const std::string& msg) |
7a8096f8df5d
more cleanup of indexing exceptions
John W. Eaton <jwe@octave.org>
parents:
20651
diff
changeset
|
87 { |
7a8096f8df5d
more cleanup of indexing exceptions
John W. Eaton <jwe@octave.org>
parents:
20651
diff
changeset
|
88 error (fmt, idx.c_str (), msg.c_str ()); |
7a8096f8df5d
more cleanup of indexing exceptions
John W. Eaton <jwe@octave.org>
parents:
20651
diff
changeset
|
89 } |
7a8096f8df5d
more cleanup of indexing exceptions
John W. Eaton <jwe@octave.org>
parents:
20651
diff
changeset
|
90 |
1957 | 91 DEFUN (all, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
92 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
93 @deftypefn {} {} all (@var{x})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
94 @deftypefnx {} {} all (@var{x}, @var{dim})\n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
95 For a vector argument, return true (logical 1) if all elements of the vector\n\ |
18812
9ac2357f19bc
doc: Replace "non-zero" with "nonzero" to match existing usage.
Rik <rik@octave.org>
parents:
18811
diff
changeset
|
96 are nonzero.\n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
97 \n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
98 For a matrix argument, return a row vector of logical ones and\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
99 zeros with each element indicating whether all of the elements of the\n\ |
18812
9ac2357f19bc
doc: Replace "non-zero" with "nonzero" to match existing usage.
Rik <rik@octave.org>
parents:
18811
diff
changeset
|
100 corresponding column of the matrix are nonzero. For example:\n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
101 \n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
102 @example\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
103 @group\n\ |
18679
a142f35f3cb6
doc: Fix unbalanced parentheses in documentation.
Rik <rik@octave.org>
parents:
18678
diff
changeset
|
104 all ([2, 3; 1, 0])\n\ |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
105 @result{} [ 1, 0 ]\n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
106 @end group\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
107 @end example\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
108 \n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
109 If the optional argument @var{dim} is supplied, work along dimension\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
110 @var{dim}.\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
111 @seealso{any}\n\ |
3369 | 112 @end deftypefn") |
523 | 113 { |
20943
42319d289714
maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
114 int nargin = args.length (); |
42319d289714
maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
115 |
42319d289714
maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
116 if (nargin < 1 || nargin > 2) |
42319d289714
maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
117 print_usage (); |
42319d289714
maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
118 |
42319d289714
maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
119 int dim = (nargin == 1 ? -1 |
42319d289714
maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
120 : args(1).int_value ("all: DIM must be an integer")-1); |
42319d289714
maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
121 |
42319d289714
maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
122 if (dim < -1) |
42319d289714
maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
123 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
|
124 |
42319d289714
maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
125 return ovl (args(0).all (dim)); |
523 | 126 } |
127 | |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
128 /* |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
129 %!test |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
130 %! 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
|
131 %! x(1,1) = 0; |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
132 %! 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
|
133 %! 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
|
134 %! 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
|
135 %! 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
|
136 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
137 %!test |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
138 %! 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
|
139 %! x(1,1) = 0; |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
140 %! 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
|
141 %! 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
|
142 %! 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
|
143 %! 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
|
144 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
145 %!error all () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
146 %!error all (1, 2, 3) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
147 */ |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
148 |
1957 | 149 DEFUN (any, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
150 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
151 @deftypefn {} {} any (@var{x})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
152 @deftypefnx {} {} any (@var{x}, @var{dim})\n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
153 For a vector argument, return true (logical 1) if any element of the vector\n\ |
18812
9ac2357f19bc
doc: Replace "non-zero" with "nonzero" to match existing usage.
Rik <rik@octave.org>
parents:
18811
diff
changeset
|
154 is nonzero.\n\ |
3369 | 155 \n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
156 For a matrix argument, return a row vector of logical ones and\n\ |
3369 | 157 zeros with each element indicating whether any of the elements of the\n\ |
18812
9ac2357f19bc
doc: Replace "non-zero" with "nonzero" to match existing usage.
Rik <rik@octave.org>
parents:
18811
diff
changeset
|
158 corresponding column of the matrix are nonzero. For example:\n\ |
3369 | 159 \n\ |
160 @example\n\ | |
161 @group\n\ | |
162 any (eye (2, 4))\n\ | |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
163 @result{} [ 1, 1, 0, 0 ]\n\ |
3369 | 164 @end group\n\ |
165 @end example\n\ | |
166 \n\ | |
4015 | 167 If the optional argument @var{dim} is supplied, work along dimension\n\ |
10840 | 168 @var{dim}. For example:\n\ |
3369 | 169 \n\ |
170 @example\n\ | |
4015 | 171 @group\n\ |
172 any (eye (2, 4), 2)\n\ | |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
173 @result{} [ 1; 1 ]\n\ |
4015 | 174 @end group\n\ |
3369 | 175 @end example\n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
176 @seealso{all}\n\ |
3369 | 177 @end deftypefn") |
523 | 178 { |
20943
42319d289714
maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
179 int nargin = args.length (); |
42319d289714
maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
180 |
42319d289714
maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
181 if (nargin < 1 || nargin > 2) |
42319d289714
maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
182 print_usage (); |
42319d289714
maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
183 |
42319d289714
maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
184 int dim = (nargin == 1 ? -1 |
42319d289714
maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
185 : args(1).int_value ("any: DIM must be an integer")-1); |
42319d289714
maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
186 |
42319d289714
maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
187 if (dim < -1) |
42319d289714
maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
188 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
|
189 |
42319d289714
maint: Eliminate ANY_ALL macro in data.cc
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
190 return ovl (args(0).any (dim)); |
523 | 191 } |
192 | |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
193 /* |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
194 %!test |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
195 %! 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
|
196 %! x(3,3) = 1; |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
197 %! 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
|
198 %! 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
|
199 %! 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
|
200 %! 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
|
201 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
202 %!test |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
203 %! 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
|
204 %! x(3,3) = 1; |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
205 %! 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
|
206 %! 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
|
207 %! 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
|
208 %! 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
|
209 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
210 %!error any () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
211 %!error any (1, 2, 3) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
212 */ |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
213 |
649 | 214 // These mapping functions may also be useful in other places, eh? |
215 | |
1957 | 216 DEFUN (atan2, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
217 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
218 @deftypefn {} {} atan2 (@var{y}, @var{x})\n\ |
3428 | 219 Compute atan (@var{y} / @var{x}) for corresponding elements of @var{y}\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
220 and @var{x}.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
221 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
222 @var{y} and @var{x} must match in size and orientation.\n\ |
15028
397f0d80bd47
Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents:
15024
diff
changeset
|
223 @seealso{tan, tand, tanh, atanh}\n\ |
3439 | 224 @end deftypefn") |
649 | 225 { |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
226 if (args.length () != 2) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
227 print_usage (); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
228 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
229 octave_value retval; |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
230 |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
231 if (! args(0).is_numeric_type ()) |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21078
diff
changeset
|
232 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
|
233 |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
234 if (! args(1).is_numeric_type ()) |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21078
diff
changeset
|
235 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
|
236 |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
237 if (args(0).is_complex_type () || args(1).is_complex_type ()) |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
238 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
|
239 |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
240 if (args(0).is_single_type () || args(1).is_single_type ()) |
649 | 241 { |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
242 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
|
243 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
|
244 else |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
245 { |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
246 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
|
247 FloatNDArray a1 = args(1).float_array_value (); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
248 retval = binmap<float> (a0, a1, ::atan2f, "atan2"); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
249 } |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
250 } |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
251 else |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
252 { |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
253 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
|
254 retval = atan2 (args(0).scalar_value (), args(1).scalar_value ()); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
255 else if (args(0).is_sparse_type ()) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
256 { |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
257 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
|
258 SparseMatrix m1 = args(1).sparse_matrix_value (); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
259 retval = binmap<double> (m0, m1, ::atan2, "atan2"); |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
260 } |
7494
bd2bd04e68ca
Treat integer types for mod/rem correctly
David Bateman <dbateman@free.fr>
parents:
7433
diff
changeset
|
261 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
262 { |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
263 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
|
264 NDArray a1 = args(1).array_value (); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
265 retval = binmap<double> (a0, a1, ::atan2, "atan2"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
266 } |
649 | 267 } |
268 | |
269 return retval; | |
270 } | |
271 | |
7506
798b0a00e80c
atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents:
7505
diff
changeset
|
272 /* |
7741 | 273 %!assert (size (atan2 (zeros (0, 2), zeros (0, 2))), [0, 2]) |
274 %!assert (size (atan2 (rand (2, 3, 4), zeros (2, 3, 4))), [2, 3, 4]) | |
275 %!assert (size (atan2 (rand (2, 3, 4), 1)), [2, 3, 4]) | |
276 %!assert (size (atan2 (1, rand (2, 3, 4))), [2, 3, 4]) | |
277 %!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
|
278 |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
279 %!test |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
280 %! rt2 = sqrt (2); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
281 %! rt3 = sqrt (3); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
282 %! 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
|
283 %! 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
|
284 %! 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
|
285 %! 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
|
286 |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
287 %!test |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
288 %! rt2 = sqrt (2); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
289 %! rt3 = sqrt (3); |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
290 %! 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
|
291 %! 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
|
292 %! 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
|
293 %! 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
|
294 |
18789
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18775
diff
changeset
|
295 ## Test sparse implementations |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18775
diff
changeset
|
296 %!shared xs |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18775
diff
changeset
|
297 %! xs = sparse (0:3); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18775
diff
changeset
|
298 %!test |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18775
diff
changeset
|
299 %! y = atan2 (1, xs); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18775
diff
changeset
|
300 %! assert (issparse (y), false); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18775
diff
changeset
|
301 %! assert (nnz (y), 4); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18775
diff
changeset
|
302 %! 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
|
303 %!test |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18775
diff
changeset
|
304 %! y = atan2 (0, xs); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18775
diff
changeset
|
305 %! assert (issparse (y), false); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18775
diff
changeset
|
306 %! assert (nnz (y), 0); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18775
diff
changeset
|
307 %! 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
|
308 %!test |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18775
diff
changeset
|
309 %! y = atan2 (xs, 1); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18775
diff
changeset
|
310 %! assert (issparse (y)); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18775
diff
changeset
|
311 %! assert (nnz (y), 3); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18775
diff
changeset
|
312 %! 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
|
313 %!test |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18775
diff
changeset
|
314 %! y = atan2 (xs, 0); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18775
diff
changeset
|
315 %! assert (issparse (y)); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18775
diff
changeset
|
316 %! assert (nnz (y), 3); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18775
diff
changeset
|
317 %! 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
|
318 %!test |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18775
diff
changeset
|
319 %! 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
|
320 %! assert (issparse (y)); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18775
diff
changeset
|
321 %! assert (nnz (y), 3); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18775
diff
changeset
|
322 %! 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
|
323 %!test |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18775
diff
changeset
|
324 %! 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
|
325 %! assert (issparse (y)); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18775
diff
changeset
|
326 %! assert (nnz (y), 3); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18775
diff
changeset
|
327 %! 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
|
328 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
329 %!error atan2 () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
330 %!error atan2 (1, 2, 3) |
7506
798b0a00e80c
atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents:
7505
diff
changeset
|
331 */ |
798b0a00e80c
atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents:
7505
diff
changeset
|
332 |
7815
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
333 |
10538
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
334 static octave_value |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
335 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
|
336 { |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
337 octave_value retval; |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
338 |
18100
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17915
diff
changeset
|
339 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
|
340 octave_value arg1 = y; |
10538
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
341 if (! arg0.is_numeric_type ()) |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21078
diff
changeset
|
342 err_wrong_type_arg ("hypot", arg0); |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
343 if (! arg1.is_numeric_type ()) |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21078
diff
changeset
|
344 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
|
345 |
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_complex_type ()) |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
347 arg0 = arg0.abs (); |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
348 if (arg1.is_complex_type ()) |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
349 arg1 = arg1.abs (); |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
350 |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
351 if (arg0.is_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
|
352 { |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
353 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
|
354 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
|
355 else |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
356 { |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
357 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
|
358 FloatNDArray a1 = arg1.float_array_value (); |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
359 retval = binmap<float> (a0, a1, ::hypotf, "hypot"); |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
360 } |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
361 } |
10538
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
362 else |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
363 { |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
364 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
|
365 retval = hypot (arg0.scalar_value (), arg1.scalar_value ()); |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
366 else if (arg0.is_sparse_type () || arg1.is_sparse_type ()) |
10538
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
367 { |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
368 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
|
369 SparseMatrix m1 = arg1.sparse_matrix_value (); |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
370 retval = binmap<double> (m0, m1, ::hypot, "hypot"); |
10538
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
371 } |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
372 else |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
373 { |
21118
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
374 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
|
375 NDArray a1 = arg1.array_value (); |
3ac9f47fb04b
Invert pattern if/code/else/err_XXX to if !/err_XXX/code.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
376 retval = binmap<double> (a0, a1, ::hypot, "hypot"); |
10538
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
377 } |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
378 } |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
379 |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
380 return retval; |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
381 } |
7815
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
382 |
7631 | 383 DEFUN (hypot, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
384 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
385 @deftypefn {} {} hypot (@var{x}, @var{y})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
386 @deftypefnx {} {} hypot (@var{x}, @var{y}, @var{z}, @dots{})\n\ |
9165
8c71a86c4bf4
Update section 17.5 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9163
diff
changeset
|
387 Compute the element-by-element square root of the sum of the squares of\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
388 @var{x} and @var{y}.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
389 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
390 This is equivalent to\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
391 @code{sqrt (@var{x}.^2 + @var{y}.^2)}, but is calculated in a manner that\n\ |
9165
8c71a86c4bf4
Update section 17.5 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9163
diff
changeset
|
392 avoids overflows for large values of @var{x} or @var{y}.\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
393 \n\ |
10538
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
394 @code{hypot} can also be called with more than 2 arguments; in this case,\n\ |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
395 the arguments are accumulated from left to right:\n\ |
10840 | 396 \n\ |
10538
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
397 @example\n\ |
10711
fbd7843974fa
Periodic grammar check of documentation files to ensure common format.
Rik <octave@nomad.inbox5.com>
parents:
10707
diff
changeset
|
398 @group\n\ |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
399 hypot (hypot (@var{x}, @var{y}), @var{z})\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
400 hypot (hypot (hypot (@var{x}, @var{y}), @var{z}), @var{w}), etc.\n\ |
10711
fbd7843974fa
Periodic grammar check of documentation files to ensure common format.
Rik <octave@nomad.inbox5.com>
parents:
10707
diff
changeset
|
401 @end group\n\ |
10538
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
402 @end example\n\ |
7631 | 403 @end deftypefn") |
404 { | |
405 int nargin = args.length (); | |
406 | |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
407 if (nargin < 2) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
408 print_usage (); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
409 |
21078
49852ff04747
maint: Remove unnecessary declarations of retval.
Rik <rik@octave.org>
parents:
21062
diff
changeset
|
410 octave_value retval; |
49852ff04747
maint: Remove unnecessary declarations of retval.
Rik <rik@octave.org>
parents:
21062
diff
changeset
|
411 |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
412 if (nargin == 2) |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
413 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
|
414 else |
10538
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
415 { |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
416 retval = args(0); |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
417 |
20562
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
418 for (int i = 1; i < nargin; i++) |
10538
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
419 retval = do_hypot (retval, args(i)); |
7631 | 420 } |
421 | |
422 return retval; | |
423 } | |
424 | |
425 /* | |
7741 | 426 %!assert (size (hypot (zeros (0, 2), zeros (0, 2))), [0, 2]) |
427 %!assert (size (hypot (rand (2, 3, 4), zeros (2, 3, 4))), [2, 3, 4]) | |
428 %!assert (size (hypot (rand (2, 3, 4), 1)), [2, 3, 4]) | |
429 %!assert (size (hypot (1, rand (2, 3, 4))), [2, 3, 4]) | |
430 %!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
|
431 %!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
|
432 %!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
|
433 |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18775
diff
changeset
|
434 ## Test sparse implementations |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18775
diff
changeset
|
435 %!shared xs |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18775
diff
changeset
|
436 %! xs = sparse (0:3); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18775
diff
changeset
|
437 %!test |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18775
diff
changeset
|
438 %! y = hypot (1, xs); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18775
diff
changeset
|
439 %! assert (nnz (y), 4); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18775
diff
changeset
|
440 %! 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
|
441 %!test |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18775
diff
changeset
|
442 %! y = hypot (0, xs); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18775
diff
changeset
|
443 %! assert (nnz (y), 3); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18775
diff
changeset
|
444 %! assert (y, xs); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18775
diff
changeset
|
445 %!test |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18775
diff
changeset
|
446 %! y = hypot (xs, 1); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18775
diff
changeset
|
447 %! assert (nnz (y), 4); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18775
diff
changeset
|
448 %! 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
|
449 %!test |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18775
diff
changeset
|
450 %! y = hypot (xs, 0); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18775
diff
changeset
|
451 %! assert (nnz (y), 3); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18775
diff
changeset
|
452 %! assert (y, xs); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18775
diff
changeset
|
453 %!test |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18775
diff
changeset
|
454 %! 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
|
455 %! assert (nnz (y), 1); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18775
diff
changeset
|
456 %! 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
|
457 %!test |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18775
diff
changeset
|
458 %! 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
|
459 %! assert (nnz (y), 1); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18775
diff
changeset
|
460 %! 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
|
461 |
7631 | 462 */ |
463 | |
9813
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
464 template<typename T, typename ET> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
465 void |
9813
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
466 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
|
467 { |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
468 f = Array<T>(x.dims ()); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
469 e = Array<ET>(x.dims ()); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
470 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
|
471 { |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
472 int exp; |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
473 f.xelem (i) = xlog2 (x(i), exp); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
474 e.xelem (i) = exp; |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
475 } |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
476 } |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
477 |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
478 DEFUN (log2, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
479 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
480 @deftypefn {} {} log2 (@var{x})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
481 @deftypefnx {} {[@var{f}, @var{e}] =} log2 (@var{x})\n\ |
9813
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
482 Compute the base-2 logarithm of each element of @var{x}.\n\ |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
483 \n\ |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
484 If called with two output arguments, split @var{x} into\n\ |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
485 binary mantissa and exponent so that\n\ |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
486 @tex\n\ |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
487 ${1 \\over 2} \\le \\left| f \\right| < 1$\n\ |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
488 @end tex\n\ |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
489 @ifnottex\n\ |
20569
c6059134f5d3
data.cc: Add @w{} around @code segments in docstrings to prevent line breaks.
Rik <rik@octave.org>
parents:
20398
diff
changeset
|
490 @w{@code{1/2 <= abs(f) < 1}}\n\ |
9813
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
491 @end ifnottex\n\ |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
492 and @var{e} is an integer. If\n\ |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
493 @tex\n\ |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
494 $x = 0$, $f = e = 0$.\n\ |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
495 @end tex\n\ |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
496 @ifnottex\n\ |
20569
c6059134f5d3
data.cc: Add @w{} around @code segments in docstrings to prevent line breaks.
Rik <rik@octave.org>
parents:
20398
diff
changeset
|
497 @w{@code{x = 0}}, @w{@code{f = e = 0}}.\n\ |
9813
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
498 @end ifnottex\n\ |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
499 @seealso{pow2, log, log10, exp}\n\ |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
500 @end deftypefn") |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
501 { |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
502 if (args.length () != 1) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
503 print_usage (); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
504 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
505 octave_value_list retval; |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
506 |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
507 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
|
508 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
|
509 else if (args(0).is_single_type ()) |
9813
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
510 { |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
511 if (args(0).is_real_type ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
512 { |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
513 FloatNDArray f; |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
514 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
|
515 // 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
|
516 FloatMatrix e; |
9813
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
517 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
|
518 retval = ovl (f, e); |
9813
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
519 } |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
520 else if (args(0).is_complex_type ()) |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
521 { |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
522 FloatComplexNDArray f; |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
523 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
|
524 // 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
|
525 FloatNDArray e; |
9813
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
526 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
|
527 retval = ovl (f, e); |
9813
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
528 } |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
529 } |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
530 else if (args(0).is_real_type ()) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
531 { |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
532 NDArray f; |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
533 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
|
534 // 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
|
535 Matrix e; |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
536 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
|
537 retval = ovl (f, e); |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
538 } |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
539 else if (args(0).is_complex_type ()) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
540 { |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
541 ComplexNDArray f; |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
542 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
|
543 // 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
|
544 NDArray e; |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
545 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
|
546 retval = ovl (f, e); |
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 else |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21078
diff
changeset
|
549 err_wrong_type_arg ("log2", args(0)); |
9813
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 return retval; |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
552 } |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
553 |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
554 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
555 %!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
|
556 %!assert (log2 (Inf), Inf) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
557 %!assert (isnan (log2 (NaN))) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
558 %!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
|
559 %!assert (log2 (complex (0,Inf)), Inf + log2 (i)) |
9813
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
560 |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
561 %!test |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
562 %! [f, e] = log2 ([0,-1; 2,-4; Inf,-Inf]); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
563 %! 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
|
564 %! assert (e(1:2,:), [0,1;2,3]); |
9813
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
565 |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
566 %!test |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
567 %! [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
|
568 %! 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
|
569 %! 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
|
570 |
9d185537e5d1
* data.cc: New test for log2 (bug #42583).
John W. Eaton <jwe@octave.org>
parents:
18809
diff
changeset
|
571 # bug #42583 |
9d185537e5d1
* data.cc: New test for log2 (bug #42583).
John W. Eaton <jwe@octave.org>
parents:
18809
diff
changeset
|
572 %!assert (all (log2 (pow2 (-1074:1023)) == -1074:1023)) |
9813
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
573 */ |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
574 |
10436
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
575 DEFUN (rem, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
576 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
577 @deftypefn {} {} rem (@var{x}, @var{y})\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
578 Return the remainder of the division @code{@var{x} / @var{y}}.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
579 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
580 The remainder is computed using the expression\n\ |
10436
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
581 \n\ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
582 @example\n\ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
583 x - y .* fix (x ./ y)\n\ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
584 @end example\n\ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
585 \n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
586 An error message is printed if the dimensions of the arguments do not agree,\n\ |
20374
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
587 or if either argument is complex.\n\ |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
588 \n\ |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
589 Programming Notes: Floating point numbers within a few eps of an integer will\n\ |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
590 be rounded to an integer before computation for compatibility with\n\ |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
591 @sc{matlab}.\n\ |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
592 \n\ |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
593 By convention,\n\ |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
594 \n\ |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
595 @example\n\ |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
596 @group\n\ |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
597 rem (@var{x}, 0) = NaN if @var{x} is a floating point variable\n\ |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
598 rem (@var{x}, 0) = 0 if @var{x} is an integer variable\n\ |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
599 rem (@var{x}, @var{y}) returns a value with the signbit from @var{x}\n\ |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
600 @end group\n\ |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
601 @end example\n\ |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
602 \n\ |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
603 For the opposite conventions see the @code{mod} function. In general,\n\ |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
604 @code{rem} is best when computing the remainder after division of two\n\ |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
605 @emph{positive} numbers. For negative numbers, or when the values are\n\ |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
606 periodic, @code{mod} is a better choice.\n\ |
10436
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
607 @seealso{mod}\n\ |
4311 | 608 @end deftypefn") |
609 { | |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
610 if (args.length () != 2) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
611 print_usage (); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
612 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
613 octave_value retval; |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
614 |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
615 if (! args(0).is_numeric_type ()) |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21078
diff
changeset
|
616 err_wrong_type_arg ("rem", args(0)); |
20980
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
617 |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
618 if (! args(1).is_numeric_type ()) |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21078
diff
changeset
|
619 err_wrong_type_arg ("rem", args(1)); |
20980
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
620 |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
621 if (args(0).is_complex_type () || args(1).is_complex_type ()) |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
622 error ("rem: not defined for complex numbers"); |
20980
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
623 |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
624 if (args(0).is_integer_type () || args(1).is_integer_type ()) |
4311 | 625 { |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
626 builtin_type_t btyp0 = args(0).builtin_type (); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
627 builtin_type_t btyp1 = args(1).builtin_type (); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
628 if (btyp0 == btyp_double || btyp0 == btyp_float) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
629 btyp0 = btyp1; |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
630 if (btyp1 == btyp_double || btyp1 == btyp_float) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
631 btyp1 = btyp0; |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
632 |
20980
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
633 if (btyp0 != btyp1) |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
634 error ("rem: cannot combine %s and %d", |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
635 args(0).class_name ().c_str (), |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
636 args(1).class_name ().c_str ()); |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
637 |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
638 switch (btyp0) |
10436
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
639 { |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
640 #define MAKE_INT_BRANCH(X) \ |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
641 case btyp_ ## X: \ |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
642 { \ |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
643 X##NDArray a0 = args(0).X##_array_value (); \ |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
644 X##NDArray a1 = args(1).X##_array_value (); \ |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
645 retval = binmap<octave_##X,octave_##X,octave_##X> (a0, a1, rem, "rem"); \ |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
646 } \ |
20980
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
647 break |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
648 |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
649 MAKE_INT_BRANCH (int8); |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
650 MAKE_INT_BRANCH (int16); |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
651 MAKE_INT_BRANCH (int32); |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
652 MAKE_INT_BRANCH (int64); |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
653 MAKE_INT_BRANCH (uint8); |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
654 MAKE_INT_BRANCH (uint16); |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
655 MAKE_INT_BRANCH (uint32); |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
656 MAKE_INT_BRANCH (uint64); |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
657 |
10436
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
658 #undef MAKE_INT_BRANCH |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
659 |
20980
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
660 default: |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
661 panic_impossible (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
662 } |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
663 } |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
664 else if (args(0).is_single_type () || args(1).is_single_type ()) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
665 { |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
666 if (args(0).is_scalar_type () && args(1).is_scalar_type ()) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
667 retval = xrem (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
|
668 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
669 { |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
670 FloatNDArray a0 = args(0).float_array_value (); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
671 FloatNDArray a1 = args(1).float_array_value (); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
672 retval = binmap<float> (a0, a1, xrem<float>, "rem"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
673 } |
4311 | 674 } |
675 else | |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
676 { |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
677 if (args(0).is_scalar_type () && args(1).is_scalar_type ()) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
678 retval = xrem (args(0).scalar_value (), args(1).scalar_value ()); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
679 else if (args(0).is_sparse_type () || args(1).is_sparse_type ()) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
680 { |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
681 SparseMatrix m0 = args(0).sparse_matrix_value (); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
682 SparseMatrix m1 = args(1).sparse_matrix_value (); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
683 retval = binmap<double> (m0, m1, xrem<double>, "rem"); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
684 } |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
685 else |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
686 { |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
687 NDArray a0 = args(0).array_value (); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
688 NDArray a1 = args(1).array_value (); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
689 retval = binmap<double> (a0, a1, xrem<double>, "rem"); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
690 } |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
691 } |
4311 | 692 |
693 return retval; | |
694 } | |
695 | |
7506
798b0a00e80c
atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents:
7505
diff
changeset
|
696 /* |
19118 | 697 %!assert (size (rem (zeros (0, 2), zeros (0, 2))), [0, 2]) |
698 %!assert (size (rem (rand (2, 3, 4), zeros (2, 3, 4))), [2, 3, 4]) | |
699 %!assert (size (rem (rand (2, 3, 4), 1)), [2, 3, 4]) | |
700 %!assert (size (rem (1, rand (2, 3, 4))), [2, 3, 4]) | |
701 %!assert (size (rem (1, 2)), [1, 1]) | |
18789
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18775
diff
changeset
|
702 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
703 %!assert (rem ([1, 2, 3; -1, -2, -3], 2), [1, 0, 1; -1, 0, -1]) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
704 %!assert (rem ([1, 2, 3; -1, -2, -3], 2 * ones (2, 3)),[1, 0, 1; -1, 0, -1]) |
20374
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
705 %!assert (rem ([0, 1, 2], [0, 0, 1]), [NaN, NaN, 0]); |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
706 %!assert (rem (uint8 ([1, 2, 3; -1, -2, -3]), uint8 (2)), uint8 ([1, 0, 1; -1, 0, -1])) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
707 %!assert (uint8 (rem ([1, 2, 3; -1, -2, -3], 2 * ones (2, 3))),uint8 ([1, 0, 1; -1, 0, -1])) |
20374
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
708 %!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
|
709 |
18789
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18775
diff
changeset
|
710 ## Test sparse implementations |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18775
diff
changeset
|
711 %!shared xs |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18775
diff
changeset
|
712 %! xs = sparse (0:3); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18775
diff
changeset
|
713 %!test |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18775
diff
changeset
|
714 %! 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
|
715 %! 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
|
716 %! 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
|
717 %!test |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18775
diff
changeset
|
718 %! 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
|
719 %! assert (nnz (y), 1); |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
720 %! 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
|
721 %!test |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18775
diff
changeset
|
722 %! y = rem (xs, 2); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18775
diff
changeset
|
723 %! assert (nnz (y), 2); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18775
diff
changeset
|
724 %! 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
|
725 %!test |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18775
diff
changeset
|
726 %! y = rem (xs, 1); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18775
diff
changeset
|
727 %! assert (nnz (y), 0); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18775
diff
changeset
|
728 %! 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
|
729 %!test |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18775
diff
changeset
|
730 %! 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
|
731 %! assert (nnz (y), 3); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18775
diff
changeset
|
732 %! 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
|
733 %!test |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18775
diff
changeset
|
734 %! 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
|
735 %! assert (nnz (y), 1); |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
736 %! 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
|
737 |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
738 ## Bug #45587 |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
739 %!assert (signbit (rem (-0, 1))) |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
740 %!assert (! signbit (rem (0, 1))) |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
741 |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
742 ## bug #42627 |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
743 %!assert (rem (0.94, 0.01), 0.0) |
18789
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18775
diff
changeset
|
744 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
745 %!error rem (uint (8), int8 (5)) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
746 %!error rem (uint8 ([1, 2]), uint8 ([3, 4, 5])) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
747 %!error rem () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
748 %!error rem (1, 2, 3) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
749 %!error rem ([1, 2], [3, 4, 5]) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
750 %!error rem (i, 1) |
7506
798b0a00e80c
atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents:
7505
diff
changeset
|
751 */ |
798b0a00e80c
atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents:
7505
diff
changeset
|
752 |
10436
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
753 DEFUN (mod, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
754 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
755 @deftypefn {} {} mod (@var{x}, @var{y})\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
756 Compute the modulo of @var{x} and @var{y}.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
757 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
758 Conceptually this is given by\n\ |
10436
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
759 \n\ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
760 @example\n\ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
761 x - y .* floor (x ./ y)\n\ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
762 @end example\n\ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
763 \n\ |
10846
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10840
diff
changeset
|
764 @noindent\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
765 and is written such that the correct modulus is returned for integer types.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
766 This function handles negative values correctly. That is,\n\ |
20374
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
767 @w{@code{mod (-1, 3)}} is 2, not -1, as @w{@code{rem (-1, 3)}} returns.\n\ |
10436
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
768 \n\ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
769 An error results if the dimensions of the arguments do not agree, or if\n\ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
770 either of the arguments is complex.\n\ |
20374
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
771 \n\ |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
772 Programming Notes: Floating point numbers within a few eps of an integer will\n\ |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
773 be rounded to an integer before computation for compatibility with\n\ |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
774 @sc{matlab}.\n\ |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
775 \n\ |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
776 By convention,\n\ |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
777 \n\ |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
778 @example\n\ |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
779 @group\n\ |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
780 mod (@var{x}, 0) = @var{x}\n\ |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
781 mod (@var{x}, @var{y}) returns a value with the signbit from @var{y}\n\ |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
782 @end group\n\ |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
783 @end example\n\ |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
784 \n\ |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
785 For the opposite conventions see the @code{rem} function. In general,\n\ |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
786 @code{mod} is a better choice than @code{rem} when any of the inputs are\n\ |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
787 negative numbers or when the values are periodic.\n\ |
10436
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
788 @seealso{rem}\n\ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
789 @end deftypefn") |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
790 { |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
791 if (args.length () != 2) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
792 print_usage (); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
793 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
794 octave_value retval; |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
795 |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
796 if (! args(0).is_numeric_type ()) |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21078
diff
changeset
|
797 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
|
798 |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
799 if (! args(1).is_numeric_type ()) |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21078
diff
changeset
|
800 err_wrong_type_arg ("mod", args(1)); |
20980
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
801 |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
802 if (args(0).is_complex_type () || args(1).is_complex_type ()) |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
803 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
|
804 |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
805 if (args(0).is_integer_type () || args(1).is_integer_type ()) |
10436
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
806 { |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
807 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
|
808 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
|
809 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
|
810 btyp0 = btyp1; |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
811 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
|
812 btyp1 = btyp0; |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
813 |
20980
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
814 if (btyp0 != btyp1) |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
815 error ("mod: cannot combine %s and %d", |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
816 args(0).class_name ().c_str (), |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
817 args(1).class_name ().c_str ()); |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
818 |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
819 switch (btyp0) |
10436
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
820 { |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
821 #define MAKE_INT_BRANCH(X) \ |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
822 case btyp_ ## X: \ |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
823 { \ |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
824 X##NDArray a0 = args(0).X##_array_value (); \ |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
825 X##NDArray a1 = args(1).X##_array_value (); \ |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
826 retval = binmap<octave_##X,octave_##X,octave_##X> (a0, a1, mod, "mod"); \ |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
827 } \ |
20980
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
828 break |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
829 |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
830 MAKE_INT_BRANCH (int8); |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
831 MAKE_INT_BRANCH (int16); |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
832 MAKE_INT_BRANCH (int32); |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
833 MAKE_INT_BRANCH (int64); |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
834 MAKE_INT_BRANCH (uint8); |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
835 MAKE_INT_BRANCH (uint16); |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
836 MAKE_INT_BRANCH (uint32); |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
837 MAKE_INT_BRANCH (uint64); |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
838 |
10436
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
839 #undef MAKE_INT_BRANCH |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
840 |
20980
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
841 default: |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
842 panic_impossible (); |
10436
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
843 } |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
844 } |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
845 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
|
846 { |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
847 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
|
848 retval = xmod (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
|
849 else |
10436
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
850 { |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
851 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
|
852 FloatNDArray a1 = args(1).float_array_value (); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
853 retval = binmap<float> (a0, a1, xmod<float>, "mod"); |
10436
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
854 } |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
855 } |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
856 else |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
857 { |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
858 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
|
859 retval = xmod (args(0).scalar_value (), args(1).scalar_value ()); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
860 else if (args(0).is_sparse_type () || args(1).is_sparse_type ()) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
861 { |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
862 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
|
863 SparseMatrix m1 = args(1).sparse_matrix_value (); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
864 retval = binmap<double> (m0, m1, xmod<double>, "mod"); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
865 } |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
866 else |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
867 { |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
868 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
|
869 NDArray a1 = args(1).array_value (); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
870 retval = binmap<double> (a0, a1, xmod<double>, "mod"); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
871 } |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
872 } |
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 return retval; |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
875 } |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
876 |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
877 /* |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
878 ## empty input test |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
879 %!assert (isempty (mod ([], []))) |
10436
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
880 |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
881 ## 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
|
882 %!assert (mod (5, 3), 2) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
883 %!assert (mod (-5, 3), 1) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
884 %!assert (mod (0, 3), 0) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
885 %!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
|
886 %!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
|
887 %!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
|
888 |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
889 ## x mod 0 tests |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
890 %!assert (mod (5, 0), 5) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
891 %!assert (mod (-5, 0), -5) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
892 %!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
|
893 %!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
|
894 %!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
|
895 %!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
|
896 |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
897 ## mixed scalar/matrix tests |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
898 %!assert (mod ([-5, 5; 0, 3], 0), [-5, 5; 0, 3]) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
899 %!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
|
900 %!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
|
901 %!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
|
902 %!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
|
903 |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
904 ## integer types |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
905 %!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
|
906 %!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
|
907 %!assert (mod (uint8 ([1:5]), uint8 (0)), uint8 ([1:5])) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
908 %!error (mod (uint8 (5), int8 (4))) |
10436
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
909 |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
910 ## mixed integer/real types |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
911 %!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
|
912 %!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
|
913 %!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
|
914 |
903c1a3df301
Add additional tests for mod with non-integer real values.
Rik <octave@nomad.inbox5.com>
parents:
11242
diff
changeset
|
915 ## non-integer real numbers |
903c1a3df301
Add additional tests for mod with non-integer real values.
Rik <octave@nomad.inbox5.com>
parents:
11242
diff
changeset
|
916 %!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
|
917 %!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
|
918 |
20374
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
919 ## Bug #45587 |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
920 %!assert (signbit (mod (-0, 0))) |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
921 %!assert (! signbit (mod (0, -0))) |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
922 |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
923 ## Bug #42627 |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
924 %!assert (mod (0.94, 0.01), 0.0) |
10436
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
925 */ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
926 |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21053
diff
changeset
|
927 // FIXME: Macros NATIVE_REDUCTION_1 and NATIVE_REDUCTION seem to be unused. |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21053
diff
changeset
|
928 // Checked 1/23/2016. They should probably be removed for clarity. |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
929 // FIXME: Need to convert reduction functions of this file for single precision |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7743
diff
changeset
|
930 |
7112 | 931 #define NATIVE_REDUCTION_1(FCN, TYPE, DIM) \ |
932 (arg.is_ ## TYPE ## _type ()) \ | |
933 { \ | |
934 TYPE ## NDArray tmp = arg. TYPE ##_array_value (); \ | |
20562
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
935 \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
936 retval = tmp.FCN (DIM); \ |
7112 | 937 } |
938 | |
8780
ea76466605ba
support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents:
8756
diff
changeset
|
939 #define NATIVE_REDUCTION(FCN, BOOL_FCN) \ |
7112 | 940 \ |
941 int nargin = args.length (); \ | |
942 \ | |
943 bool isnative = false; \ | |
7815
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
944 bool isdouble = false; \ |
20562
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
945 \ |
7112 | 946 if (nargin > 1 && args(nargin - 1).is_string ()) \ |
947 { \ | |
948 std::string str = args(nargin - 1).string_value (); \ | |
20562
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
949 \ |
19743
67f2c76f9f4d
Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents:
19739
diff
changeset
|
950 if (str == "native") \ |
67f2c76f9f4d
Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents:
19739
diff
changeset
|
951 isnative = true; \ |
67f2c76f9f4d
Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents:
19739
diff
changeset
|
952 else if (str == "double") \ |
67f2c76f9f4d
Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents:
19739
diff
changeset
|
953 isdouble = true; \ |
67f2c76f9f4d
Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents:
19739
diff
changeset
|
954 else \ |
67f2c76f9f4d
Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents:
19739
diff
changeset
|
955 error ("sum: unrecognized string argument"); \ |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21053
diff
changeset
|
956 \ |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21053
diff
changeset
|
957 nargin--; \ |
7112 | 958 } \ |
20562
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
959 \ |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
960 if (nargin < 1 || nargin > 2) \ |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
961 print_usage (); \ |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
962 \ |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
963 octave_value retval; \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
964 \ |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
965 octave_value arg = args(0); \ |
7112 | 966 \ |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
967 int dim = (nargin == 1 ? -1 : args(1).int_value (true) - 1); \ |
7112 | 968 \ |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
969 if (dim < -1) \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
970 error (#FCN ": invalid dimension argument = %d", dim + 1); \ |
20562
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
971 \ |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
972 if (arg.is_sparse_type ()) \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
973 { \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
974 if (arg.is_real_type ()) \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
975 { \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
976 SparseMatrix tmp = arg.sparse_matrix_value (); \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
977 \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
978 retval = tmp.FCN (dim); \ |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
979 } \ |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
980 else \ |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
981 { \ |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
982 SparseComplexMatrix tmp \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
983 = arg.sparse_complex_matrix_value (); \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
984 \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
985 retval = tmp.FCN (dim); \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
986 } \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
987 } \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
988 else \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
989 { \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
990 if (isnative) \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
991 { \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
992 if NATIVE_REDUCTION_1 (FCN, uint8, dim) \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
993 else if NATIVE_REDUCTION_1 (FCN, uint16, dim) \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
994 else if NATIVE_REDUCTION_1 (FCN, uint32, dim) \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
995 else if NATIVE_REDUCTION_1 (FCN, uint64, dim) \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
996 else if NATIVE_REDUCTION_1 (FCN, int8, dim) \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
997 else if NATIVE_REDUCTION_1 (FCN, int16, dim) \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
998 else if NATIVE_REDUCTION_1 (FCN, int32, dim) \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
999 else if NATIVE_REDUCTION_1 (FCN, int64, dim) \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1000 else if (arg.is_bool_type ()) \ |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1001 { \ |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1002 boolNDArray tmp = arg.bool_array_value (); \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1003 \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1004 retval = boolNDArray (tmp.BOOL_FCN (dim)); \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1005 } \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1006 else if (arg.is_char_matrix ()) \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1007 { \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1008 error (#FCN, ": invalid char type"); \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1009 } \ |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20943
diff
changeset
|
1010 else if (! isdouble && arg.is_single_type ()) \ |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1011 { \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1012 if (arg.is_complex_type ()) \ |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1013 { \ |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1014 FloatComplexNDArray tmp = \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1015 arg.float_complex_array_value (); \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1016 \ |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1017 retval = tmp.FCN (dim); \ |
20562
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1018 } \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1019 else if (arg.is_real_type ()) \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1020 { \ |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1021 FloatNDArray tmp = arg.float_array_value (); \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1022 \ |
20562
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1023 retval = tmp.FCN (dim); \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1024 } \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1025 } \ |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1026 else if (arg.is_complex_type ()) \ |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1027 { \ |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1028 ComplexNDArray tmp = arg.complex_array_value (); \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1029 \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1030 retval = tmp.FCN (dim); \ |
20562
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1031 } \ |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1032 else if (arg.is_real_type ()) \ |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1033 { \ |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1034 NDArray tmp = arg.array_value (); \ |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1035 \ |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1036 retval = tmp.FCN (dim); \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1037 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1038 else \ |
20562
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1039 { \ |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21078
diff
changeset
|
1040 err_wrong_type_arg (#FCN, arg); \ |
20562
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1041 return retval; \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1042 } \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1043 } \ |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1044 else if (arg.is_bool_type ()) \ |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1045 { \ |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1046 boolNDArray tmp = arg.bool_array_value (); \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1047 \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1048 retval = tmp.FCN (dim); \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1049 } \ |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20943
diff
changeset
|
1050 else if (! isdouble && arg.is_single_type ()) \ |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1051 { \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1052 if (arg.is_real_type ()) \ |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1053 { \ |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1054 FloatNDArray tmp = arg.float_array_value (); \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1055 \ |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1056 retval = tmp.FCN (dim); \ |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1057 } \ |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1058 else if (arg.is_complex_type ()) \ |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1059 { \ |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1060 FloatComplexNDArray tmp = \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1061 arg.float_complex_array_value (); \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1062 \ |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1063 retval = tmp.FCN (dim); \ |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1064 } \ |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1065 } \ |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1066 else if (arg.is_real_type ()) \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1067 { \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1068 NDArray tmp = arg.array_value (); \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1069 \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1070 retval = tmp.FCN (dim); \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1071 } \ |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1072 else if (arg.is_complex_type ()) \ |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1073 { \ |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1074 ComplexNDArray tmp = arg.complex_array_value (); \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1075 \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1076 retval = tmp.FCN (dim); \ |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1077 } \ |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1078 else \ |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1079 { \ |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21078
diff
changeset
|
1080 err_wrong_type_arg (#FCN, arg); \ |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1081 return retval; \ |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1082 } \ |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1083 } \ |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1084 \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1085 return retval |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1086 |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1087 #define DATA_REDUCTION(FCN) \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1088 \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1089 int nargin = args.length (); \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1090 \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1091 if (nargin < 1 || nargin > 2) \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1092 print_usage (); \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1093 \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1094 octave_value retval; \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1095 \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1096 octave_value arg = args(0); \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1097 \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1098 int dim = (nargin == 1 ? -1 : args(1).int_value (true) - 1); \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1099 \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1100 if (dim < -1) \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1101 error (#FCN ": invalid dimension argument = %d", dim + 1); \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1102 \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1103 if (arg.is_real_type ()) \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1104 { \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1105 if (arg.is_sparse_type ()) \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1106 { \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1107 SparseMatrix tmp = arg.sparse_matrix_value (); \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1108 \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1109 retval = tmp.FCN (dim); \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1110 } \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1111 else if (arg.is_single_type ()) \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1112 { \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1113 FloatNDArray tmp = arg.float_array_value (); \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1114 \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1115 retval = tmp.FCN (dim); \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1116 } \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1117 else \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1118 { \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1119 NDArray tmp = arg.array_value (); \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1120 \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1121 retval = tmp.FCN (dim); \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1122 } \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1123 } \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1124 else if (arg.is_complex_type ()) \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1125 { \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1126 if (arg.is_sparse_type ()) \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1127 { \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1128 SparseComplexMatrix tmp = arg.sparse_complex_matrix_value (); \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1129 \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1130 retval = tmp.FCN (dim); \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1131 } \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1132 else if (arg.is_single_type ()) \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1133 { \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1134 FloatComplexNDArray tmp \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1135 = arg.float_complex_array_value (); \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1136 \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1137 retval = tmp.FCN (dim); \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1138 } \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1139 else \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1140 { \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1141 ComplexNDArray tmp = arg.complex_array_value (); \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1142 \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1143 retval = tmp.FCN (dim); \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1144 } \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1145 } \ |
3723 | 1146 else \ |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1147 { \ |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21078
diff
changeset
|
1148 err_wrong_type_arg (#FCN, arg); \ |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1149 return retval; \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1150 } \ |
3723 | 1151 \ |
1152 return retval | |
1153 | |
1957 | 1154 DEFUN (cumprod, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1155 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
1156 @deftypefn {} {} cumprod (@var{x})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
1157 @deftypefnx {} {} cumprod (@var{x}, @var{dim})\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
1158 Cumulative product of elements along dimension @var{dim}.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
1159 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
1160 If @var{dim} is omitted, it defaults to the first non-singleton dimension.\n\ |
21046
8190fe6dc3fd
* data.cc (Fcumsum, Fcumprod): Provide example in docstring.
John W. Eaton <jwe@octave.org>
parents:
21041
diff
changeset
|
1161 For example:\n\ |
8190fe6dc3fd
* data.cc (Fcumsum, Fcumprod): Provide example in docstring.
John W. Eaton <jwe@octave.org>
parents:
21041
diff
changeset
|
1162 \n\ |
8190fe6dc3fd
* data.cc (Fcumsum, Fcumprod): Provide example in docstring.
John W. Eaton <jwe@octave.org>
parents:
21041
diff
changeset
|
1163 @example\n\ |
8190fe6dc3fd
* data.cc (Fcumsum, Fcumprod): Provide example in docstring.
John W. Eaton <jwe@octave.org>
parents:
21041
diff
changeset
|
1164 @group\n\ |
21053 | 1165 cumprod ([1, 2; 3, 4; 5, 6])\n\ |
21046
8190fe6dc3fd
* data.cc (Fcumsum, Fcumprod): Provide example in docstring.
John W. Eaton <jwe@octave.org>
parents:
21041
diff
changeset
|
1166 @result{} 1 2\n\ |
8190fe6dc3fd
* data.cc (Fcumsum, Fcumprod): Provide example in docstring.
John W. Eaton <jwe@octave.org>
parents:
21041
diff
changeset
|
1167 3 8\n\ |
8190fe6dc3fd
* data.cc (Fcumsum, Fcumprod): Provide example in docstring.
John W. Eaton <jwe@octave.org>
parents:
21041
diff
changeset
|
1168 15 48\n\ |
8190fe6dc3fd
* data.cc (Fcumsum, Fcumprod): Provide example in docstring.
John W. Eaton <jwe@octave.org>
parents:
21041
diff
changeset
|
1169 @end group\n\ |
8190fe6dc3fd
* data.cc (Fcumsum, Fcumprod): Provide example in docstring.
John W. Eaton <jwe@octave.org>
parents:
21041
diff
changeset
|
1170 @end example\n\ |
9163
9cb0c21e97f7
Update section 17.4 (Sums and Products) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9155
diff
changeset
|
1171 @seealso{prod, cumsum}\n\ |
3428 | 1172 @end deftypefn") |
523 | 1173 { |
3723 | 1174 DATA_REDUCTION (cumprod); |
523 | 1175 } |
1176 | |
7815
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1177 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1178 %!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
|
1179 %!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
|
1180 %!assert (cumprod ([i, 2+i, -3+2i, 4]), [i, -1+2i, -1-8i, -4-32i]) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1181 %!assert (cumprod ([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i]), [1, 2, 3; i, 4i, 9i; -1+i, -8+8i, -27+27i]) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1182 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1183 %!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
|
1184 %!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
|
1185 %!assert (cumprod (single ([i, 2+i, -3+2i, 4])), single ([i, -1+2i, -1-8i, -4-32i])) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1186 %!assert (cumprod (single ([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i])), single ([1, 2, 3; i, 4i, 9i; -1+i, -8+8i, -27+27i])) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1187 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1188 %!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
|
1189 %!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
|
1190 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1191 %!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
|
1192 %!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
|
1193 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1194 %!error cumprod () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1195 */ |
7815
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1196 |
1957 | 1197 DEFUN (cumsum, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1198 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
1199 @deftypefn {} {} cumsum (@var{x})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
1200 @deftypefnx {} {} cumsum (@var{x}, @var{dim})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
1201 @deftypefnx {} {} cumsum (@dots{}, \"native\")\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
1202 @deftypefnx {} {} cumsum (@dots{}, \"double\")\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
1203 @deftypefnx {} {} cumsum (@dots{}, \"extra\")\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
1204 Cumulative sum of elements along dimension @var{dim}.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
1205 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
1206 If @var{dim} is omitted, it defaults to the first non-singleton dimension.\n\ |
21046
8190fe6dc3fd
* data.cc (Fcumsum, Fcumprod): Provide example in docstring.
John W. Eaton <jwe@octave.org>
parents:
21041
diff
changeset
|
1207 For example:\n\ |
8190fe6dc3fd
* data.cc (Fcumsum, Fcumprod): Provide example in docstring.
John W. Eaton <jwe@octave.org>
parents:
21041
diff
changeset
|
1208 \n\ |
8190fe6dc3fd
* data.cc (Fcumsum, Fcumprod): Provide example in docstring.
John W. Eaton <jwe@octave.org>
parents:
21041
diff
changeset
|
1209 @example\n\ |
8190fe6dc3fd
* data.cc (Fcumsum, Fcumprod): Provide example in docstring.
John W. Eaton <jwe@octave.org>
parents:
21041
diff
changeset
|
1210 @group\n\ |
8190fe6dc3fd
* data.cc (Fcumsum, Fcumprod): Provide example in docstring.
John W. Eaton <jwe@octave.org>
parents:
21041
diff
changeset
|
1211 cumsum ([1, 2; 3, 4; 5, 6])\n\ |
8190fe6dc3fd
* data.cc (Fcumsum, Fcumprod): Provide example in docstring.
John W. Eaton <jwe@octave.org>
parents:
21041
diff
changeset
|
1212 @result{} 1 2\n\ |
8190fe6dc3fd
* data.cc (Fcumsum, Fcumprod): Provide example in docstring.
John W. Eaton <jwe@octave.org>
parents:
21041
diff
changeset
|
1213 4 6\n\ |
8190fe6dc3fd
* data.cc (Fcumsum, Fcumprod): Provide example in docstring.
John W. Eaton <jwe@octave.org>
parents:
21041
diff
changeset
|
1214 9 12\n\ |
8190fe6dc3fd
* data.cc (Fcumsum, Fcumprod): Provide example in docstring.
John W. Eaton <jwe@octave.org>
parents:
21041
diff
changeset
|
1215 @end group\n\ |
8190fe6dc3fd
* data.cc (Fcumsum, Fcumprod): Provide example in docstring.
John W. Eaton <jwe@octave.org>
parents:
21041
diff
changeset
|
1216 @end example\n\ |
8780
ea76466605ba
support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents:
8756
diff
changeset
|
1217 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17268
diff
changeset
|
1218 See @code{sum} for an explanation of the optional parameters\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17268
diff
changeset
|
1219 @qcode{\"native\"}, @qcode{\"double\"}, and @qcode{\"extra\"}.\n\ |
9163
9cb0c21e97f7
Update section 17.4 (Sums and Products) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9155
diff
changeset
|
1220 @seealso{sum, cumprod}\n\ |
3428 | 1221 @end deftypefn") |
523 | 1222 { |
9721
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1223 int nargin = args.length (); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1224 |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1225 bool isnative = false; |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1226 bool isdouble = false; |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1227 |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1228 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
|
1229 { |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1230 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
|
1231 |
19743
67f2c76f9f4d
Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents:
19739
diff
changeset
|
1232 if (str == "native") |
67f2c76f9f4d
Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents:
19739
diff
changeset
|
1233 isnative = true; |
67f2c76f9f4d
Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents:
19739
diff
changeset
|
1234 else if (str == "double") |
67f2c76f9f4d
Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents:
19739
diff
changeset
|
1235 isdouble = true; |
67f2c76f9f4d
Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents:
19739
diff
changeset
|
1236 else |
67f2c76f9f4d
Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents:
19739
diff
changeset
|
1237 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
|
1238 |
21062
d9c1884d1aaa
maint: Eliminate space between variable and decrement '--' operator.
Rik <rik@octave.org>
parents:
21055
diff
changeset
|
1239 nargin--; |
9721
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1240 } |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1241 |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1242 if (nargin < 1 || nargin > 2) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1243 print_usage (); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1244 |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1245 int dim = -1; |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1246 if (nargin == 2) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1247 { |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1248 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
|
1249 if (dim < 0) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1250 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
|
1251 } |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1252 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1253 octave_value retval; |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1254 octave_value arg = args(0); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1255 |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1256 switch (arg.builtin_type ()) |
9721
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1257 { |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1258 case btyp_double: |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1259 if (arg.is_sparse_type ()) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1260 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
|
1261 else |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1262 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
|
1263 break; |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1264 case btyp_complex: |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1265 if (arg.is_sparse_type ()) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1266 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
|
1267 else |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1268 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
|
1269 break; |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1270 case btyp_float: |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1271 if (isdouble) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1272 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
|
1273 else |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1274 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
|
1275 break; |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1276 case btyp_float_complex: |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1277 if (isdouble) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1278 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
|
1279 else |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1280 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
|
1281 break; |
9721
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1282 |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1283 #define MAKE_INT_BRANCH(X) \ |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1284 case btyp_ ## X: \ |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1285 if (isnative) \ |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1286 retval = arg.X ## _array_value ().cumsum (dim); \ |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1287 else \ |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1288 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
|
1289 break; |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1290 |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1291 MAKE_INT_BRANCH (int8); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1292 MAKE_INT_BRANCH (int16); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1293 MAKE_INT_BRANCH (int32); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1294 MAKE_INT_BRANCH (int64); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1295 MAKE_INT_BRANCH (uint8); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1296 MAKE_INT_BRANCH (uint16); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1297 MAKE_INT_BRANCH (uint32); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1298 MAKE_INT_BRANCH (uint64); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1299 |
9721
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1300 #undef MAKE_INT_BRANCH |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1301 |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1302 case btyp_bool: |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1303 if (arg.is_sparse_type ()) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1304 { |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1305 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
|
1306 if (isnative) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1307 retval = cs != 0.0; |
20562
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1308 else |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1309 retval = cs; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1310 } |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1311 else |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1312 { |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1313 NDArray cs = arg.bool_array_value ().cumsum (dim); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1314 if (isnative) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1315 retval = cs != 0.0; |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1316 else |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1317 retval = cs; |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1318 } |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1319 break; |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1320 |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1321 default: |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21078
diff
changeset
|
1322 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
|
1323 } |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1324 |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1325 return retval; |
523 | 1326 } |
1327 | |
7815
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1328 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1329 %!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
|
1330 %!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
|
1331 %!assert (cumsum ([i, 2+i, -3+2i, 4]), [i, 2+2i, -1+4i, 3+4i]) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1332 %!assert (cumsum ([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i]), [1, 2, 3; 1+i, 2+2i, 3+3i; 2+2i, 4+4i, 6+6i]) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1333 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1334 %!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
|
1335 %!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
|
1336 %!assert (cumsum (single ([i, 2+i, -3+2i, 4])), single ([i, 2+2i, -1+4i, 3+4i])) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1337 %!assert (cumsum (single ([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i])), single ([1, 2, 3; 1+i, 2+2i, 3+3i; 2+2i, 4+4i, 6+6i])) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1338 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1339 %!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
|
1340 %!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
|
1341 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1342 %!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
|
1343 %!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
|
1344 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1345 %!error cumsum () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1346 */ |
7815
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1347 |
1957 | 1348 DEFUN (diag, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1349 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
1350 @deftypefn {} {@var{M} =} diag (@var{v})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
1351 @deftypefnx {} {@var{M} =} diag (@var{v}, @var{k})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
1352 @deftypefnx {} {@var{M} =} diag (@var{v}, @var{m}, @var{n})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
1353 @deftypefnx {} {@var{v} =} diag (@var{M})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
1354 @deftypefnx {} {@var{v} =} diag (@var{M}, @var{k})\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
1355 Return a diagonal matrix with vector @var{v} on diagonal @var{k}.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
1356 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
1357 The second argument is optional. If it is positive, the vector is placed on\n\ |
19038
9e3c35d934ab
doc: Periodic spell check of documentation.
Rik <rik@octave.org>
parents:
18873
diff
changeset
|
1358 the @var{k}-th superdiagonal. If it is negative, it is placed on the\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
1359 @var{-k}-th subdiagonal. The default value of @var{k} is 0, and the vector\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
1360 is placed on the main diagonal. For example:\n\ |
3369 | 1361 \n\ |
1362 @example\n\ | |
1363 @group\n\ | |
1364 diag ([1, 2, 3], 1)\n\ | |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
1365 @result{} 0 1 0 0\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
1366 0 0 2 0\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
1367 0 0 0 3\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
1368 0 0 0 0\n\ |
3369 | 1369 @end group\n\ |
1370 @end example\n\ | |
6772 | 1371 \n\ |
1372 @noindent\n\ | |
12571
bed932910eb9
Add documentation for 3-input form of diag(). Add new tests.
Rik <octave@nomad.inbox5.com>
parents:
12570
diff
changeset
|
1373 The 3-input form returns a diagonal matrix with vector @var{v} on the main\n\ |
bed932910eb9
Add documentation for 3-input form of diag(). Add new tests.
Rik <octave@nomad.inbox5.com>
parents:
12570
diff
changeset
|
1374 diagonal and the resulting matrix being of size @var{m} rows x @var{n}\n\ |
bed932910eb9
Add documentation for 3-input form of diag(). Add new tests.
Rik <octave@nomad.inbox5.com>
parents:
12570
diff
changeset
|
1375 columns.\n\ |
bed932910eb9
Add documentation for 3-input form of diag(). Add new tests.
Rik <octave@nomad.inbox5.com>
parents:
12570
diff
changeset
|
1376 \n\ |
6772 | 1377 Given a matrix argument, instead of a vector, @code{diag} extracts the\n\ |
6774 | 1378 @var{k}-th diagonal of the matrix.\n\ |
3369 | 1379 @end deftypefn") |
523 | 1380 { |
1381 int nargin = args.length (); | |
1382 | |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1383 if (nargin < 1 || nargin > 3) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1384 print_usage (); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1385 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1386 octave_value retval; |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1387 |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1388 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
|
1389 retval = args(0).diag (); |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1390 else if (nargin == 2) |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7618
diff
changeset
|
1391 { |
21041
63374982750b
Usage of corresponding value extractor for octave_idx_type. Improves support
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
21014
diff
changeset
|
1392 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
|
1393 |
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
1394 retval = args(0).diag (k); |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7618
diff
changeset
|
1395 } |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1396 else |
12570
1a93988610a3
Reverse changset cc8ccdfec424. Restore 3-input form of diag().
Rik <octave@nomad.inbox5.com>
parents:
12567
diff
changeset
|
1397 { |
1a93988610a3
Reverse changset cc8ccdfec424. Restore 3-input form of diag().
Rik <octave@nomad.inbox5.com>
parents:
12567
diff
changeset
|
1398 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
|
1399 |
20980
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1400 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
|
1401 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
|
1402 |
21041
63374982750b
Usage of corresponding value extractor for octave_idx_type. Improves support
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
21014
diff
changeset
|
1403 octave_idx_type m = args(1).xidx_type_value ("diag: invalid dimensions"); |
63374982750b
Usage of corresponding value extractor for octave_idx_type. Improves support
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
21014
diff
changeset
|
1404 octave_idx_type n = args(2).xidx_type_value ("diag: invalid dimensions"); |
20980
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1405 |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1406 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
|
1407 } |
523 | 1408 |
1409 return retval; | |
1410 } | |
1411 | |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1412 /* |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1413 |
14843
7d4f87c75dbb
data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents:
14635
diff
changeset
|
1414 %!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
|
1415 %!assert (diag ([1; 2; 3], 1), [0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0]) |
7d4f87c75dbb
data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents:
14635
diff
changeset
|
1416 %!assert (diag ([1; 2; 3], 2), [0, 0, 1, 0, 0; 0, 0, 0, 2, 0; 0, 0, 0, 0, 3; 0, 0, 0, 0, 0; 0, 0, 0, 0, 0]) |
7d4f87c75dbb
data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents:
14635
diff
changeset
|
1417 %!assert (diag ([1; 2; 3],-1), [0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0]) |
7d4f87c75dbb
data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents:
14635
diff
changeset
|
1418 %!assert (diag ([1; 2; 3],-2), [0, 0, 0, 0, 0; 0, 0, 0, 0, 0; 1, 0, 0, 0, 0; 0, 2, 0, 0, 0; 0, 0, 3, 0, 0]) |
7d4f87c75dbb
data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents:
14635
diff
changeset
|
1419 |
7d4f87c75dbb
data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents:
14635
diff
changeset
|
1420 %!assert (diag ([1, 0, 0; 0, 2, 0; 0, 0, 3]), [1; 2; 3]) |
7d4f87c75dbb
data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents:
14635
diff
changeset
|
1421 %!assert (diag ([0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0], 1), [1; 2; 3]) |
7d4f87c75dbb
data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents:
14635
diff
changeset
|
1422 %!assert (diag ([0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0], -1), [1; 2; 3]) |
7d4f87c75dbb
data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents:
14635
diff
changeset
|
1423 %!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
|
1424 %!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
|
1425 |
7d4f87c75dbb
data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents:
14635
diff
changeset
|
1426 %!assert (full (diag (single ([1; 2; 3]))), single ([1, 0, 0; 0, 2, 0; 0, 0, 3])) |
7d4f87c75dbb
data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents:
14635
diff
changeset
|
1427 %!assert (diag (single ([1; 2; 3]), 1), single ([0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0])) |
7d4f87c75dbb
data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents:
14635
diff
changeset
|
1428 %!assert (diag (single ([1; 2; 3]), 2), single ([0, 0, 1, 0, 0; 0, 0, 0, 2, 0; 0, 0, 0, 0, 3; 0, 0, 0, 0, 0; 0, 0, 0, 0, 0])) |
7d4f87c75dbb
data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents:
14635
diff
changeset
|
1429 %!assert (diag (single ([1; 2; 3]),-1), single ([0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0])) |
7d4f87c75dbb
data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents:
14635
diff
changeset
|
1430 %!assert (diag (single ([1; 2; 3]),-2), single ([0, 0, 0, 0, 0; 0, 0, 0, 0, 0; 1, 0, 0, 0, 0; 0, 2, 0, 0, 0; 0, 0, 3, 0, 0])) |
7d4f87c75dbb
data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents:
14635
diff
changeset
|
1431 |
7d4f87c75dbb
data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents:
14635
diff
changeset
|
1432 %!assert (diag (single ([1, 0, 0; 0, 2, 0; 0, 0, 3])), single ([1; 2; 3])) |
7d4f87c75dbb
data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents:
14635
diff
changeset
|
1433 %!assert (diag (single ([0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0]), 1), single ([1; 2; 3])) |
7d4f87c75dbb
data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents:
14635
diff
changeset
|
1434 %!assert (diag (single ([0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0]), -1), single ([1; 2; 3])) |
7d4f87c75dbb
data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents:
14635
diff
changeset
|
1435 |
7d4f87c75dbb
data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents:
14635
diff
changeset
|
1436 %!assert (diag (int8 ([1; 2; 3])), int8 ([1, 0, 0; 0, 2, 0; 0, 0, 3])) |
7d4f87c75dbb
data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents:
14635
diff
changeset
|
1437 %!assert (diag (int8 ([1; 2; 3]), 1), int8 ([0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0])) |
7d4f87c75dbb
data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents:
14635
diff
changeset
|
1438 %!assert (diag (int8 ([1; 2; 3]), 2), int8 ([0, 0, 1, 0, 0; 0, 0, 0, 2, 0; 0, 0, 0, 0, 3; 0, 0, 0, 0, 0; 0, 0, 0, 0, 0])) |
7d4f87c75dbb
data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents:
14635
diff
changeset
|
1439 %!assert (diag (int8 ([1; 2; 3]),-1), int8 ([0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0])) |
7d4f87c75dbb
data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents:
14635
diff
changeset
|
1440 %!assert (diag (int8 ([1; 2; 3]),-2), int8 ([0, 0, 0, 0, 0; 0, 0, 0, 0, 0; 1, 0, 0, 0, 0; 0, 2, 0, 0, 0; 0, 0, 3, 0, 0])) |
7d4f87c75dbb
data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents:
14635
diff
changeset
|
1441 |
7d4f87c75dbb
data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents:
14635
diff
changeset
|
1442 %!assert (diag (int8 ([1, 0, 0; 0, 2, 0; 0, 0, 3])), int8 ([1; 2; 3])) |
7d4f87c75dbb
data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents:
14635
diff
changeset
|
1443 %!assert (diag (int8 ([0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0]), 1), int8 ([1; 2; 3])) |
7d4f87c75dbb
data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents:
14635
diff
changeset
|
1444 %!assert (diag (int8 ([0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0]), -1), int8 ([1; 2; 3])) |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1445 |
15428
fd5c0159b588
Fix diag handling of diagvectors (bug #37411)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14567
diff
changeset
|
1446 ## bug #37411 |
fd5c0159b588
Fix diag handling of diagvectors (bug #37411)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14567
diff
changeset
|
1447 %!assert (diag (diag ([5, 2, 3])(:,1)), diag([5 0 0 ])) |
fd5c0159b588
Fix diag handling of diagvectors (bug #37411)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14567
diff
changeset
|
1448 %!assert (diag (diag ([5, 2, 3])(:,1), 2), [0 0 5 0 0; zeros(4, 5)]) |
fd5c0159b588
Fix diag handling of diagvectors (bug #37411)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14567
diff
changeset
|
1449 %!assert (diag (diag ([5, 2, 3])(:,1), -2), [[0 0 5 0 0]', zeros(5, 4)]) |
fd5c0159b588
Fix diag handling of diagvectors (bug #37411)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14567
diff
changeset
|
1450 |
14490
3959f3f81e33
Initialise memory in non-square diag call (bug #35946)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14171
diff
changeset
|
1451 ## 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
|
1452 %!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]) |
14567
5bb5fcffa29d
correctly fill cell arrays for three-arg diag function calls
John W. Eaton <jwe@octave.org>
parents:
14490
diff
changeset
|
1453 %!assert (diag (1, 2, 3), [1,0,0; 0,0,0]); |
5bb5fcffa29d
correctly fill cell arrays for three-arg diag function calls
John W. Eaton <jwe@octave.org>
parents:
14490
diff
changeset
|
1454 %!assert (diag ({1}, 2, 3), {1,[],[]; [],[],[]}); |
5bb5fcffa29d
correctly fill cell arrays for three-arg diag function calls
John W. Eaton <jwe@octave.org>
parents:
14490
diff
changeset
|
1455 %!assert (diag ({1,2}, 3, 4), {1,[],[],[]; [],2,[],[]; [],[],[],[]}); |
14490
3959f3f81e33
Initialise memory in non-square diag call (bug #35946)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14171
diff
changeset
|
1456 |
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
|
1457 ## 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
|
1458 %!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
|
1459 %!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
|
1460 %!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
|
1461 |
12571
bed932910eb9
Add documentation for 3-input form of diag(). Add new tests.
Rik <octave@nomad.inbox5.com>
parents:
12570
diff
changeset
|
1462 %% Test input validation |
14491
5bd9e47e9277
maint: periodic merge of stable to default
Jordi Gutiérrez Hermoso <jordigh@octave.org>
diff
changeset
|
1463 %!error <Invalid call to diag> diag () |
5bd9e47e9277
maint: periodic merge of stable to default
Jordi Gutiérrez Hermoso <jordigh@octave.org>
diff
changeset
|
1464 %!error <Invalid call to diag> diag (1,2,3,4) |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1465 %!error diag (ones (2), 3, 3) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1466 %!error diag (1:3, -4, 3) |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1467 |
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
|
1468 %!assert (diag (1, 3, 3), diag ([1, 0, 0])) |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14521
diff
changeset
|
1469 %!assert (diag (i, 3, 3), diag ([i, 0, 0])) |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14521
diff
changeset
|
1470 %!assert (diag (single (1), 3, 3), diag ([single(1), 0, 0])) |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14521
diff
changeset
|
1471 %!assert (diag (single (i), 3, 3), diag ([single(i), 0, 0])) |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14521
diff
changeset
|
1472 %!assert (diag ([1, 2], 3, 3), diag ([1, 2, 0])) |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14521
diff
changeset
|
1473 %!assert (diag ([1, 2]*i, 3, 3), diag ([1, 2, 0]*i)) |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14521
diff
changeset
|
1474 %!assert (diag (single ([1, 2]), 3, 3), diag (single ([1, 2, 0]))) |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14521
diff
changeset
|
1475 %!assert (diag (single ([1, 2]*i), 3, 3), diag (single ([1, 2, 0]*i))) |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14521
diff
changeset
|
1476 */ |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1477 |
1957 | 1478 DEFUN (prod, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1479 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
1480 @deftypefn {} {} prod (@var{x})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
1481 @deftypefnx {} {} prod (@var{x}, @var{dim})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
1482 @deftypefnx {} {} prod (@dots{}, \"native\")\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
1483 @deftypefnx {} {} prod (@dots{}, \"double\")\n\ |
18725
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18679
diff
changeset
|
1484 Product of elements along dimension @var{dim}.\n\ |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18679
diff
changeset
|
1485 \n\ |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18679
diff
changeset
|
1486 If @var{dim} is omitted, it defaults to the first non-singleton dimension.\n\ |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18679
diff
changeset
|
1487 \n\ |
18812
9ac2357f19bc
doc: Replace "non-zero" with "nonzero" to match existing usage.
Rik <rik@octave.org>
parents:
18811
diff
changeset
|
1488 The optional @qcode{\"type\"} input determines the class of the variable\n\ |
9ac2357f19bc
doc: Replace "non-zero" with "nonzero" to match existing usage.
Rik <rik@octave.org>
parents:
18811
diff
changeset
|
1489 used for calculations. If the argument @qcode{\"native\"} is given, then\n\ |
9ac2357f19bc
doc: Replace "non-zero" with "nonzero" to match existing usage.
Rik <rik@octave.org>
parents:
18811
diff
changeset
|
1490 the operation is performed in the same type as the original argument, rather\n\ |
9ac2357f19bc
doc: Replace "non-zero" with "nonzero" to match existing usage.
Rik <rik@octave.org>
parents:
18811
diff
changeset
|
1491 than the default double type.\n\ |
18725
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18679
diff
changeset
|
1492 \n\ |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18679
diff
changeset
|
1493 For example:\n\ |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18679
diff
changeset
|
1494 \n\ |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18679
diff
changeset
|
1495 @example\n\ |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18679
diff
changeset
|
1496 @group\n\ |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18679
diff
changeset
|
1497 prod ([true, true])\n\ |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18679
diff
changeset
|
1498 @result{} 1\n\ |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18679
diff
changeset
|
1499 prod ([true, true], \"native\")\n\ |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18679
diff
changeset
|
1500 @result{} true\n\ |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18679
diff
changeset
|
1501 @end group\n\ |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18679
diff
changeset
|
1502 @end example\n\ |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18679
diff
changeset
|
1503 \n\ |
18812
9ac2357f19bc
doc: Replace "non-zero" with "nonzero" to match existing usage.
Rik <rik@octave.org>
parents:
18811
diff
changeset
|
1504 On the contrary, if @qcode{\"double\"} is given, the operation is performed\n\ |
9ac2357f19bc
doc: Replace "non-zero" with "nonzero" to match existing usage.
Rik <rik@octave.org>
parents:
18811
diff
changeset
|
1505 in double precision even for single precision inputs.\n\ |
9163
9cb0c21e97f7
Update section 17.4 (Sums and Products) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9155
diff
changeset
|
1506 @seealso{cumprod, sum}\n\ |
3428 | 1507 @end deftypefn") |
523 | 1508 { |
18725
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18679
diff
changeset
|
1509 int nargin = args.length (); |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18679
diff
changeset
|
1510 |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18679
diff
changeset
|
1511 bool isnative = false; |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18679
diff
changeset
|
1512 bool isdouble = false; |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18679
diff
changeset
|
1513 |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18679
diff
changeset
|
1514 if (nargin > 1 && args(nargin - 1).is_string ()) |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18679
diff
changeset
|
1515 { |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18679
diff
changeset
|
1516 std::string str = args(nargin - 1).string_value (); |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18679
diff
changeset
|
1517 |
19743
67f2c76f9f4d
Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents:
19739
diff
changeset
|
1518 if (str == "native") |
67f2c76f9f4d
Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents:
19739
diff
changeset
|
1519 isnative = true; |
67f2c76f9f4d
Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents:
19739
diff
changeset
|
1520 else if (str == "double") |
67f2c76f9f4d
Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents:
19739
diff
changeset
|
1521 isdouble = true; |
67f2c76f9f4d
Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents:
19739
diff
changeset
|
1522 else |
67f2c76f9f4d
Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents:
19739
diff
changeset
|
1523 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
|
1524 |
21062
d9c1884d1aaa
maint: Eliminate space between variable and decrement '--' operator.
Rik <rik@octave.org>
parents:
21055
diff
changeset
|
1525 nargin--; |
18725
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18679
diff
changeset
|
1526 } |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18679
diff
changeset
|
1527 |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1528 if (nargin < 1 || nargin > 2) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1529 print_usage (); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1530 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1531 octave_value retval; |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
1532 |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1533 octave_value arg = args(0); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1534 |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1535 int dim = -1; |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1536 if (nargin == 2) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1537 { |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1538 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
|
1539 if (dim < 0) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1540 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
|
1541 } |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1542 |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1543 switch (arg.builtin_type ()) |
18725
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18679
diff
changeset
|
1544 { |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1545 case btyp_double: |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1546 if (arg.is_sparse_type ()) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1547 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
|
1548 else |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1549 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
|
1550 break; |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1551 case btyp_complex: |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1552 if (arg.is_sparse_type ()) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1553 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
|
1554 else |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1555 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
|
1556 break; |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1557 case btyp_float: |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1558 if (isdouble) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1559 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
|
1560 else |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1561 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
|
1562 break; |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1563 case btyp_float_complex: |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1564 if (isdouble) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1565 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
|
1566 else |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1567 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
|
1568 break; |
18725
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18679
diff
changeset
|
1569 |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18679
diff
changeset
|
1570 #define MAKE_INT_BRANCH(X) \ |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1571 case btyp_ ## X: \ |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1572 if (isnative) \ |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1573 retval = arg.X ## _array_value ().prod (dim); \ |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1574 else \ |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1575 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
|
1576 break; |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1577 |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1578 MAKE_INT_BRANCH (int8); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1579 MAKE_INT_BRANCH (int16); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1580 MAKE_INT_BRANCH (int32); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1581 MAKE_INT_BRANCH (int64); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1582 MAKE_INT_BRANCH (uint8); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1583 MAKE_INT_BRANCH (uint16); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1584 MAKE_INT_BRANCH (uint32); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1585 MAKE_INT_BRANCH (uint64); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1586 |
18725
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18679
diff
changeset
|
1587 #undef MAKE_INT_BRANCH |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18679
diff
changeset
|
1588 |
20562
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1589 // GAGME: Accursed Matlab compatibility... |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1590 case btyp_char: |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1591 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
|
1592 break; |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1593 |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1594 case btyp_bool: |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1595 if (arg.is_sparse_type ()) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1596 { |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1597 if (isnative) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1598 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
|
1599 else |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1600 retval = arg.sparse_matrix_value ().prod (dim); |
18725
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18679
diff
changeset
|
1601 } |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1602 else if (isnative) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1603 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
|
1604 else |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1605 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
|
1606 break; |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1607 |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
1608 default: |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21078
diff
changeset
|
1609 err_wrong_type_arg ("prod", arg); |
18725
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18679
diff
changeset
|
1610 } |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18679
diff
changeset
|
1611 |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18679
diff
changeset
|
1612 return retval; |
523 | 1613 } |
1614 | |
7815
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1615 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1616 %!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
|
1617 %!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
|
1618 %!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
|
1619 %!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
|
1620 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1621 %!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
|
1622 %!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
|
1623 %!assert (prod (single ([i, 2+i, -3+2i, 4])), single (-4 - 32i)) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1624 %!assert (prod (single ([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i])), single ([-1+i, -8+8i, -27+27i])) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1625 |
18725
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18679
diff
changeset
|
1626 %% Test sparse |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18679
diff
changeset
|
1627 %!assert (prod (sparse ([1, 2, 3])), sparse (6)) |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18679
diff
changeset
|
1628 %!assert (prod (sparse ([-1; -2; -3])), sparse (-6)) |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18679
diff
changeset
|
1629 ## Commented out until bug #42290 is fixed |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18679
diff
changeset
|
1630 #%!assert (prod (sparse ([i, 2+i, -3+2i, 4])), sparse (-4 - 32i)) |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18679
diff
changeset
|
1631 #%!assert (prod (sparse ([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i])), sparse ([-1+i, -8+8i, -27+27i])) |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18679
diff
changeset
|
1632 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1633 %!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
|
1634 %!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
|
1635 %!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
|
1636 %!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
|
1637 %!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
|
1638 %!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
|
1639 %!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
|
1640 %!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
|
1641 %!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
|
1642 %!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
|
1643 %!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
|
1644 %!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
|
1645 %!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
|
1646 %!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
|
1647 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1648 %!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
|
1649 %!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
|
1650 %!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
|
1651 %!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
|
1652 %!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
|
1653 %!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
|
1654 %!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
|
1655 %!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
|
1656 %!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
|
1657 %!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
|
1658 %!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
|
1659 %!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
|
1660 %!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
|
1661 %!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
|
1662 |
18725
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18679
diff
changeset
|
1663 %% Test "double" type argument |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18679
diff
changeset
|
1664 %!assert (prod (single ([1, 2, 3]), "double"), 6) |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18679
diff
changeset
|
1665 %!assert (prod (single ([-1; -2; -3]), "double"), -6) |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18679
diff
changeset
|
1666 %!assert (prod (single ([i, 2+i, -3+2i, 4]), "double"), -4 - 32i) |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18679
diff
changeset
|
1667 %!assert (prod (single ([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i]), "double"), [-1+i, -8+8i, -27+27i]) |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18679
diff
changeset
|
1668 |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18679
diff
changeset
|
1669 %% Test "native" type argument |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18679
diff
changeset
|
1670 %!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
|
1671 %!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
|
1672 %!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
|
1673 %!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
|
1674 %!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
|
1675 %!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
|
1676 |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18679
diff
changeset
|
1677 %% Test input validation |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1678 %!error prod () |
18725
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18679
diff
changeset
|
1679 %!error prod (1,2,3) |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18679
diff
changeset
|
1680 %!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
|
1681 */ |
7815
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1682 |
10758
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1683 static bool |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1684 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
|
1685 { |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1686 int n_args = args.length (); |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1687 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
|
1688 if (args(i).numel () != 1) |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1689 return false; |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1690 |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1691 return true; |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1692 } |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1693 |
10533
f094ac9bc93e
reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents:
10498
diff
changeset
|
1694 template <class TYPE, class T> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
1695 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
|
1696 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
|
1697 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
|
1698 int dim) |
f094ac9bc93e
reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents:
10498
diff
changeset
|
1699 { |
f094ac9bc93e
reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents:
10498
diff
changeset
|
1700 int n_args = args.length (); |
10758
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1701 if (! (equal_types<T, char>::value |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1702 || equal_types<T, octave_value>::value) |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1703 && 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
|
1704 { |
10758
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1705 // Optimize all scalars case. |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1706 dim_vector dv (1, 1); |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1707 if (dim == -1 || dim == -2) |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1708 dim = -dim - 1; |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1709 else if (dim >= 2) |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1710 dv.resize (dim+1, 1); |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1711 dv(dim) = n_args; |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1712 |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1713 result.clear (dv); |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1714 |
20562
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1715 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
|
1716 { |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1717 octave_quit (); |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1718 |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1719 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
|
1720 } |
10533
f094ac9bc93e
reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents:
10498
diff
changeset
|
1721 } |
10758
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1722 else |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1723 { |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1724 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
|
1725 |
20562
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1726 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
|
1727 { |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1728 octave_quit (); |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1729 |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1730 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
|
1731 } |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1732 |
20562
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1733 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
|
1734 } |
10533
f094ac9bc93e
reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents:
10498
diff
changeset
|
1735 } |
f094ac9bc93e
reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents:
10498
diff
changeset
|
1736 |
f094ac9bc93e
reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents:
10498
diff
changeset
|
1737 template <class TYPE, class T> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
1738 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
|
1739 single_type_concat (Sparse<T>& result, |
10498
8615b55b5caf
fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents:
10436
diff
changeset
|
1740 const octave_value_list& args, |
8615b55b5caf
fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents:
10436
diff
changeset
|
1741 int dim) |
8615b55b5caf
fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents:
10436
diff
changeset
|
1742 { |
10533
f094ac9bc93e
reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents:
10498
diff
changeset
|
1743 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
|
1744 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
|
1745 |
20562
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1746 for (int j = 0; j < n_args; j++) |
10498
8615b55b5caf
fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents:
10436
diff
changeset
|
1747 { |
8615b55b5caf
fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents:
10436
diff
changeset
|
1748 octave_quit (); |
8615b55b5caf
fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents:
10436
diff
changeset
|
1749 |
10716
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1750 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
|
1751 } |
10533
f094ac9bc93e
reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents:
10498
diff
changeset
|
1752 |
20562
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1753 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
|
1754 } |
8615b55b5caf
fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents:
10436
diff
changeset
|
1755 |
10533
f094ac9bc93e
reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents:
10498
diff
changeset
|
1756 // Dispatcher. |
10498
8615b55b5caf
fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents:
10436
diff
changeset
|
1757 template<class TYPE> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
1758 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
|
1759 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
|
1760 { |
10533
f094ac9bc93e
reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents:
10498
diff
changeset
|
1761 TYPE result; |
f094ac9bc93e
reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents:
10498
diff
changeset
|
1762 |
f094ac9bc93e
reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents:
10498
diff
changeset
|
1763 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
|
1764 |
8615b55b5caf
fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents:
10436
diff
changeset
|
1765 return result; |
8615b55b5caf
fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents:
10436
diff
changeset
|
1766 } |
8615b55b5caf
fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents:
10436
diff
changeset
|
1767 |
10758
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1768 template<class MAP> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
1769 static void |
10758
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1770 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
|
1771 const octave_value_list& args, |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1772 int dim) |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1773 { |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1774 int n_args = args.length (); |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1775 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
|
1776 |
20562
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1777 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
|
1778 { |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1779 octave_quit (); |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1780 |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1781 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
|
1782 } |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1783 |
20562
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1784 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
|
1785 } |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1786 |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1787 static octave_map |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1788 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
|
1789 int dim) |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1790 { |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1791 octave_map result; |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1792 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
|
1793 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
|
1794 else |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1795 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
|
1796 |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1797 return result; |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1798 } |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1799 |
4824 | 1800 static octave_value |
13294
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1801 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
|
1802 { |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1803 octave_value retval; |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1804 |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1805 // 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
|
1806 // 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
|
1807 // type. |
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 std::string cname = ov.class_name (); |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1810 |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1811 octave_value fcn = symbol_table::find_method (dtype, cname); |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1812 |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1813 if (fcn.is_defined ()) |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1814 { |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20726
diff
changeset
|
1815 octave_value_list result; |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20726
diff
changeset
|
1816 |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20726
diff
changeset
|
1817 try |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20726
diff
changeset
|
1818 { |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20726
diff
changeset
|
1819 result = fcn.do_multi_index_op (1, octave_value_list (1, ov)); |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20726
diff
changeset
|
1820 } |
20785
b6f2909e7f94
always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1821 catch (octave_execution_exception& e) |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20726
diff
changeset
|
1822 { |
20756
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
1823 error (e, "conversion from %s to %s failed", dtype.c_str (), |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20726
diff
changeset
|
1824 cname.c_str ()); |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20726
diff
changeset
|
1825 } |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20726
diff
changeset
|
1826 |
20980
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1827 if (result.length () == 0) |
13294
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1828 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
|
1829 cname.c_str ()); |
20980
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1830 |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1831 retval = result(0); |
13294
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1832 } |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1833 else |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1834 { |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1835 // 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
|
1836 // dispatch type. |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1837 |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1838 fcn = symbol_table::find_method (dtype, dtype); |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1839 |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
1840 if (! fcn.is_defined ()) |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
1841 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
|
1842 |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
1843 octave_value_list result; |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
1844 |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
1845 try |
13294
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1846 { |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
1847 result = fcn.do_multi_index_op (1, octave_value_list (1, ov)); |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
1848 } |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
1849 catch (octave_execution_exception& e) |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
1850 { |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
1851 error (e, "%s constructor failed for %s argument", dtype.c_str (), |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
1852 cname.c_str ()); |
13294
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1853 } |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
1854 |
20980
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1855 if (result.length () == 0) |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
1856 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
|
1857 cname.c_str ()); |
20980
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1858 |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1859 retval = result(0); |
13294
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1860 } |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1861 |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1862 return retval; |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1863 } |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1864 |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1865 octave_value |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1866 do_class_concat (const octave_value_list& ovl, std::string cattype, int dim) |
4806 | 1867 { |
1868 octave_value retval; | |
1869 | |
13294
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1870 // Get dominant type for list |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1871 |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1872 std::string dtype = get_dispatch_type (ovl); |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1873 |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1874 octave_value fcn = symbol_table::find_method (cattype, dtype); |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1875 |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1876 if (fcn.is_defined ()) |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1877 { |
20726
25d676f9619c
Preface error() messages with name of function when possible.
Rik <rik@octave.org>
parents:
20720
diff
changeset
|
1878 // 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
|
1879 |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20726
diff
changeset
|
1880 octave_value_list tmp2; |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20726
diff
changeset
|
1881 |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20726
diff
changeset
|
1882 try |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20726
diff
changeset
|
1883 { |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20726
diff
changeset
|
1884 tmp2 = fcn.do_multi_index_op (1, ovl); |
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20726
diff
changeset
|
1885 } |
20785
b6f2909e7f94
always throw exception after debugging with debug_on_error
John W. Eaton <jwe@octave.org>
parents:
20756
diff
changeset
|
1886 catch (octave_execution_exception& e) |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20726
diff
changeset
|
1887 { |
20756
200ae1d650b7
propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents:
20741
diff
changeset
|
1888 error (e, "%s/%s method failed", dtype.c_str (), cattype.c_str ()); |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20726
diff
changeset
|
1889 } |
13294
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1890 |
20980
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1891 if (tmp2.length () == 0) |
20741
a5ab31b52ae8
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20726
diff
changeset
|
1892 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
|
1893 cattype.c_str ()); |
20980
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1894 |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
1895 retval = tmp2(0); |
13294
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1896 } |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1897 else |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1898 { |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1899 // 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
|
1900 // 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
|
1901 // default operation for octave_class values. |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1902 |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1903 octave_idx_type j = 0; |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1904 octave_idx_type len = ovl.length (); |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1905 octave_value_list tmp (len, octave_value ()); |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1906 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
|
1907 { |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1908 octave_value elt = ovl(k); |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1909 |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1910 std::string t1_type = elt.class_name (); |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1911 |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1912 if (t1_type == dtype) |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1913 tmp(j++) = elt; |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1914 else if (elt.is_object () || ! elt.is_empty ()) |
20562
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
1915 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
|
1916 } |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1917 |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1918 tmp.resize (j); |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1919 |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1920 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
|
1921 |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1922 std::string cname = tmp(0).class_name (); |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1923 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
|
1924 |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1925 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
|
1926 } |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1927 |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1928 return retval; |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1929 } |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1930 |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1931 static octave_value |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1932 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
|
1933 { |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1934 octave_value retval; |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1935 |
20811 | 1936 // We may need to convert elements of the list to cells, so make a copy. |
1937 // This should be efficient, it is done mostly by incrementing reference | |
1938 // counts. | |
13294
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1939 octave_value_list args = xargs; |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1940 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
1941 int n_args = args.length (); |
4806 | 1942 |
10716
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1943 if (n_args == 0) |
5714 | 1944 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
|
1945 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
|
1946 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
|
1947 else if (n_args > 1) |
4824 | 1948 { |
13294
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1949 std::string result_type; |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1950 |
19399
2304ddfd736f
Restore warning Octave:num-to-str missing since 3.2.4 (bug #43814).
Rik <rik@octave.org>
parents:
18869
diff
changeset
|
1951 bool all_strings_p = true; |
13294
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1952 bool all_sq_strings_p = true; |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1953 bool all_dq_strings_p = true; |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1954 bool all_real_p = true; |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1955 bool all_cmplx_p = true; |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1956 bool any_sparse_p = false; |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1957 bool any_cell_p = false; |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1958 bool any_class_p = false; |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1959 |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1960 bool first_elem_is_struct = false; |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1961 |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1962 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
|
1963 { |
13294
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1964 if (i == 0) |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1965 { |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1966 result_type = args(i).class_name (); |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1967 |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1968 first_elem_is_struct = args(i).is_map (); |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1969 } |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1970 else |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1971 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
|
1972 |
19399
2304ddfd736f
Restore warning Octave:num-to-str missing since 3.2.4 (bug #43814).
Rik <rik@octave.org>
parents:
18869
diff
changeset
|
1973 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
|
1974 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
|
1975 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
|
1976 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
|
1977 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
|
1978 all_dq_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
|
1979 if (all_real_p && ! args(i).is_real_type ()) |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1980 all_real_p = false; |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1981 if (all_cmplx_p && ! (args(i).is_complex_type () |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1982 || args(i).is_real_type ())) |
13294
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1983 all_cmplx_p = false; |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20943
diff
changeset
|
1984 if (! any_sparse_p && args(i).is_sparse_type ()) |
10716
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1985 any_sparse_p = true; |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20943
diff
changeset
|
1986 if (! any_cell_p && args(i).is_cell ()) |
13294
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1987 any_cell_p = true; |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20943
diff
changeset
|
1988 if (! any_class_p && args(i).is_object ()) |
13294
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1989 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
|
1990 } |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1991 |
13294
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1992 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
|
1993 { |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1994 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
|
1995 { |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1996 if (! args(i).is_cell ()) |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1997 args(i) = Cell (args(i)); |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1998 } |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1999 } |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
2000 |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
2001 if (any_class_p) |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
2002 { |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
2003 retval = do_class_concat (args, fname, dim); |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
2004 } |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
2005 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
|
2006 { |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2007 if (any_sparse_p) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
2008 { |
10716
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2009 if (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
|
2010 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
|
2011 else |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2012 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
|
2013 } |
10716
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2014 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2015 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2016 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
|
2017 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
|
2018 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
|
2019 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
|
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 } |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2022 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
|
2023 { |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2024 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
|
2025 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
|
2026 else |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2027 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
|
2028 } |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2029 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
|
2030 { |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2031 char type = all_dq_strings_p ? '"' : '\''; |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2032 |
19399
2304ddfd736f
Restore warning Octave:num-to-str missing since 3.2.4 (bug #43814).
Rik <rik@octave.org>
parents:
18869
diff
changeset
|
2033 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
|
2034 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
|
2035 "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
|
2036 else |
2304ddfd736f
Restore warning Octave:num-to-str missing since 3.2.4 (bug #43814).
Rik <rik@octave.org>
parents:
18869
diff
changeset
|
2037 maybe_warn_string_concat (all_dq_strings_p, all_sq_strings_p); |
2304ddfd736f
Restore warning Octave:num-to-str missing since 3.2.4 (bug #43814).
Rik <rik@octave.org>
parents:
18869
diff
changeset
|
2038 |
2304ddfd736f
Restore warning Octave:num-to-str missing since 3.2.4 (bug #43814).
Rik <rik@octave.org>
parents:
18869
diff
changeset
|
2039 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
|
2040 |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2041 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
|
2042 } |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2043 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
|
2044 { |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2045 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
|
2046 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
|
2047 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
|
2048 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
|
2049 } |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2050 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
|
2051 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
|
2052 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
|
2053 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
|
2054 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
|
2055 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
|
2056 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
|
2057 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
|
2058 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
|
2059 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
|
2060 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
|
2061 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
|
2062 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
|
2063 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
|
2064 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
|
2065 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
|
2066 else if (result_type == "cell") |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
2067 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
|
2068 else if (result_type == "struct") |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
2069 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
|
2070 else |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2071 { |
20218
b2100e1659ac
maint: Use cuddled parentheses when indexing dimension_vectors.
Rik <rik@octave.org>
parents:
20183
diff
changeset
|
2072 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
|
2073 |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2074 // Default concatenation. |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2075 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
|
2076 = &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
|
2077 |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2078 if (dim == -1 || dim == -2) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2079 { |
10716
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2080 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
|
2081 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
|
2082 } |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2083 |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2084 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
|
2085 { |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2086 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
|
2087 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
|
2088 } |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2089 |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2090 // 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
|
2091 // of the first argument, resize it to be empty and then resize |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2092 // it to be full. This is done since it means that there is no |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2093 // 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
|
2094 // 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
|
2095 // 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
|
2096 // 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
|
2097 // |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2098 // We might also start with a empty octave_value using |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
2099 // tmp = octave_value_typeinfo::lookup_type |
10716
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2100 // (args(1).type_name()); |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2101 // and then directly resize. However, for some types there might |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2102 // 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
|
2103 |
18112
b560bac0fca2
maint: Don't use space between 'args' and '(' when doing indexing.
Rik <rik@octave.org>
parents:
18100
diff
changeset
|
2104 octave_value tmp = args(0); |
10716
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2105 tmp = tmp.resize (dim_vector (0,0)).resize (dv); |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2106 |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2107 int dv_len = dv.length (); |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
2108 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
|
2109 |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2110 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
|
2111 { |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2112 // 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
|
2113 // 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
|
2114 // the right type. |
18112
b560bac0fca2
maint: Don't use space between 'args' and '(' when doing indexing.
Rik <rik@octave.org>
parents:
18100
diff
changeset
|
2115 tmp = do_cat_op (tmp, args(j), ra_idx); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2116 |
18112
b560bac0fca2
maint: Don't use space between 'args' and '(' when doing indexing.
Rik <rik@octave.org>
parents:
18100
diff
changeset
|
2117 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
|
2118 |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2119 if (dim >= dv_len) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2120 { |
10716
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2121 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
|
2122 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
|
2123 |
10716
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2124 break; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2125 } |
10716
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2126 else |
20218
b2100e1659ac
maint: Use cuddled parentheses when indexing dimension_vectors.
Rik <rik@octave.org>
parents:
20183
diff
changeset
|
2127 ra_idx(dim) += (dim < dv_tmp.length () ? dv_tmp(dim) : 1); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2128 } |
10716
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2129 retval = tmp; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2130 } |
4806 | 2131 } |
2132 else | |
5823 | 2133 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
|
2134 |
4806 | 2135 return retval; |
2136 } | |
2137 | |
2138 DEFUN (horzcat, args, , | |
4824 | 2139 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
2140 @deftypefn {} {} horzcat (@var{array1}, @var{array2}, @dots{}, @var{arrayN})\n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
2141 Return the horizontal concatenation of N-D array objects, @var{array1},\n\ |
4806 | 2142 @var{array2}, @dots{}, @var{arrayN} along dimension 2.\n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
2143 \n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
2144 Arrays may also be concatenated horizontally using the syntax for creating\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
2145 new matrices. For example:\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
2146 \n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
2147 @example\n\ |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
2148 @var{hcat} = [ @var{array1}, @var{array2}, @dots{} ]\n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
2149 @end example\n\ |
5642 | 2150 @seealso{cat, vertcat}\n\ |
2151 @end deftypefn") | |
4806 | 2152 { |
10716
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2153 return do_cat (args, -2, "horzcat"); |
4806 | 2154 } |
2155 | |
13294
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
2156 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2157 ## Test concatenation with all zero matrices |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2158 %!assert (horzcat ("", 65*ones (1,10)), "AAAAAAAAAA"); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2159 %!assert (horzcat (65*ones (1,10), ""), "AAAAAAAAAA"); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2160 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2161 %!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
|
2162 %!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
|
2163 %!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
|
2164 %!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
|
2165 %!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
|
2166 %!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
|
2167 %!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
|
2168 %!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
|
2169 %!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
|
2170 %!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
|
2171 %!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
|
2172 %!assert (class (horzcat (int64 (1), true)), "int64") |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2173 %!assert (class (horzcat (int64 (1), "a")), "char") |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2174 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2175 %!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
|
2176 %!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
|
2177 %!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
|
2178 %!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
|
2179 %!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
|
2180 %!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
|
2181 %!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
|
2182 %!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
|
2183 %!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
|
2184 %!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
|
2185 %!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
|
2186 %!assert (class (horzcat (int32 (1), true)), "int32") |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2187 %!assert (class (horzcat (int32 (1), "a")), "char") |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2188 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2189 %!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
|
2190 %!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
|
2191 %!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
|
2192 %!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
|
2193 %!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
|
2194 %!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
|
2195 %!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
|
2196 %!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
|
2197 %!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
|
2198 %!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
|
2199 %!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
|
2200 %!assert (class (horzcat (int16 (1), true)), "int16") |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2201 %!assert (class (horzcat (int16 (1), "a")), "char") |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2202 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2203 %!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
|
2204 %!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
|
2205 %!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
|
2206 %!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
|
2207 %!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
|
2208 %!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
|
2209 %!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
|
2210 %!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
|
2211 %!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
|
2212 %!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
|
2213 %!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
|
2214 %!assert (class (horzcat (int8 (1), true)), "int8") |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2215 %!assert (class (horzcat (int8 (1), "a")), "char") |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2216 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2217 %!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
|
2218 %!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
|
2219 %!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
|
2220 %!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
|
2221 %!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
|
2222 %!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
|
2223 %!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
|
2224 %!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
|
2225 %!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
|
2226 %!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
|
2227 %!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
|
2228 %!assert (class (horzcat (uint64 (1), true)), "uint64") |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2229 %!assert (class (horzcat (uint64 (1), "a")), "char") |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2230 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2231 %!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
|
2232 %!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
|
2233 %!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
|
2234 %!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
|
2235 %!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
|
2236 %!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
|
2237 %!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
|
2238 %!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
|
2239 %!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
|
2240 %!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
|
2241 %!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
|
2242 %!assert (class (horzcat (uint32 (1), true)), "uint32") |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2243 %!assert (class (horzcat (uint32 (1), "a")), "char") |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2244 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2245 %!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
|
2246 %!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
|
2247 %!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
|
2248 %!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
|
2249 %!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
|
2250 %!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
|
2251 %!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
|
2252 %!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
|
2253 %!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
|
2254 %!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
|
2255 %!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
|
2256 %!assert (class (horzcat (uint16 (1), true)), "uint16") |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2257 %!assert (class (horzcat (uint16 (1), "a")), "char") |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2258 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2259 %!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
|
2260 %!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
|
2261 %!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
|
2262 %!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
|
2263 %!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
|
2264 %!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
|
2265 %!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
|
2266 %!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
|
2267 %!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
|
2268 %!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
|
2269 %!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
|
2270 %!assert (class (horzcat (uint8 (1), true)), "uint8") |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2271 %!assert (class (horzcat (uint8 (1), "a")), "char") |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2272 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2273 %!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
|
2274 %!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
|
2275 %!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
|
2276 %!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
|
2277 %!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
|
2278 %!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
|
2279 %!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
|
2280 %!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
|
2281 %!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
|
2282 %!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
|
2283 %!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
|
2284 %!assert (class (horzcat (single (1), true)), "single") |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2285 %!assert (class (horzcat (single (1), "a")), "char") |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2286 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2287 %!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
|
2288 %!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
|
2289 %!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
|
2290 %!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
|
2291 %!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
|
2292 %!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
|
2293 %!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
|
2294 %!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
|
2295 %!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
|
2296 %!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
|
2297 %!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
|
2298 %!assert (class (horzcat (double (1), true)), "double") |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2299 %!assert (class (horzcat (double (1), "a")), "char") |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2300 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2301 %!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
|
2302 %!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
|
2303 %!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
|
2304 %!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
|
2305 %!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
|
2306 %!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
|
2307 %!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
|
2308 %!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
|
2309 %!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
|
2310 %!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
|
2311 %!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
|
2312 %!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
|
2313 %!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
|
2314 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2315 %!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
|
2316 %!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
|
2317 %!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
|
2318 %!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
|
2319 %!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
|
2320 %!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
|
2321 %!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
|
2322 %!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
|
2323 %!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
|
2324 %!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
|
2325 %!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
|
2326 %!assert (class (horzcat (true, true)), "logical") |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2327 %!assert (class (horzcat (true, "a")), "char") |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2328 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2329 %!assert (class (horzcat ("a", int64 (1))), "char") |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2330 %!assert (class (horzcat ("a", int32 (1))), "char") |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2331 %!assert (class (horzcat ("a", int16 (1))), "char") |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2332 %!assert (class (horzcat ("a", int8 (1))), "char") |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2333 %!assert (class (horzcat ("a", int64 (1))), "char") |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2334 %!assert (class (horzcat ("a", int32 (1))), "char") |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2335 %!assert (class (horzcat ("a", int16 (1))), "char") |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2336 %!assert (class (horzcat ("a", int8 (1))), "char") |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2337 %!assert (class (horzcat ("a", single (1))), "char") |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2338 %!assert (class (horzcat ("a", double (1))), "char") |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2339 %!assert (class (horzcat ("a", cell (1))), "cell") |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2340 %!assert (class (horzcat ("a", true)), "char") |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2341 %!assert (class (horzcat ("a", "a")), "char") |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2342 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2343 %!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
|
2344 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2345 %!error horzcat (struct ("foo", "bar"), cell (1)) |
13294
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
2346 */ |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
2347 |
4806 | 2348 DEFUN (vertcat, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2349 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
2350 @deftypefn {} {} vertcat (@var{array1}, @var{array2}, @dots{}, @var{arrayN})\n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
2351 Return the vertical concatenation of N-D array objects, @var{array1},\n\ |
4806 | 2352 @var{array2}, @dots{}, @var{arrayN} along dimension 1.\n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
2353 \n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
2354 Arrays may also be concatenated vertically using the syntax for creating\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
2355 new matrices. For example:\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
2356 \n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
2357 @example\n\ |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
2358 @var{vcat} = [ @var{array1}; @var{array2}; @dots{} ]\n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
2359 @end example\n\ |
5642 | 2360 @seealso{cat, horzcat}\n\ |
2361 @end deftypefn") | |
4806 | 2362 { |
10716
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2363 return do_cat (args, -1, "vertcat"); |
4806 | 2364 } |
2365 | |
13294
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
2366 /* |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
2367 %!test |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2368 %! c = {"foo"; "bar"; "bazoloa"}; |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2369 %! assert (vertcat (c, "a", "bc", "def"), {"foo"; "bar"; "bazoloa"; "a"; "bc"; "def"}); |
13294
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
2370 */ |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
2371 |
4758 | 2372 DEFUN (cat, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2373 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
2374 @deftypefn {} {} cat (@var{dim}, @var{array1}, @var{array2}, @dots{}, @var{arrayN})\n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
2375 Return the concatenation of N-D array objects, @var{array1},\n\ |
4806 | 2376 @var{array2}, @dots{}, @var{arrayN} along dimension @var{dim}.\n\ |
4758 | 2377 \n\ |
2378 @example\n\ | |
2379 @group\n\ | |
2380 A = ones (2, 2);\n\ | |
2381 B = zeros (2, 2);\n\ | |
2382 cat (2, A, B)\n\ | |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
2383 @result{} 1 1 0 0\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
2384 1 1 0 0\n\ |
4758 | 2385 @end group\n\ |
2386 @end example\n\ | |
2387 \n\ | |
2388 Alternatively, we can concatenate @var{A} and @var{B} along the\n\ | |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
2389 second dimension in the following way:\n\ |
4758 | 2390 \n\ |
2391 @example\n\ | |
2392 @group\n\ | |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
2393 [A, B]\n\ |
4758 | 2394 @end group\n\ |
2395 @end example\n\ | |
2396 \n\ | |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
2397 @var{dim} can be larger than the dimensions of the N-D array objects\n\ |
4758 | 2398 and the result will thus have @var{dim} dimensions as the\n\ |
2399 following example shows:\n\ | |
10840 | 2400 \n\ |
4758 | 2401 @example\n\ |
2402 @group\n\ | |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
2403 cat (4, ones (2, 2), zeros (2, 2))\n\ |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
2404 @result{} ans(:,:,1,1) =\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
2405 \n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
2406 1 1\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
2407 1 1\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
2408 \n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
2409 ans(:,:,1,2) =\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
2410 \n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
2411 0 0\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
2412 0 0\n\ |
4758 | 2413 @end group\n\ |
2414 @end example\n\ | |
5642 | 2415 @seealso{horzcat, vertcat}\n\ |
2416 @end deftypefn") | |
4758 | 2417 { |
20850
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
2418 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
|
2419 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
|
2420 |
20850
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
2421 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
|
2422 |
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
2423 if (dim < 0) |
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
2424 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
|
2425 |
21127
df7891224709
maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents:
21121
diff
changeset
|
2426 return ovl (do_cat (args.slice (1, args.length () - 1), dim, "cat")); |
4758 | 2427 } |
2428 | |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
2429 /* |
14085
4e8f23ccadce
test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents:
14022
diff
changeset
|
2430 %!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
|
2431 %! 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
|
2432 %! |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2433 %! 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
|
2434 %! 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
|
2435 %! assert (cat (1, cast ([1; 2], t1), cast (3, t2)), cast ([1; 2; 3], tr)); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2436 %! assert (cat (1, cast ([1; 2], t1), cast ([3; 4], t2)), cast ([1; 2; 3; 4], tr)); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2437 %! 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
|
2438 %! 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
|
2439 %! assert (cat (2, cast ([1, 2], t1), cast (3, t2)), cast ([1, 2, 3], tr)); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2440 %! assert (cat (2, cast ([1, 2], t1), cast ([3, 4], t2)), cast ([1, 2, 3, 4], tr)); |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2441 %! |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2442 %! 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
|
2443 %! 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
|
2444 %! 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
|
2445 %! 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
|
2446 %! 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
|
2447 %! 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
|
2448 %! 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
|
2449 %! 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
|
2450 %! |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2451 %! if (nargin == 3 || cmplx) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2452 %! 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
|
2453 %! 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
|
2454 %! assert (cat (1, cast ([1i; 2], t1), cast (3, t2)), cast ([1i; 2; 3], tr)); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2455 %! assert (cat (1, cast ([1i; 2], t1), cast ([3; 4], t2)), cast ([1i; 2; 3; 4], tr)); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2456 %! 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
|
2457 %! 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
|
2458 %! assert (cat (2, cast ([1i, 2], t1), cast (3, t2)), cast ([1i, 2, 3], tr)); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2459 %! assert (cat (2, cast ([1i, 2], t1), cast ([3, 4], t2)), cast ([1i, 2, 3, 4], tr)); |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2460 %! |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2461 %! 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
|
2462 %! 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
|
2463 %! 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
|
2464 %! 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
|
2465 %! 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
|
2466 %! 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
|
2467 %! 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
|
2468 %! 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
|
2469 %! |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2470 %! 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
|
2471 %! 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
|
2472 %! assert (cat (1, cast ([1; 2], t1), cast (3i, t2)), cast ([1; 2; 3i], tr)); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2473 %! assert (cat (1, cast ([1; 2], t1), cast ([3i; 4], t2)), cast ([1; 2; 3i; 4], tr)); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2474 %! 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
|
2475 %! 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
|
2476 %! assert (cat (2, cast ([1, 2], t1), cast (3i, t2)), cast ([1, 2, 3i], tr)); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2477 %! assert (cat (2, cast ([1, 2], t1), cast ([3i, 4], t2)), cast ([1, 2, 3i, 4], tr)); |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2478 %! |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2479 %! 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
|
2480 %! 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
|
2481 %! 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
|
2482 %! 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
|
2483 %! 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
|
2484 %! 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
|
2485 %! 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
|
2486 %! 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
|
2487 %! |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2488 %! assert (cat (1, cast (1i, t1), cast (2i, t2)), cast ([1i; 2i], tr)); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2489 %! assert (cat (1, cast (1i, t1), cast ([2i; 3], t2)), cast ([1i; 2i; 3], tr)); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2490 %! assert (cat (1, cast ([1i; 2], t1), cast (3i, t2)), cast ([1i; 2; 3i], tr)); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2491 %! assert (cat (1, cast ([1i; 2], t1), cast ([3i; 4], t2)), cast ([1i; 2; 3i; 4], tr)); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2492 %! assert (cat (2, cast (1i, t1), cast (2i, t2)), cast ([1i, 2i], tr)); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2493 %! assert (cat (2, cast (1i, t1), cast ([2i, 3], t2)), cast ([1i, 2i, 3], tr)); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2494 %! assert (cat (2, cast ([1i, 2], t1), cast (3i, t2)), cast ([1i, 2, 3i], tr)); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2495 %! assert (cat (2, cast ([1i, 2], t1), cast ([3i, 4], t2)), cast ([1i, 2, 3i, 4], tr)); |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2496 %! |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2497 %! 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
|
2498 %! 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
|
2499 %! assert ([cast([1i; 2], t1); cast(3i, t2)], cast ([1i; 2; 3i], tr)); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2500 %! assert ([cast([1i; 2], t1); cast([3i; 4], t2)], cast ([1i; 2; 3i; 4], tr)); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2501 %! 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
|
2502 %! 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
|
2503 %! assert ([cast([1i, 2], t1), cast(3i, t2)], cast ([1i, 2, 3i], tr)); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2504 %! assert ([cast([1i, 2], t1), cast([3i, 4], t2)], cast ([1i, 2, 3i, 4], tr)); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2505 %! endif |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2506 %! ret = true; |
14085
4e8f23ccadce
test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents:
14022
diff
changeset
|
2507 %!endfunction |
4e8f23ccadce
test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents:
14022
diff
changeset
|
2508 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2509 %!assert (__testcat ("double", "double", "double")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2510 %!assert (__testcat ("single", "double", "single")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2511 %!assert (__testcat ("double", "single", "single")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2512 %!assert (__testcat ("single", "single", "single")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2513 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2514 %!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
|
2515 %!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
|
2516 %!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
|
2517 %!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
|
2518 %!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
|
2519 %!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
|
2520 %!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
|
2521 %!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
|
2522 %!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
|
2523 %!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
|
2524 %!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
|
2525 %!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
|
2526 %!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
|
2527 %!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
|
2528 %!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
|
2529 %!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
|
2530 %!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
|
2531 %!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
|
2532 %!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
|
2533 %!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
|
2534 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2535 %!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
|
2536 %!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
|
2537 %!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
|
2538 %!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
|
2539 %!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
|
2540 %!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
|
2541 %!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
|
2542 %!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
|
2543 %!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
|
2544 %!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
|
2545 %!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
|
2546 %!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
|
2547 %!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
|
2548 %!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
|
2549 %!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
|
2550 %!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
|
2551 %!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
|
2552 %!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
|
2553 %!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
|
2554 %!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
|
2555 |
4e8f23ccadce
test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents:
14022
diff
changeset
|
2556 %!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
|
2557 %!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
|
2558 %!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
|
2559 %!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
|
2560 |
4e8f23ccadce
test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents:
14022
diff
changeset
|
2561 %!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
|
2562 %!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
|
2563 %!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
|
2564 |
18678
6113e0c6920b
maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents:
18676
diff
changeset
|
2565 %!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
|
2566 %!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
|
2567 |
14085
4e8f23ccadce
test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents:
14022
diff
changeset
|
2568 %!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
|
2569 %!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
|
2570 */ |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
2571 |
4593 | 2572 static octave_value |
6959 | 2573 do_permute (const octave_value_list& args, bool inv) |
4593 | 2574 { |
20850
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
2575 if (args.length () != 2 || args(1).length () < args(1).ndims ()) |
5823 | 2576 print_usage (); |
4593 | 2577 |
20850
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
2578 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
|
2579 |
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
2580 // 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
|
2581 // and pass that to permute? |
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
2582 int n = vec.numel (); |
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
2583 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
|
2584 vec(i)--; |
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
2585 |
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
2586 return octave_value (args(0).permute (vec, inv)); |
4593 | 2587 } |
2588 | |
2589 DEFUN (permute, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2590 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
2591 @deftypefn {} {} permute (@var{A}, @var{perm})\n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
2592 Return the generalized transpose for an N-D array object @var{A}.\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
2593 \n\ |
4593 | 2594 The permutation vector @var{perm} must contain the elements\n\ |
20569
c6059134f5d3
data.cc: Add @w{} around @code segments in docstrings to prevent line breaks.
Rik <rik@octave.org>
parents:
20398
diff
changeset
|
2595 @w{@code{1:ndims (A)}} (in any order, but each element must appear only\n\ |
c6059134f5d3
data.cc: Add @w{} around @code segments in docstrings to prevent line breaks.
Rik <rik@octave.org>
parents:
20398
diff
changeset
|
2596 once). The @var{N}th dimension of @var{A} gets remapped to dimension\n\ |
19152
0f9c5a15c8fa
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
19118
diff
changeset
|
2597 @code{@var{PERM}(@var{N})}. For example:\n\ |
19073
ec1e295402fa
doc: explain permute's PERM variable and give examples
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
19038
diff
changeset
|
2598 \n\ |
ec1e295402fa
doc: explain permute's PERM variable and give examples
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
19038
diff
changeset
|
2599 @example\n\ |
ec1e295402fa
doc: explain permute's PERM variable and give examples
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
19038
diff
changeset
|
2600 @group\n\ |
ec1e295402fa
doc: explain permute's PERM variable and give examples
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
19038
diff
changeset
|
2601 @var{x} = zeros ([2, 3, 5, 7]);\n\ |
ec1e295402fa
doc: explain permute's PERM variable and give examples
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
19038
diff
changeset
|
2602 size (@var{x})\n\ |
ec1e295402fa
doc: explain permute's PERM variable and give examples
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
19038
diff
changeset
|
2603 @result{} 2 3 5 7\n\ |
ec1e295402fa
doc: explain permute's PERM variable and give examples
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
19038
diff
changeset
|
2604 \n\ |
ec1e295402fa
doc: explain permute's PERM variable and give examples
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
19038
diff
changeset
|
2605 size (permute (@var{x}, [2, 1, 3, 4]))\n\ |
ec1e295402fa
doc: explain permute's PERM variable and give examples
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
19038
diff
changeset
|
2606 @result{} 3 2 5 7\n\ |
ec1e295402fa
doc: explain permute's PERM variable and give examples
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
19038
diff
changeset
|
2607 \n\ |
ec1e295402fa
doc: explain permute's PERM variable and give examples
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
19038
diff
changeset
|
2608 size (permute (@var{x}, [1, 3, 4, 2]))\n\ |
ec1e295402fa
doc: explain permute's PERM variable and give examples
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
19038
diff
changeset
|
2609 @result{} 2 5 7 3\n\ |
ec1e295402fa
doc: explain permute's PERM variable and give examples
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
19038
diff
changeset
|
2610 \n\ |
ec1e295402fa
doc: explain permute's PERM variable and give examples
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
19038
diff
changeset
|
2611 ## The identity permutation\n\ |
ec1e295402fa
doc: explain permute's PERM variable and give examples
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
19038
diff
changeset
|
2612 size (permute (@var{x}, [1, 2, 3, 4]))\n\ |
ec1e295402fa
doc: explain permute's PERM variable and give examples
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
19038
diff
changeset
|
2613 @result{} 2 3 5 7\n\ |
ec1e295402fa
doc: explain permute's PERM variable and give examples
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
19038
diff
changeset
|
2614 @end group\n\ |
ec1e295402fa
doc: explain permute's PERM variable and give examples
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
19038
diff
changeset
|
2615 @end example\n\ |
5642 | 2616 @seealso{ipermute}\n\ |
2617 @end deftypefn") | |
4593 | 2618 { |
6959 | 2619 return do_permute (args, false); |
4593 | 2620 } |
2621 | |
2622 DEFUN (ipermute, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2623 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
2624 @deftypefn {} {} ipermute (@var{A}, @var{iperm})\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
2625 The inverse of the @code{permute} function.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
2626 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
2627 The expression\n\ |
4593 | 2628 \n\ |
2629 @example\n\ | |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
2630 ipermute (permute (A, perm), perm)\n\ |
4593 | 2631 @end example\n\ |
10840 | 2632 \n\ |
10846
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10840
diff
changeset
|
2633 @noindent\n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
2634 returns the original array @var{A}.\n\ |
5642 | 2635 @seealso{permute}\n\ |
2636 @end deftypefn") | |
4593 | 2637 { |
6959 | 2638 return do_permute (args, true); |
4593 | 2639 } |
2640 | |
3195 | 2641 DEFUN (length, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2642 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
2643 @deftypefn {} {} length (@var{a})\n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17268
diff
changeset
|
2644 Return the length of the object @var{a}.\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17268
diff
changeset
|
2645 \n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17268
diff
changeset
|
2646 The length is 0 for empty objects, 1 for scalars, and the number of elements\n\ |
20398
fc23fbe05f3a
doc: Clarify behavior of length() function (bug #45611).
Rik <rik@octave.org>
parents:
20183
diff
changeset
|
2647 for vectors. For matrix or N-dimensional objects, the length is the number\n\ |
fc23fbe05f3a
doc: Clarify behavior of length() function (bug #45611).
Rik <rik@octave.org>
parents:
20183
diff
changeset
|
2648 of elements along the largest dimension\n\ |
fc23fbe05f3a
doc: Clarify behavior of length() function (bug #45611).
Rik <rik@octave.org>
parents:
20183
diff
changeset
|
2649 (equivalent to @w{@code{max (size (@var{a}))}}).\n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17268
diff
changeset
|
2650 @seealso{numel, size}\n\ |
3373 | 2651 @end deftypefn") |
3195 | 2652 { |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2653 if (args.length () != 1) |
5823 | 2654 print_usage (); |
3195 | 2655 |
21127
df7891224709
maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents:
21121
diff
changeset
|
2656 return ovl (args(0).length ()); |
3195 | 2657 } |
2658 | |
4554 | 2659 DEFUN (ndims, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2660 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
2661 @deftypefn {} {} ndims (@var{a})\n\ |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
2662 Return the number of dimensions of @var{a}.\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
2663 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
2664 For any array, the result will always be greater than or equal to 2.\n\ |
4554 | 2665 Trailing singleton dimensions are not counted.\n\ |
10840 | 2666 \n\ |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
2667 @example\n\ |
10711
fbd7843974fa
Periodic grammar check of documentation files to ensure common format.
Rik <octave@nomad.inbox5.com>
parents:
10707
diff
changeset
|
2668 @group\n\ |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
2669 ndims (ones (4, 1, 2, 1))\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
2670 @result{} 3\n\ |
10711
fbd7843974fa
Periodic grammar check of documentation files to ensure common format.
Rik <octave@nomad.inbox5.com>
parents:
10707
diff
changeset
|
2671 @end group\n\ |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
2672 @end example\n\ |
15028
397f0d80bd47
Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents:
15024
diff
changeset
|
2673 @seealso{size}\n\ |
4554 | 2674 @end deftypefn") |
2675 { | |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2676 if (args.length () != 1) |
5823 | 2677 print_usage (); |
4554 | 2678 |
21127
df7891224709
maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents:
21121
diff
changeset
|
2679 return ovl (args(0).ndims ()); |
4554 | 2680 } |
2681 | |
4559 | 2682 DEFUN (numel, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2683 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
2684 @deftypefn {} {} numel (@var{a})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
2685 @deftypefnx {} {} numel (@var{a}, @var{idx1}, @var{idx2}, @dots{})\n\ |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
2686 Return the number of elements in the object @var{a}.\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
2687 \n\ |
9705
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
2688 Optionally, if indices @var{idx1}, @var{idx2}, @dots{} are supplied,\n\ |
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
2689 return the number of elements that would result from the indexing\n\ |
10840 | 2690 \n\ |
9705
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
2691 @example\n\ |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
2692 @var{a}(@var{idx1}, @var{idx2}, @dots{})\n\ |
9705
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
2693 @end example\n\ |
10840 | 2694 \n\ |
20572
db3286201347
doc: Add explanation of ':' optional input to numel().
Rik <rik@octave.org>
parents:
20569
diff
changeset
|
2695 Note that the indices do not have to be scalar numbers. For example,\n\ |
12924
67a5acac8e1b
Clarify what indices can be for numel
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12681
diff
changeset
|
2696 \n\ |
67a5acac8e1b
Clarify what indices can be for numel
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12681
diff
changeset
|
2697 @example\n\ |
13929
9cae456085c2
Grammarcheck of documentation before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
2698 @group\n\ |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
2699 @var{a} = 1;\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
2700 @var{b} = ones (2, 3);\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
2701 numel (@var{a}, @var{b})\n\ |
13929
9cae456085c2
Grammarcheck of documentation before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
2702 @end group\n\ |
12924
67a5acac8e1b
Clarify what indices can be for numel
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12681
diff
changeset
|
2703 @end example\n\ |
67a5acac8e1b
Clarify what indices can be for numel
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12681
diff
changeset
|
2704 \n\ |
13929
9cae456085c2
Grammarcheck of documentation before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
2705 @noindent\n\ |
12924
67a5acac8e1b
Clarify what indices can be for numel
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12681
diff
changeset
|
2706 will return 6, as this is the number of ways to index with @var{b}.\n\ |
20572
db3286201347
doc: Add explanation of ':' optional input to numel().
Rik <rik@octave.org>
parents:
20569
diff
changeset
|
2707 Or the index could be the string @qcode{\":\"} which represents the colon\n\ |
db3286201347
doc: Add explanation of ':' optional input to numel().
Rik <rik@octave.org>
parents:
20569
diff
changeset
|
2708 operator. For example,\n\ |
db3286201347
doc: Add explanation of ':' optional input to numel().
Rik <rik@octave.org>
parents:
20569
diff
changeset
|
2709 \n\ |
db3286201347
doc: Add explanation of ':' optional input to numel().
Rik <rik@octave.org>
parents:
20569
diff
changeset
|
2710 @example\n\ |
db3286201347
doc: Add explanation of ':' optional input to numel().
Rik <rik@octave.org>
parents:
20569
diff
changeset
|
2711 @group\n\ |
db3286201347
doc: Add explanation of ':' optional input to numel().
Rik <rik@octave.org>
parents:
20569
diff
changeset
|
2712 @var{a} = ones (5, 3);\n\ |
db3286201347
doc: Add explanation of ':' optional input to numel().
Rik <rik@octave.org>
parents:
20569
diff
changeset
|
2713 numel (@var{a}, 2, \":\")\n\ |
db3286201347
doc: Add explanation of ':' optional input to numel().
Rik <rik@octave.org>
parents:
20569
diff
changeset
|
2714 @end group\n\ |
db3286201347
doc: Add explanation of ':' optional input to numel().
Rik <rik@octave.org>
parents:
20569
diff
changeset
|
2715 @end example\n\ |
db3286201347
doc: Add explanation of ':' optional input to numel().
Rik <rik@octave.org>
parents:
20569
diff
changeset
|
2716 \n\ |
db3286201347
doc: Add explanation of ':' optional input to numel().
Rik <rik@octave.org>
parents:
20569
diff
changeset
|
2717 @noindent\n\ |
db3286201347
doc: Add explanation of ':' optional input to numel().
Rik <rik@octave.org>
parents:
20569
diff
changeset
|
2718 will return 3 as the second row has three column entries.\n\ |
12924
67a5acac8e1b
Clarify what indices can be for numel
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12681
diff
changeset
|
2719 \n\ |
9705
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
2720 This method is also called when an object appears as lvalue with cs-list\n\ |
9758
09da0bd91412
Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents:
9736
diff
changeset
|
2721 indexing, i.e., @code{object@{@dots{}@}} or @code{object(@dots{}).field}.\n\ |
5724 | 2722 @seealso{size}\n\ |
4559 | 2723 @end deftypefn") |
2724 { | |
20850
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
2725 int nargin = args.length (); |
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
2726 |
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
2727 if (nargin == 0) |
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
2728 print_usage (); |
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
2729 |
4559 | 2730 octave_value retval; |
9329
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9319
diff
changeset
|
2731 |
9705
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
2732 if (nargin == 1) |
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
2733 retval = args(0).numel (); |
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
2734 else if (nargin > 1) |
4559 | 2735 { |
9705
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
2736 // 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
|
2737 // an overloaded call, not to builtin! |
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
2738 retval = dims_to_numel (args(0).dims (), args.slice (1, nargin-1)); |
4559 | 2739 } |
2740 | |
2741 return retval; | |
2742 } | |
2743 | |
1957 | 2744 DEFUN (size, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2745 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
2746 @deftypefn {} {} size (@var{a})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
2747 @deftypefnx {} {} size (@var{a}, @var{dim})\n\ |
12546
39ca02387a32
Improve docstrings for a number of functions.
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
2748 Return the number of rows and columns of @var{a}.\n\ |
3373 | 2749 \n\ |
2750 With one input argument and one output argument, the result is returned\n\ | |
4741 | 2751 in a row vector. If there are multiple output arguments, the number of\n\ |
2752 rows is assigned to the first, and the number of columns to the second,\n\ | |
10840 | 2753 etc. For example:\n\ |
3373 | 2754 \n\ |
2755 @example\n\ | |
2756 @group\n\ | |
2757 size ([1, 2; 3, 4; 5, 6])\n\ | |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
2758 @result{} [ 3, 2 ]\n\ |
1031 | 2759 \n\ |
3373 | 2760 [nr, nc] = size ([1, 2; 3, 4; 5, 6])\n\ |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
2761 @result{} nr = 3\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
2762 @result{} nc = 2\n\ |
3373 | 2763 @end group\n\ |
2764 @end example\n\ | |
2765 \n\ | |
4741 | 2766 If given a second argument, @code{size} will return the size of the\n\ |
10840 | 2767 corresponding dimension. For example,\n\ |
1031 | 2768 \n\ |
3373 | 2769 @example\n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
9041
diff
changeset
|
2770 @group\n\ |
3373 | 2771 size ([1, 2; 3, 4; 5, 6], 2)\n\ |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
2772 @result{} 2\n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
9041
diff
changeset
|
2773 @end group\n\ |
3373 | 2774 @end example\n\ |
2775 \n\ | |
2776 @noindent\n\ | |
2777 returns the number of columns in the given matrix.\n\ | |
15028
397f0d80bd47
Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents:
15024
diff
changeset
|
2778 @seealso{numel, ndims, length, rows, columns}\n\ |
3373 | 2779 @end deftypefn") |
523 | 2780 { |
2086 | 2781 octave_value_list retval; |
523 | 2782 |
2783 int nargin = args.length (); | |
2784 | |
4513 | 2785 if (nargin == 1) |
523 | 2786 { |
9706
71160b139b07
simplify length,ndims,size and size_equal
Jaroslav Hajek <highegg@gmail.com>
parents:
9705
diff
changeset
|
2787 const dim_vector dimensions = args(0).dims (); |
4513 | 2788 |
2789 if (nargout > 1) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2790 { |
9706
71160b139b07
simplify length,ndims,size and size_equal
Jaroslav Hajek <highegg@gmail.com>
parents:
9705
diff
changeset
|
2791 const dim_vector rdims = dimensions.redim (nargout); |
71160b139b07
simplify length,ndims,size and size_equal
Jaroslav Hajek <highegg@gmail.com>
parents:
9705
diff
changeset
|
2792 retval.resize (nargout); |
71160b139b07
simplify length,ndims,size and size_equal
Jaroslav Hajek <highegg@gmail.com>
parents:
9705
diff
changeset
|
2793 for (int i = 0; i < nargout; i++) |
71160b139b07
simplify length,ndims,size and size_equal
Jaroslav Hajek <highegg@gmail.com>
parents:
9705
diff
changeset
|
2794 retval(i) = rdims(i); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2795 } |
4513 | 2796 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2797 { |
9706
71160b139b07
simplify length,ndims,size and size_equal
Jaroslav Hajek <highegg@gmail.com>
parents:
9705
diff
changeset
|
2798 int ndims = dimensions.length (); |
71160b139b07
simplify length,ndims,size and size_equal
Jaroslav Hajek <highegg@gmail.com>
parents:
9705
diff
changeset
|
2799 |
71160b139b07
simplify length,ndims,size and size_equal
Jaroslav Hajek <highegg@gmail.com>
parents:
9705
diff
changeset
|
2800 NoAlias<Matrix> m (1, ndims); |
71160b139b07
simplify length,ndims,size and size_equal
Jaroslav Hajek <highegg@gmail.com>
parents:
9705
diff
changeset
|
2801 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2802 for (int i = 0; i < ndims; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2803 m(i) = dimensions(i); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2804 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2805 retval(0) = m; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2806 } |
1031 | 2807 } |
2808 else if (nargin == 2 && nargout < 2) | |
2809 { | |
21041
63374982750b
Usage of corresponding value extractor for octave_idx_type. Improves support
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
21014
diff
changeset
|
2810 octave_idx_type nd = args(1).xidx_type_value ("size: DIM must be an integer"); |
20704
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
2811 |
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
2812 const dim_vector dv = args(0).dims (); |
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
2813 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
2814 if (nd < 1) |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
2815 error ("size: requested dimension DIM (= %d) out of range", nd); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
2816 |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
2817 if (nd <= dv.length ()) |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
2818 retval(0) = dv(nd-1); |
20704
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
2819 else |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
2820 retval(0) = 1; |
523 | 2821 } |
712 | 2822 else |
5823 | 2823 print_usage (); |
523 | 2824 |
2825 return retval; | |
2826 } | |
2827 | |
6156 | 2828 DEFUN (size_equal, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2829 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
2830 @deftypefn {} {} size_equal (@var{a}, @var{b}, @dots{})\n\ |
6561 | 2831 Return true if the dimensions of all arguments agree.\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
2832 \n\ |
6156 | 2833 Trailing singleton dimensions are ignored.\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
2834 When called with a single or no argument @code{size_equal} returns true.\n\ |
15028
397f0d80bd47
Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents:
15024
diff
changeset
|
2835 @seealso{size, numel, ndims}\n\ |
6156 | 2836 @end deftypefn") |
2837 { | |
6561 | 2838 int nargin = args.length (); |
2839 | |
8947
1e4b3149365a
allow size_equal called with 1 arg
Jaroslav Hajek <highegg@gmail.com>
parents:
8934
diff
changeset
|
2840 if (nargin >= 1) |
6156 | 2841 { |
2842 dim_vector a_dims = args(0).dims (); | |
6561 | 2843 |
2844 for (int i = 1; i < nargin; ++i) | |
2845 { | |
2846 dim_vector b_dims = args(i).dims (); | |
2847 | |
2848 if (a_dims != b_dims) | |
21078
49852ff04747
maint: Remove unnecessary declarations of retval.
Rik <rik@octave.org>
parents:
21062
diff
changeset
|
2849 return ovl (false); |
6561 | 2850 } |
6156 | 2851 } |
2852 | |
21078
49852ff04747
maint: Remove unnecessary declarations of retval.
Rik <rik@octave.org>
parents:
21062
diff
changeset
|
2853 return ovl (true); |
6156 | 2854 } |
2855 | |
5602 | 2856 DEFUN (nnz, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2857 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
2858 @deftypefn {} {@var{n} =} nnz (@var{a})\n\ |
18812
9ac2357f19bc
doc: Replace "non-zero" with "nonzero" to match existing usage.
Rik <rik@octave.org>
parents:
18811
diff
changeset
|
2859 Return the number of nonzero elements in @var{a}.\n\ |
18809
53af80da6781
doc: Update documentation of sparse functions including seealso links.
Rik <rik@octave.org>
parents:
18789
diff
changeset
|
2860 @seealso{nzmax, nonzeros, find}\n\ |
5602 | 2861 @end deftypefn") |
2862 { | |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2863 if (args.length () != 1) |
5823 | 2864 print_usage (); |
5602 | 2865 |
21127
df7891224709
maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents:
21121
diff
changeset
|
2866 return ovl (args(0).nnz ()); |
5602 | 2867 } |
2868 | |
5604 | 2869 DEFUN (nzmax, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2870 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
2871 @deftypefn {} {@var{n} =} nzmax (@var{SM})\n\ |
5604 | 2872 Return the amount of storage allocated to the sparse matrix @var{SM}.\n\ |
18809
53af80da6781
doc: Update documentation of sparse functions including seealso links.
Rik <rik@octave.org>
parents:
18789
diff
changeset
|
2873 \n\ |
7001 | 2874 Note that Octave tends to crop unused memory at the first opportunity\n\ |
18809
53af80da6781
doc: Update documentation of sparse functions including seealso links.
Rik <rik@octave.org>
parents:
18789
diff
changeset
|
2875 for sparse objects. Thus, in general the value of @code{nzmax} will be the\n\ |
20183
4e7f12a763cd
doc: Remove typo of same word twice in a row.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
2876 same as @code{nnz} except for some cases of user-created sparse objects.\n\ |
15034
1116864ee270
doc: Fix for bad cross-referencing due to use of aliases in Texinfo.
Rik <rik@octave.org>
parents:
15031
diff
changeset
|
2877 @seealso{nnz, spalloc, sparse}\n\ |
5604 | 2878 @end deftypefn") |
2879 { | |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2880 if (args.length () != 1) |
5823 | 2881 print_usage (); |
5604 | 2882 |
21127
df7891224709
maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents:
21121
diff
changeset
|
2883 return ovl (args(0).nzmax ()); |
5604 | 2884 } |
2885 | |
5677 | 2886 DEFUN (rows, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2887 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
2888 @deftypefn {} {} rows (@var{a})\n\ |
5677 | 2889 Return the number of rows of @var{a}.\n\ |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
2890 @seealso{columns, size, length, numel, isscalar, isvector, ismatrix}\n\ |
5677 | 2891 @end deftypefn") |
2892 { | |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2893 if (args.length () != 1) |
5823 | 2894 print_usage (); |
5677 | 2895 |
21127
df7891224709
maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents:
21121
diff
changeset
|
2896 return ovl (args(0).rows ()); |
5677 | 2897 } |
2898 | |
20810 | 2899 /* |
2900 %!assert (rows (ones (2,5)), 2) | |
2901 %!assert (rows (ones (5,2)), 5) | |
20811 | 2902 %!assert (rows (ones (5,4,3,2)), 5) |
20810 | 2903 %!assert (rows (ones (3,4,5,2)), 3) |
2904 | |
2905 %!assert (rows (cell (2,5)), 2) | |
2906 %!assert (rows (cell (5,2)), 5) | |
20811 | 2907 %!assert (rows (cell (5,4,3,2)), 5) |
20810 | 2908 %!assert (rows (cell (3,4,5,2)), 3) |
2909 | |
2910 %!test | |
2911 %! x(2,5,3).a = 1; | |
2912 %! assert (rows (x), 2); | |
2913 %! y(5,4,3).b = 2; | |
2914 %! assert (rows (y), 5); | |
2915 | |
2916 %!assert (rows ("Hello World"), 1) | |
2917 | |
2918 %!assert (rows ([]), 0) | |
20815 | 2919 %!assert (rows (zeros (2,0)), 2) |
20810 | 2920 |
2921 ## Test input validation | |
2922 %!error rows () | |
2923 %!error rows (1,2) | |
2924 */ | |
2925 | |
5677 | 2926 DEFUN (columns, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2927 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
2928 @deftypefn {} {} columns (@var{a})\n\ |
5677 | 2929 Return the number of columns of @var{a}.\n\ |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
2930 @seealso{rows, size, length, numel, isscalar, isvector, ismatrix}\n\ |
5677 | 2931 @end deftypefn") |
2932 { | |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2933 if (args.length () != 1) |
5823 | 2934 print_usage (); |
5677 | 2935 |
21127
df7891224709
maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents:
21121
diff
changeset
|
2936 return ovl (args(0).columns ()); |
5677 | 2937 } |
2938 | |
1957 | 2939 DEFUN (sum, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2940 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
2941 @deftypefn {} {} sum (@var{x})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
2942 @deftypefnx {} {} sum (@var{x}, @var{dim})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
2943 @deftypefnx {} {} sum (@dots{}, \"native\")\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
2944 @deftypefnx {} {} sum (@dots{}, \"double\")\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
2945 @deftypefnx {} {} sum (@dots{}, \"extra\")\n\ |
18726
5baada25d5a2
Rewrite docstring of sum() to match prod().
Rik <rik@octave.org>
parents:
18725
diff
changeset
|
2946 Sum of elements along dimension @var{dim}.\n\ |
5baada25d5a2
Rewrite docstring of sum() to match prod().
Rik <rik@octave.org>
parents:
18725
diff
changeset
|
2947 \n\ |
5baada25d5a2
Rewrite docstring of sum() to match prod().
Rik <rik@octave.org>
parents:
18725
diff
changeset
|
2948 If @var{dim} is omitted, it defaults to the first non-singleton dimension.\n\ |
5baada25d5a2
Rewrite docstring of sum() to match prod().
Rik <rik@octave.org>
parents:
18725
diff
changeset
|
2949 \n\ |
18812
9ac2357f19bc
doc: Replace "non-zero" with "nonzero" to match existing usage.
Rik <rik@octave.org>
parents:
18811
diff
changeset
|
2950 The optional @qcode{\"type\"} input determines the class of the variable\n\ |
9ac2357f19bc
doc: Replace "non-zero" with "nonzero" to match existing usage.
Rik <rik@octave.org>
parents:
18811
diff
changeset
|
2951 used for calculations. If the argument @qcode{\"native\"} is given, then\n\ |
9ac2357f19bc
doc: Replace "non-zero" with "nonzero" to match existing usage.
Rik <rik@octave.org>
parents:
18811
diff
changeset
|
2952 the operation is performed in the same type as the original argument, rather\n\ |
9ac2357f19bc
doc: Replace "non-zero" with "nonzero" to match existing usage.
Rik <rik@octave.org>
parents:
18811
diff
changeset
|
2953 than the default double type.\n\ |
18726
5baada25d5a2
Rewrite docstring of sum() to match prod().
Rik <rik@octave.org>
parents:
18725
diff
changeset
|
2954 \n\ |
5baada25d5a2
Rewrite docstring of sum() to match prod().
Rik <rik@octave.org>
parents:
18725
diff
changeset
|
2955 For example:\n\ |
7112 | 2956 \n\ |
2957 @example\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
9041
diff
changeset
|
2958 @group\n\ |
7112 | 2959 sum ([true, true])\n\ |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
2960 @result{} 2\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
2961 sum ([true, true], \"native\")\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
2962 @result{} true\n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
9041
diff
changeset
|
2963 @end group\n\ |
7112 | 2964 @end example\n\ |
10840 | 2965 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17268
diff
changeset
|
2966 On the contrary, if @qcode{\"double\"} is given, the sum is performed in\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17268
diff
changeset
|
2967 double precision even for single precision inputs.\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17268
diff
changeset
|
2968 \n\ |
18812
9ac2357f19bc
doc: Replace "non-zero" with "nonzero" to match existing usage.
Rik <rik@octave.org>
parents:
18811
diff
changeset
|
2969 For double precision inputs, the @qcode{\"extra\"} option will use a more\n\ |
9ac2357f19bc
doc: Replace "non-zero" with "nonzero" to match existing usage.
Rik <rik@octave.org>
parents:
18811
diff
changeset
|
2970 accurate algorithm than straightforward summation. For single precision\n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17268
diff
changeset
|
2971 inputs, @qcode{\"extra\"} is the same as @qcode{\"double\"}. Otherwise,\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17268
diff
changeset
|
2972 @qcode{\"extra\"} has no effect.\n\ |
9163
9cb0c21e97f7
Update section 17.4 (Sums and Products) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9155
diff
changeset
|
2973 @seealso{cumsum, sumsq, prod}\n\ |
3428 | 2974 @end deftypefn") |
523 | 2975 { |
9721
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2976 int nargin = args.length (); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2977 |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2978 bool isnative = false; |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2979 bool isdouble = false; |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2980 bool isextra = false; |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2981 |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2982 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
|
2983 { |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2984 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
|
2985 |
19743
67f2c76f9f4d
Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents:
19739
diff
changeset
|
2986 if (str == "native") |
67f2c76f9f4d
Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents:
19739
diff
changeset
|
2987 isnative = true; |
67f2c76f9f4d
Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents:
19739
diff
changeset
|
2988 else if (str == "double") |
67f2c76f9f4d
Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents:
19739
diff
changeset
|
2989 isdouble = true; |
67f2c76f9f4d
Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents:
19739
diff
changeset
|
2990 else if (str == "extra") |
67f2c76f9f4d
Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents:
19739
diff
changeset
|
2991 isextra = true; |
67f2c76f9f4d
Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents:
19739
diff
changeset
|
2992 else |
67f2c76f9f4d
Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents:
19739
diff
changeset
|
2993 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
|
2994 |
21062
d9c1884d1aaa
maint: Eliminate space between variable and decrement '--' operator.
Rik <rik@octave.org>
parents:
21055
diff
changeset
|
2995 nargin--; |
9721
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2996 } |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2997 |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2998 if (nargin < 1 || nargin > 2) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
2999 print_usage (); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3000 |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3001 int dim = -1; |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3002 if (nargin == 2) |
9721
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
3003 { |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3004 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
|
3005 if (dim < 0) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3006 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
|
3007 } |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3008 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
3009 octave_value retval; |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
3010 octave_value arg = args(0); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
3011 |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3012 switch (arg.builtin_type ()) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3013 { |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3014 case btyp_double: |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3015 if (arg.is_sparse_type ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3016 { |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3017 if (isextra) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3018 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
|
3019 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
|
3020 } |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3021 else if (isextra) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3022 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
|
3023 else |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3024 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
|
3025 break; |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3026 |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3027 case btyp_complex: |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3028 if (arg.is_sparse_type ()) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3029 { |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3030 if (isextra) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3031 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
|
3032 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
|
3033 } |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3034 else if (isextra) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3035 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
|
3036 else |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3037 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
|
3038 break; |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3039 |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3040 case btyp_float: |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3041 if (isdouble || isextra) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3042 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
|
3043 else |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3044 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
|
3045 break; |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3046 |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3047 case btyp_float_complex: |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3048 if (isdouble || isextra) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3049 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
|
3050 else |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3051 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
|
3052 break; |
9721
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
3053 |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
3054 #define MAKE_INT_BRANCH(X) \ |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3055 case btyp_ ## X: \ |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3056 if (isnative) \ |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3057 retval = arg.X ## _array_value ().sum (dim); \ |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3058 else \ |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3059 retval = arg.X ## _array_value ().dsum (dim); \ |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3060 break; |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3061 |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3062 MAKE_INT_BRANCH (int8); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3063 MAKE_INT_BRANCH (int16); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3064 MAKE_INT_BRANCH (int32); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3065 MAKE_INT_BRANCH (int64); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3066 MAKE_INT_BRANCH (uint8); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3067 MAKE_INT_BRANCH (uint16); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3068 MAKE_INT_BRANCH (uint32); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3069 MAKE_INT_BRANCH (uint64); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3070 |
9721
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
3071 #undef MAKE_INT_BRANCH |
19597
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19596
diff
changeset
|
3072 |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3073 // GAGME: Accursed Matlab compatibility... |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3074 case btyp_char: |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3075 if (isextra) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3076 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
|
3077 else |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3078 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
|
3079 break; |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3080 |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3081 case btyp_bool: |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3082 if (arg.is_sparse_type ()) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3083 { |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3084 if (isnative) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3085 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
|
3086 else |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3087 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
|
3088 } |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3089 else if (isnative) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3090 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
|
3091 else |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3092 retval = arg.bool_array_value ().sum (dim); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3093 break; |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3094 |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3095 default: |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21078
diff
changeset
|
3096 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
|
3097 } |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
3098 |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
3099 return retval; |
523 | 3100 } |
3101 | |
7112 | 3102 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3103 %!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
|
3104 %!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
|
3105 %!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
|
3106 %!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
|
3107 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3108 %!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
|
3109 %!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
|
3110 %!assert (sum (single ([i, 2+i, -3+2i, 4])), single (3+4i)) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3111 %!assert (sum (single ([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i])), single ([2+2i, 4+4i, 6+6i])) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3112 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3113 %!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
|
3114 %!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
|
3115 %!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
|
3116 %!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
|
3117 %!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
|
3118 %!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
|
3119 %!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
|
3120 %!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
|
3121 %!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
|
3122 %!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
|
3123 %!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
|
3124 %!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
|
3125 %!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
|
3126 %!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
|
3127 %!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
|
3128 %!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
|
3129 %!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
|
3130 %!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
|
3131 %!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
|
3132 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3133 %!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
|
3134 %!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
|
3135 %!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
|
3136 %!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
|
3137 %!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
|
3138 %!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
|
3139 %!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
|
3140 %!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
|
3141 %!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
|
3142 %!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
|
3143 %!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
|
3144 %!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
|
3145 %!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
|
3146 %!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
|
3147 %!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
|
3148 %!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
|
3149 %!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
|
3150 %!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
|
3151 %!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
|
3152 |
18726
5baada25d5a2
Rewrite docstring of sum() to match prod().
Rik <rik@octave.org>
parents:
18725
diff
changeset
|
3153 ## Test "native" |
5baada25d5a2
Rewrite docstring of sum() to match prod().
Rik <rik@octave.org>
parents:
18725
diff
changeset
|
3154 %!assert (sum ([true,true]), 2) |
5baada25d5a2
Rewrite docstring of sum() to match prod().
Rik <rik@octave.org>
parents:
18725
diff
changeset
|
3155 %!assert (sum ([true,true], "native"), true) |
5baada25d5a2
Rewrite docstring of sum() to match prod().
Rik <rik@octave.org>
parents:
18725
diff
changeset
|
3156 %!assert (sum (int8 ([127,10,-20])), 117) |
5baada25d5a2
Rewrite docstring of sum() to match prod().
Rik <rik@octave.org>
parents:
18725
diff
changeset
|
3157 %!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
|
3158 |
15623
d928ad126b66
maint: add a new test for Fsum corresponding to cset e9d842dcfc91
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15621
diff
changeset
|
3159 ;-) |
d928ad126b66
maint: add a new test for Fsum corresponding to cset e9d842dcfc91
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15621
diff
changeset
|
3160 %!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
|
3161 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3162 %!error sum () |
18726
5baada25d5a2
Rewrite docstring of sum() to match prod().
Rik <rik@octave.org>
parents:
18725
diff
changeset
|
3163 %!error sum (1,2,3) |
5baada25d5a2
Rewrite docstring of sum() to match prod().
Rik <rik@octave.org>
parents:
18725
diff
changeset
|
3164 %!error <unrecognized type argument 'foobar'> sum (1, "foobar") |
7112 | 3165 */ |
3166 | |
1957 | 3167 DEFUN (sumsq, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3168 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
3169 @deftypefn {} {} sumsq (@var{x})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
3170 @deftypefnx {} {} sumsq (@var{x}, @var{dim})\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
3171 Sum of squares of elements along dimension @var{dim}.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
3172 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
3173 If @var{dim} is omitted, it defaults to the first non-singleton dimension.\n\ |
5061 | 3174 \n\ |
3175 This function is conceptually equivalent to computing\n\ | |
10840 | 3176 \n\ |
3723 | 3177 @example\n\ |
3178 sum (x .* conj (x), dim)\n\ | |
3179 @end example\n\ | |
10840 | 3180 \n\ |
10846
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10840
diff
changeset
|
3181 @noindent\n\ |
9163
9cb0c21e97f7
Update section 17.4 (Sums and Products) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9155
diff
changeset
|
3182 but it uses less memory and avoids calling @code{conj} if @var{x} is real.\n\ |
15028
397f0d80bd47
Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents:
15024
diff
changeset
|
3183 @seealso{sum, prod}\n\ |
3428 | 3184 @end deftypefn") |
523 | 3185 { |
3723 | 3186 DATA_REDUCTION (sumsq); |
523 | 3187 } |
3188 | |
7815
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
3189 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3190 %!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
|
3191 %!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
|
3192 %!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
|
3193 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3194 %!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
|
3195 %!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
|
3196 %!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
|
3197 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3198 %!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
|
3199 %!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
|
3200 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3201 %!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
|
3202 %!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
|
3203 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3204 %!error sumsq () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3205 */ |
7815
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
3206 |
6688 | 3207 DEFUN (islogical, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3208 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
3209 @deftypefn {} {} islogical (@var{x})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
3210 @deftypefnx {} {} isbool (@var{x})\n\ |
6688 | 3211 Return true if @var{x} is a logical object.\n\ |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11422
diff
changeset
|
3212 @seealso{isfloat, isinteger, ischar, isnumeric, isa}\n\ |
3439 | 3213 @end deftypefn") |
3209 | 3214 { |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3215 if (args.length () != 1) |
5823 | 3216 print_usage (); |
3209 | 3217 |
21127
df7891224709
maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents:
21121
diff
changeset
|
3218 return ovl (args(0).is_bool_type ()); |
3209 | 3219 } |
3220 | |
6688 | 3221 DEFALIAS (isbool, islogical); |
3209 | 3222 |
7815
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
3223 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3224 %!assert (islogical (true), true) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3225 %!assert (islogical (false), true) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3226 %!assert (islogical ([true, false]), true) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3227 %!assert (islogical (1), false) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3228 %!assert (islogical (1i), false) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3229 %!assert (islogical ([1,1]), false) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3230 %!assert (islogical (single (1)), false) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3231 %!assert (islogical (single (1i)), false) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3232 %!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
|
3233 %!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
|
3234 %!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
|
3235 */ |
7815
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
3236 |
6223 | 3237 DEFUN (isinteger, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3238 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
3239 @deftypefn {} {} isinteger (@var{x})\n\ |
6223 | 3240 Return true if @var{x} is an integer object (int8, uint8, int16, etc.).\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
3241 \n\ |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11422
diff
changeset
|
3242 Note that @w{@code{isinteger (14)}} is false because numeric constants in\n\ |
8429
f34ab2b433e8
One word missing from int8 help string.
Francesco Potortì <pot@gnu.org>
parents:
8366
diff
changeset
|
3243 Octave are double precision floating point values.\n\ |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11422
diff
changeset
|
3244 @seealso{isfloat, ischar, islogical, isnumeric, isa}\n\ |
6223 | 3245 @end deftypefn") |
3246 { | |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3247 if (args.length () != 1) |
6223 | 3248 print_usage (); |
3249 | |
21127
df7891224709
maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents:
21121
diff
changeset
|
3250 return ovl (args(0).is_integer_type ()); |
6223 | 3251 } |
3252 | |
4028 | 3253 DEFUN (iscomplex, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3254 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
3255 @deftypefn {} {} iscomplex (@var{x})\n\ |
3428 | 3256 Return true if @var{x} is a complex-valued numeric object.\n\ |
15028
397f0d80bd47
Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents:
15024
diff
changeset
|
3257 @seealso{isreal, isnumeric, islogical, ischar, isfloat, isa}\n\ |
3428 | 3258 @end deftypefn") |
3186 | 3259 { |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3260 if (args.length () != 1) |
5823 | 3261 print_usage (); |
3186 | 3262 |
21127
df7891224709
maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents:
21121
diff
changeset
|
3263 return ovl (args(0).is_complex_type ()); |
3186 | 3264 } |
3265 | |
7576 | 3266 DEFUN (isfloat, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3267 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
3268 @deftypefn {} {} isfloat (@var{x})\n\ |
7576 | 3269 Return true if @var{x} is a floating-point numeric object.\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
3270 \n\ |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11422
diff
changeset
|
3271 Objects of class double or single are floating-point objects.\n\ |
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11422
diff
changeset
|
3272 @seealso{isinteger, ischar, islogical, isnumeric, isa}\n\ |
7576 | 3273 @end deftypefn") |
3274 { | |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3275 if (args.length () != 1) |
7576 | 3276 print_usage (); |
3277 | |
21127
df7891224709
maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents:
21121
diff
changeset
|
3278 return ovl (args(0).is_float_type ()); |
7576 | 3279 } |
3280 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3281 // FIXME: perhaps this should be implemented with an |
5476 | 3282 // octave_value member function? |
3283 | |
3284 DEFUN (complex, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3285 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
3286 @deftypefn {} {} complex (@var{x})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
3287 @deftypefnx {} {} complex (@var{re}, @var{im})\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
3288 Return a complex value from real arguments.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
3289 \n\ |
20569
c6059134f5d3
data.cc: Add @w{} around @code segments in docstrings to prevent line breaks.
Rik <rik@octave.org>
parents:
20398
diff
changeset
|
3290 With 1 real argument @var{x}, return the complex result\n\ |
c6059134f5d3
data.cc: Add @w{} around @code segments in docstrings to prevent line breaks.
Rik <rik@octave.org>
parents:
20398
diff
changeset
|
3291 @w{@code{@var{x} + 0i}}.\n\ |
c6059134f5d3
data.cc: Add @w{} around @code segments in docstrings to prevent line breaks.
Rik <rik@octave.org>
parents:
20398
diff
changeset
|
3292 \n\ |
c6059134f5d3
data.cc: Add @w{} around @code segments in docstrings to prevent line breaks.
Rik <rik@octave.org>
parents:
20398
diff
changeset
|
3293 With 2 real arguments, return the complex result\n\ |
c6059134f5d3
data.cc: Add @w{} around @code segments in docstrings to prevent line breaks.
Rik <rik@octave.org>
parents:
20398
diff
changeset
|
3294 @w{@code{@var{re} + @var{im}}}.\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
3295 @code{complex} can often be more convenient than expressions such as\n\ |
20569
c6059134f5d3
data.cc: Add @w{} around @code segments in docstrings to prevent line breaks.
Rik <rik@octave.org>
parents:
20398
diff
changeset
|
3296 @w{@code{a + i*b}}.\n\ |
9309
fb8b8589dd46
Expand documentation for 'complex' function
Rik <rdrider0-list@yahoo.com>
parents:
9308
diff
changeset
|
3297 For example:\n\ |
fb8b8589dd46
Expand documentation for 'complex' function
Rik <rdrider0-list@yahoo.com>
parents:
9308
diff
changeset
|
3298 \n\ |
fb8b8589dd46
Expand documentation for 'complex' function
Rik <rdrider0-list@yahoo.com>
parents:
9308
diff
changeset
|
3299 @example\n\ |
9758
09da0bd91412
Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents:
9736
diff
changeset
|
3300 @group\n\ |
9309
fb8b8589dd46
Expand documentation for 'complex' function
Rik <rdrider0-list@yahoo.com>
parents:
9308
diff
changeset
|
3301 complex ([1, 2], [3, 4])\n\ |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
3302 @result{} [ 1 + 3i 2 + 4i ]\n\ |
9758
09da0bd91412
Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents:
9736
diff
changeset
|
3303 @end group\n\ |
9309
fb8b8589dd46
Expand documentation for 'complex' function
Rik <rdrider0-list@yahoo.com>
parents:
9308
diff
changeset
|
3304 @end example\n\ |
15028
397f0d80bd47
Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents:
15024
diff
changeset
|
3305 @seealso{real, imag, iscomplex, abs, arg}\n\ |
5476 | 3306 @end deftypefn") |
3307 { | |
3308 int nargin = args.length (); | |
3309 | |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3310 if (nargin < 1 || nargin > 2) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3311 print_usage (); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3312 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
3313 octave_value retval; |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
3314 |
5476 | 3315 if (nargin == 1) |
3316 { | |
3317 octave_value arg = args(0); | |
3318 | |
3319 if (arg.is_complex_type ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3320 retval = arg; |
5476 | 3321 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3322 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3323 if (arg.is_sparse_type ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3324 { |
20704
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
3325 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
|
3326 |
20562
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3327 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
|
3328 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3329 else if (arg.is_single_type ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3330 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3331 if (arg.numel () == 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3332 { |
20704
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
3333 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
|
3334 |
20562
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3335 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
|
3336 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3337 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3338 { |
20704
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
3339 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
|
3340 |
20562
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3341 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
|
3342 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3343 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3344 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3345 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3346 if (arg.numel () == 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3347 { |
20704
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
3348 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
|
3349 |
20562
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3350 retval = octave_value (new octave_complex (val)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3351 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3352 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3353 { |
20704
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
3354 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
|
3355 |
20562
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3356 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
|
3357 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3358 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3359 } |
5476 | 3360 } |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3361 else |
5476 | 3362 { |
3363 octave_value re = args(0); | |
3364 octave_value im = args(1); | |
3365 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7743
diff
changeset
|
3366 if (re.is_sparse_type () && im.is_sparse_type ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3367 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3368 const SparseMatrix re_val = re.sparse_matrix_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3369 const SparseMatrix im_val = im.sparse_matrix_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3370 |
20562
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3371 if (re.numel () == 1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3372 { |
20562
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3373 SparseComplexMatrix result; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3374 if (re_val.nnz () == 0) |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3375 result = Complex (0, 1) * SparseComplexMatrix (im_val); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3376 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3377 { |
20562
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3378 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
|
3379 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
|
3380 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
|
3381 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3382 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
|
3383 { |
20562
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3384 octave_idx_type off = j * nr; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3385 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
|
3386 i < im_val.cidx (j + 1); i++) |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3387 result.data (im_val.ridx (i) + off) += |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3388 Complex (0, im_val.data (i)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3389 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3390 } |
20562
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3391 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
|
3392 } |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3393 else if (im.numel () == 1) |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3394 { |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3395 SparseComplexMatrix result; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3396 if (im_val.nnz () == 0) |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3397 result = SparseComplexMatrix (re_val); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3398 else |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3399 { |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3400 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
|
3401 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
|
3402 result = SparseComplexMatrix (nr, nc, |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3403 Complex (0, im_val(0))); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3404 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3405 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
|
3406 { |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3407 octave_idx_type off = j * nr; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3408 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
|
3409 i < re_val.cidx (j + 1); i++) |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3410 result.data (re_val.ridx (i) + off) += |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3411 re_val.data (i); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3412 } |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3413 } |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3414 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
|
3415 } |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3416 else |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3417 { |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
3418 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
|
3419 error ("complex: dimension mismatch"); |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
3420 |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
3421 SparseComplexMatrix result; |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
3422 result = SparseComplexMatrix (re_val) |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
3423 + Complex (0, 1) * SparseComplexMatrix (im_val); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
3424 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
|
3425 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3426 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7743
diff
changeset
|
3427 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
|
3428 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3429 if (re.numel () == 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3430 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3431 float re_val = re.float_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3432 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3433 if (im.numel () == 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3434 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3435 float im_val = im.double_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3436 |
20562
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3437 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
|
3438 (FloatComplex (re_val, im_val))); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3439 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3440 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3441 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3442 const FloatNDArray im_val = im.float_array_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3443 |
20562
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3444 FloatComplexNDArray result (im_val.dims (), |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3445 FloatComplex ()); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3446 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3447 for (octave_idx_type i = 0; i < im_val.numel (); i++) |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3448 result.xelem (i) = FloatComplex (re_val, im_val(i)); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3449 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3450 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
|
3451 (result)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3452 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3453 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3454 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3455 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3456 const FloatNDArray re_val = re.float_array_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3457 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3458 if (im.numel () == 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3459 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3460 float im_val = im.float_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3461 |
20562
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3462 FloatComplexNDArray result (re_val.dims (), |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3463 FloatComplex ()); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3464 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3465 for (octave_idx_type i = 0; i < re_val.numel (); i++) |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3466 result.xelem (i) = FloatComplex (re_val(i), im_val); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3467 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3468 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
|
3469 (result)); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3470 } |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3471 else |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3472 { |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3473 const FloatNDArray im_val = im.float_array_value (); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3474 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
3475 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
|
3476 error ("complex: dimension mismatch"); |
20921
4d3daf7e43f3
eliminate trailing whitespace in source files
John W. Eaton <jwe@octave.org>
parents:
20918
diff
changeset
|
3477 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
3478 FloatComplexNDArray result (re_val.dims (), |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
3479 FloatComplex ()); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
3480 |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
3481 for (octave_idx_type i = 0; i < re_val.numel (); i++) |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
3482 result.xelem (i) = FloatComplex (re_val(i), |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
3483 im_val(i)); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
3484 |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
3485 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
|
3486 (result)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3487 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3488 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3489 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7743
diff
changeset
|
3490 else if (re.numel () == 1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3491 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3492 double re_val = re.double_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3493 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3494 if (im.numel () == 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3495 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3496 double im_val = im.double_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3497 |
20562
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3498 retval = octave_value (new octave_complex |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3499 (Complex (re_val, im_val))); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3500 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3501 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3502 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3503 const NDArray im_val = im.array_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3504 |
20562
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3505 ComplexNDArray result (im_val.dims (), Complex ()); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3506 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3507 for (octave_idx_type i = 0; i < im_val.numel (); i++) |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3508 result.xelem (i) = Complex (re_val, im_val(i)); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3509 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3510 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
|
3511 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3512 } |
5476 | 3513 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3514 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3515 const NDArray re_val = re.array_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3516 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3517 if (im.numel () == 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3518 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3519 double im_val = im.double_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3520 |
20562
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3521 ComplexNDArray result (re_val.dims (), Complex ()); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3522 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3523 for (octave_idx_type i = 0; i < re_val.numel (); i++) |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3524 result.xelem (i) = Complex (re_val(i), im_val); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3525 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3526 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
|
3527 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3528 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3529 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3530 const NDArray im_val = im.array_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3531 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
3532 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
|
3533 error ("complex: dimension mismatch"); |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
3534 |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
3535 ComplexNDArray result (re_val.dims (), Complex ()); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
3536 |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
3537 for (octave_idx_type i = 0; i < re_val.numel (); i++) |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
3538 result.xelem (i) = Complex (re_val(i), im_val(i)); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
3539 |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
3540 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
|
3541 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3542 } |
5476 | 3543 } |
3544 | |
3545 return retval; | |
3546 } | |
3547 | |
3258 | 3548 DEFUN (isreal, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3549 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
3550 @deftypefn {} {} isreal (@var{x})\n\ |
10291
fc879f361bda
make isreal matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10290
diff
changeset
|
3551 Return true if @var{x} is a non-complex matrix or scalar.\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
3552 \n\ |
10711
fbd7843974fa
Periodic grammar check of documentation files to ensure common format.
Rik <octave@nomad.inbox5.com>
parents:
10707
diff
changeset
|
3553 For compatibility with @sc{matlab}, this includes logical and character\n\ |
10291
fc879f361bda
make isreal matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10290
diff
changeset
|
3554 matrices.\n\ |
15028
397f0d80bd47
Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents:
15024
diff
changeset
|
3555 @seealso{iscomplex, isnumeric, isa}\n\ |
3428 | 3556 @end deftypefn") |
3258 | 3557 { |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3558 if (args.length () != 1) |
5823 | 3559 print_usage (); |
3258 | 3560 |
21127
df7891224709
maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents:
21121
diff
changeset
|
3561 return ovl (args(0).is_real_type ()); |
3258 | 3562 } |
3563 | |
3202 | 3564 DEFUN (isempty, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3565 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
3566 @deftypefn {} {} isempty (@var{a})\n\ |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11422
diff
changeset
|
3567 Return true if @var{a} is an empty matrix (any one of its dimensions is\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
3568 zero).\n\ |
15028
397f0d80bd47
Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents:
15024
diff
changeset
|
3569 @seealso{isnull, isa}\n\ |
3373 | 3570 @end deftypefn") |
3202 | 3571 { |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3572 if (args.length () != 1) |
5823 | 3573 print_usage (); |
3202 | 3574 |
21127
df7891224709
maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents:
21121
diff
changeset
|
3575 return ovl (args(0).is_empty ()); |
3202 | 3576 } |
3577 | |
16779
8fce0ed4894a
Specialize is_empty and numel methods for sparse matrices (debian bug #706376)
David Bateman <dbateman@free.fr>
parents:
16077
diff
changeset
|
3578 /* |
8fce0ed4894a
Specialize is_empty and numel methods for sparse matrices (debian bug #706376)
David Bateman <dbateman@free.fr>
parents:
16077
diff
changeset
|
3579 %% Debian bug #706376 |
8fce0ed4894a
Specialize is_empty and numel methods for sparse matrices (debian bug #706376)
David Bateman <dbateman@free.fr>
parents:
16077
diff
changeset
|
3580 %!assert (isempty (speye(2^16)), false) |
8fce0ed4894a
Specialize is_empty and numel methods for sparse matrices (debian bug #706376)
David Bateman <dbateman@free.fr>
parents:
16077
diff
changeset
|
3581 */ |
8fce0ed4894a
Specialize is_empty and numel methods for sparse matrices (debian bug #706376)
David Bateman <dbateman@free.fr>
parents:
16077
diff
changeset
|
3582 |
3206 | 3583 DEFUN (isnumeric, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3584 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
3585 @deftypefn {} {} isnumeric (@var{x})\n\ |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11422
diff
changeset
|
3586 Return true if @var{x} is a numeric object, i.e., an integer, real, or\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
3587 complex array.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
3588 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
3589 Logical and character arrays are not considered to be numeric.\n\ |
15028
397f0d80bd47
Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents:
15024
diff
changeset
|
3590 @seealso{isinteger, isfloat, isreal, iscomplex, islogical, ischar, iscell, isstruct, isa}\n\ |
3428 | 3591 @end deftypefn") |
3206 | 3592 { |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3593 if (args.length () != 1) |
5823 | 3594 print_usage (); |
3206 | 3595 |
21127
df7891224709
maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents:
21121
diff
changeset
|
3596 return ovl (args(0).is_numeric_type ()); |
3206 | 3597 } |
3598 | |
11435
20f53b3a558f
Add tests for sparse forms of logical matrices to islogical, isnumeric.
Rik <octave@nomad.inbox5.com>
parents:
11431
diff
changeset
|
3599 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3600 %!assert (isnumeric (1), true) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3601 %!assert (isnumeric (1i), true) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3602 %!assert (isnumeric ([1,1]), true) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3603 %!assert (isnumeric (single (1)), true) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3604 %!assert (isnumeric (single (1i)), true) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3605 %!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
|
3606 %!assert (isnumeric (int8 (1)), true) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3607 %!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
|
3608 %!assert (isnumeric ("Hello World"), false) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3609 %!assert (isnumeric (true), false) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3610 %!assert (isnumeric (false), false) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3611 %!assert (isnumeric ([true, false]), false) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3612 %!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
|
3613 */ |
20f53b3a558f
Add tests for sparse forms of logical matrices to islogical, isnumeric.
Rik <octave@nomad.inbox5.com>
parents:
11431
diff
changeset
|
3614 |
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
|
3615 DEFUN (isscalar, args, , |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19795
diff
changeset
|
3616 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
3617 @deftypefn {} {} isscalar (@var{x})\n\ |
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
|
3618 Return true if @var{x} is a scalar.\n\ |
bc52657a7d29
Convert isscalar from an m-file to a built-in function (bug #42422).
Jason Alan Palmer <jalanpalmer@gmail.com>
parents:
18812
diff
changeset
|
3619 @seealso{isvector, ismatrix}\n\ |
bc52657a7d29
Convert isscalar from an m-file to a built-in function (bug #42422).
Jason Alan Palmer <jalanpalmer@gmail.com>
parents:
18812
diff
changeset
|
3620 @end deftypefn") |
bc52657a7d29
Convert isscalar from an m-file to a built-in function (bug #42422).
Jason Alan Palmer <jalanpalmer@gmail.com>
parents:
18812
diff
changeset
|
3621 { |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3622 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
|
3623 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
|
3624 |
21127
df7891224709
maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents:
21121
diff
changeset
|
3625 return ovl (args(0).numel () == 1); |
18813
bc52657a7d29
Convert isscalar from an m-file to a built-in function (bug #42422).
Jason Alan Palmer <jalanpalmer@gmail.com>
parents:
18812
diff
changeset
|
3626 } |
bc52657a7d29
Convert isscalar from an m-file to a built-in function (bug #42422).
Jason Alan Palmer <jalanpalmer@gmail.com>
parents:
18812
diff
changeset
|
3627 |
bc52657a7d29
Convert isscalar from an m-file to a built-in function (bug #42422).
Jason Alan Palmer <jalanpalmer@gmail.com>
parents:
18812
diff
changeset
|
3628 /* |
bc52657a7d29
Convert isscalar from an m-file to a built-in function (bug #42422).
Jason Alan Palmer <jalanpalmer@gmail.com>
parents:
18812
diff
changeset
|
3629 %!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
|
3630 %!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
|
3631 %!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
|
3632 %!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
|
3633 |
bc52657a7d29
Convert isscalar from an m-file to a built-in function (bug #42422).
Jason Alan Palmer <jalanpalmer@gmail.com>
parents:
18812
diff
changeset
|
3634 %!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
|
3635 %!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
|
3636 %!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
|
3637 |
bc52657a7d29
Convert isscalar from an m-file to a built-in function (bug #42422).
Jason Alan Palmer <jalanpalmer@gmail.com>
parents:
18812
diff
changeset
|
3638 %!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
|
3639 %! 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
|
3640 %! 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
|
3641 |
bc52657a7d29
Convert isscalar from an m-file to a built-in function (bug #42422).
Jason Alan Palmer <jalanpalmer@gmail.com>
parents:
18812
diff
changeset
|
3642 %% Test input validation |
bc52657a7d29
Convert isscalar from an m-file to a built-in function (bug #42422).
Jason Alan Palmer <jalanpalmer@gmail.com>
parents:
18812
diff
changeset
|
3643 %!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
|
3644 %!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
|
3645 */ |
bc52657a7d29
Convert isscalar from an m-file to a built-in function (bug #42422).
Jason Alan Palmer <jalanpalmer@gmail.com>
parents:
18812
diff
changeset
|
3646 |
18814
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3647 DEFUN (isvector, args, , |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19795
diff
changeset
|
3648 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
3649 @deftypefn {} {} isvector (@var{x})\n\ |
18814
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3650 Return true if @var{x} is a vector.\n\ |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3651 \n\ |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3652 A vector is a 2-D array where one of the dimensions is equal to 1. As a\n\ |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3653 consequence a 1x1 array, or scalar, is also a vector.\n\ |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3654 @seealso{isscalar, ismatrix, size, rows, columns, length}\n\ |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3655 @end deftypefn") |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3656 { |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3657 if (args.length () != 1) |
18814
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3658 print_usage (); |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3659 |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3660 dim_vector sz = args(0).dims (); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3661 |
21127
df7891224709
maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents:
21121
diff
changeset
|
3662 return ovl (sz.length () == 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
|
3663 } |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3664 |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3665 /* |
19700
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19697
diff
changeset
|
3666 %!assert (isvector (1), true) |
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19697
diff
changeset
|
3667 %!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
|
3668 %!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
|
3669 %!assert (isvector ([]), false) |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3670 %!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
|
3671 |
19700
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19697
diff
changeset
|
3672 %!assert (isvector ("t"), true) |
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19697
diff
changeset
|
3673 %!assert (isvector ("test"), true) |
18814
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3674 %!assert (isvector (["test"; "ing"]), false) |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3675 |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3676 %!test |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3677 %! s.a = 1; |
19700
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19697
diff
changeset
|
3678 %! assert (isvector (s), true); |
18814
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3679 |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3680 %% Test input validation |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3681 %!error isvector () |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3682 %!error isvector ([1, 2], 2) |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3683 */ |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3684 |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3685 DEFUN (isrow, args, , |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19795
diff
changeset
|
3686 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
3687 @deftypefn {} {} isrow (@var{x})\n\ |
19795
ca7599ae464d
doc: Grammarcheck documentation ahead of 4.0 release.
Rik <rik@octave.org>
parents:
19749
diff
changeset
|
3688 Return true if @var{x} is a row vector 1xN with non-negative N.\n\ |
18814
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3689 @seealso{iscolumn, isscalar, isvector, ismatrix}\n\ |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3690 @end deftypefn") |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3691 { |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3692 if (args.length () != 1) |
18814
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3693 print_usage (); |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3694 |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3695 dim_vector sz = args(0).dims (); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3696 |
21127
df7891224709
maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents:
21121
diff
changeset
|
3697 return ovl (sz.length () == 2 && sz(0) == 1); |
18814
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3698 } |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3699 |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3700 /* |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3701 %!assert (isrow ([1, 2, 3])) |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3702 %!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
|
3703 %!assert (isrow (1)) |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3704 %!assert (isrow ([]), false) |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3705 %!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
|
3706 |
19700
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19697
diff
changeset
|
3707 %!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
|
3708 %!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
|
3709 %!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
|
3710 %!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
|
3711 %!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
|
3712 |
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19697
diff
changeset
|
3713 %!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
|
3714 %!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
|
3715 |
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19697
diff
changeset
|
3716 |
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19697
diff
changeset
|
3717 %!assert (isrow ("t"), true) |
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19697
diff
changeset
|
3718 %!assert (isrow ("test"), true) |
18814
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3719 %!assert (isrow (["test"; "ing"]), false) |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3720 |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3721 %!test |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3722 %! s.a = 1; |
19700
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19697
diff
changeset
|
3723 %! assert (isrow (s), true); |
18814
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3724 |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3725 %% Test input validation |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3726 %!error isrow () |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3727 %!error isrow ([1, 2], 2) |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3728 */ |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3729 |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3730 DEFUN (iscolumn, args, , |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19795
diff
changeset
|
3731 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
3732 @deftypefn {} {} iscolumn (@var{x})\n\ |
19795
ca7599ae464d
doc: Grammarcheck documentation ahead of 4.0 release.
Rik <rik@octave.org>
parents:
19749
diff
changeset
|
3733 Return true if @var{x} is a column vector Nx1 with non-negative N.\n\ |
18814
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3734 @seealso{isrow, isscalar, isvector, ismatrix}\n\ |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3735 @end deftypefn") |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3736 { |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3737 if (args.length () != 1) |
18814
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3738 print_usage (); |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3739 |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3740 dim_vector sz = args(0).dims (); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3741 |
21127
df7891224709
maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents:
21121
diff
changeset
|
3742 return ovl (sz.length () == 2 && sz(1) == 1); |
18814
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3743 } |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3744 |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3745 /* |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3746 %!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
|
3747 %!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
|
3748 %!assert (iscolumn (1), true) |
18814
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3749 %!assert (iscolumn ([]), false) |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3750 %!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
|
3751 |
19700
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19697
diff
changeset
|
3752 %!assert (iscolumn ("t"), true) |
18814
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3753 %!assert (iscolumn ("test"), false) |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3754 %!assert (iscolumn (["test"; "ing"]), false) |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3755 |
19700
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19697
diff
changeset
|
3756 %!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
|
3757 %!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
|
3758 %!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
|
3759 %!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
|
3760 %!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
|
3761 |
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19697
diff
changeset
|
3762 %!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
|
3763 %!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
|
3764 |
18814
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3765 %!test |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3766 %! s.a = 1; |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3767 %! assert (iscolumn (s)); |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3768 |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3769 %% Test input validation |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3770 %!error iscolumn () |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3771 %!error iscolumn ([1, 2], 2) |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3772 */ |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3773 |
4028 | 3774 DEFUN (ismatrix, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3775 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
3776 @deftypefn {} {} ismatrix (@var{a})\n\ |
19795
ca7599ae464d
doc: Grammarcheck documentation ahead of 4.0 release.
Rik <rik@octave.org>
parents:
19749
diff
changeset
|
3777 Return true if @var{a} is a 2-D array.\n\ |
15028
397f0d80bd47
Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents:
15024
diff
changeset
|
3778 @seealso{isscalar, isvector, iscell, isstruct, issparse, isa}\n\ |
3333 | 3779 @end deftypefn") |
3202 | 3780 { |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3781 if (args.length () != 1) |
5823 | 3782 print_usage (); |
3202 | 3783 |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3784 dim_vector sz = args(0).dims (); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3785 |
21127
df7891224709
maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents:
21121
diff
changeset
|
3786 return ovl (sz.length () == 2 && sz(0) >= 0 && sz(1) >= 0); |
3202 | 3787 } |
3788 | |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3789 /* |
19700
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19697
diff
changeset
|
3790 %!assert (ismatrix ([]), true) |
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19697
diff
changeset
|
3791 %!assert (ismatrix (1), true) |
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19697
diff
changeset
|
3792 %!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
|
3793 %!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
|
3794 |
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19697
diff
changeset
|
3795 %!assert (ismatrix (zeros (0)), true) |
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19697
diff
changeset
|
3796 %!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
|
3797 %!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
|
3798 %!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
|
3799 |
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19697
diff
changeset
|
3800 %!assert (ismatrix (single ([])), true) |
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19697
diff
changeset
|
3801 %!assert (ismatrix (single (1)), true) |
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19697
diff
changeset
|
3802 %!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
|
3803 %!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
|
3804 |
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19697
diff
changeset
|
3805 %!assert (ismatrix ("t"), true) |
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19697
diff
changeset
|
3806 %!assert (ismatrix ("test"), true) |
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19697
diff
changeset
|
3807 %!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
|
3808 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3809 %!test |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3810 %! s.a = 1; |
19700
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19697
diff
changeset
|
3811 %! assert (ismatrix (s), true); |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3812 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3813 %!error ismatrix () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3814 %!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
|
3815 */ |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3816 |
18814
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3817 DEFUN (issquare, args, , |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19795
diff
changeset
|
3818 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
3819 @deftypefn {} {} issquare (@var{x})\n\ |
18814
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3820 Return true if @var{x} is a square matrix.\n\ |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3821 @seealso{isscalar, isvector, ismatrix, size}\n\ |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3822 @end deftypefn") |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3823 { |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3824 if (args.length () != 1) |
18814
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3825 print_usage (); |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3826 |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3827 dim_vector sz = args(0).dims (); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
3828 |
21127
df7891224709
maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents:
21121
diff
changeset
|
3829 return ovl (sz.length () == 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
|
3830 } |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3831 |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3832 /* |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3833 %!assert (issquare ([])) |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3834 %!assert (issquare (1)) |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3835 %!assert (! issquare ([1, 2])) |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3836 %!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
|
3837 %!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
|
3838 %!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
|
3839 %!assert (issquare ("t")) |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3840 %!assert (! issquare ("test")) |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3841 %!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
|
3842 %!test |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3843 %! s.a = 1; |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3844 %! assert (issquare (s)); |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3845 %!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
|
3846 %!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
|
3847 |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3848 %% Test input validation |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3849 %!error issquare () |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3850 %!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
|
3851 */ |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
18813
diff
changeset
|
3852 |
3354 | 3853 static octave_value |
5747 | 3854 fill_matrix (const octave_value_list& args, int val, const char *fcn) |
523 | 3855 { |
3354 | 3856 octave_value retval; |
523 | 3857 |
3858 int nargin = args.length (); | |
3859 | |
4946 | 3860 oct_data_conv::data_type dt = oct_data_conv::dt_double; |
4481 | 3861 |
4946 | 3862 dim_vector dims (1, 1); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
3863 |
4481 | 3864 if (nargin > 0 && args(nargin-1).is_string ()) |
3865 { | |
4946 | 3866 std::string nm = args(nargin-1).string_value (); |
4481 | 3867 nargin--; |
3868 | |
4946 | 3869 dt = oct_data_conv::string_to_data_type (nm); |
4481 | 3870 } |
3871 | |
523 | 3872 switch (nargin) |
3873 { | |
712 | 3874 case 0: |
3875 break; | |
777 | 3876 |
610 | 3877 case 1: |
4481 | 3878 get_dimensions (args(0), fcn, dims); |
610 | 3879 break; |
777 | 3880 |
4563 | 3881 default: |
3882 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3883 dims.resize (nargin); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3884 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3885 for (int i = 0; i < nargin; i++) |
20704
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
3886 dims(i) = (args(i).is_empty () |
20711
7b608fadc663
Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents:
20704
diff
changeset
|
3887 ? 0 : args(i).xidx_type_value ("%s: dimension arguments must be scalar integers", fcn)); |
4563 | 3888 } |
3889 break; | |
4481 | 3890 } |
3891 | |
20562
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3892 dims.chop_trailing_singletons (); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3893 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3894 check_dimensions (dims, fcn); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3895 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3896 // FIXME: perhaps this should be made extensible by |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3897 // using the class name to lookup a function to call to create |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3898 // the new value. |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3899 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3900 // 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
|
3901 // NDArray to scalar. |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3902 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3903 switch (dt) |
4481 | 3904 { |
20562
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3905 case oct_data_conv::dt_int8: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3906 retval = int8NDArray (dims, val); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3907 break; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3908 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3909 case oct_data_conv::dt_uint8: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3910 retval = uint8NDArray (dims, val); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3911 break; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3912 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3913 case oct_data_conv::dt_int16: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3914 retval = int16NDArray (dims, val); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3915 break; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3916 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3917 case oct_data_conv::dt_uint16: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3918 retval = uint16NDArray (dims, val); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3919 break; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3920 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3921 case oct_data_conv::dt_int32: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3922 retval = int32NDArray (dims, val); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3923 break; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3924 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3925 case oct_data_conv::dt_uint32: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3926 retval = uint32NDArray (dims, val); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3927 break; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3928 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3929 case oct_data_conv::dt_int64: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3930 retval = int64NDArray (dims, val); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3931 break; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3932 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3933 case oct_data_conv::dt_uint64: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3934 retval = uint64NDArray (dims, val); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3935 break; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3936 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3937 case oct_data_conv::dt_single: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3938 retval = FloatNDArray (dims, val); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3939 break; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3940 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3941 case oct_data_conv::dt_double: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3942 { |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3943 if (val == 1 && dims.length () == 2 && dims(0) == 1) |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3944 retval = Range (1.0, 0.0, dims(1)); // packed form |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3945 else |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3946 retval = NDArray (dims, val); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3947 } |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3948 break; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3949 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3950 case oct_data_conv::dt_logical: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3951 retval = boolNDArray (dims, val); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3952 break; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3953 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3954 default: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3955 error ("%s: invalid class name", fcn); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
3956 break; |
523 | 3957 } |
3958 | |
3959 return retval; | |
3960 } | |
3961 | |
5747 | 3962 static octave_value |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
3963 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
|
3964 const char *fcn) |
7795
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3965 { |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3966 octave_value retval; |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3967 |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3968 int nargin = args.length (); |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3969 |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3970 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
|
3971 |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3972 dim_vector dims (1, 1); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
3973 |
7795
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3974 if (nargin > 0 && args(nargin-1).is_string ()) |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3975 { |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3976 std::string nm = args(nargin-1).string_value (); |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3977 nargin--; |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3978 |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3979 dt = oct_data_conv::string_to_data_type (nm); |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3980 } |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3981 |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3982 switch (nargin) |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3983 { |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3984 case 0: |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3985 break; |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3986 |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3987 case 1: |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3988 get_dimensions (args(0), fcn, dims); |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3989 break; |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3990 |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3991 default: |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3992 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3993 dims.resize (nargin); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3994 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3995 for (int i = 0; i < nargin; i++) |
20704
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
3996 dims(i) = (args(i).is_empty () |
20711
7b608fadc663
Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents:
20704
diff
changeset
|
3997 ? 0 : args(i).xidx_type_value ("%s: dimension arguments must be scalar integers", fcn)); |
7795
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3998 } |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3999 break; |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4000 } |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4001 |
20562
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4002 dims.chop_trailing_singletons (); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4003 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4004 check_dimensions (dims, fcn); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4005 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4006 // 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
|
4007 // NDArray to scalar. |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4008 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4009 switch (dt) |
7795
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4010 { |
20562
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4011 case oct_data_conv::dt_single: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4012 retval = FloatNDArray (dims, fval); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4013 break; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4014 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4015 case oct_data_conv::dt_double: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4016 retval = NDArray (dims, val); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4017 break; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4018 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4019 default: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4020 error ("%s: invalid class name", fcn); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4021 break; |
7795
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4022 } |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4023 |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4024 return retval; |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4025 } |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4026 |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4027 static octave_value |
5747 | 4028 fill_matrix (const octave_value_list& args, double val, const char *fcn) |
4029 { | |
4030 octave_value retval; | |
4031 | |
4032 int nargin = args.length (); | |
4033 | |
4034 oct_data_conv::data_type dt = oct_data_conv::dt_double; | |
4035 | |
4036 dim_vector dims (1, 1); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
4037 |
5747 | 4038 if (nargin > 0 && args(nargin-1).is_string ()) |
4039 { | |
4040 std::string nm = args(nargin-1).string_value (); | |
4041 nargin--; | |
4042 | |
4043 dt = oct_data_conv::string_to_data_type (nm); | |
4044 } | |
4045 | |
4046 switch (nargin) | |
4047 { | |
4048 case 0: | |
4049 break; | |
4050 | |
4051 case 1: | |
4052 get_dimensions (args(0), fcn, dims); | |
4053 break; | |
4054 | |
4055 default: | |
4056 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4057 dims.resize (nargin); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4058 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4059 for (int i = 0; i < nargin; i++) |
20704
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
4060 dims(i) = (args(i).is_empty () |
20711
7b608fadc663
Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents:
20704
diff
changeset
|
4061 ? 0 : args(i).xidx_type_value ("%s: dimension arguments must be scalar integers", fcn)); |
5747 | 4062 } |
4063 break; | |
4064 } | |
4065 | |
20562
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4066 dims.chop_trailing_singletons (); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4067 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4068 check_dimensions (dims, fcn); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4069 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4070 // 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
|
4071 // NDArray to scalar. |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4072 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4073 switch (dt) |
5747 | 4074 { |
20562
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4075 case oct_data_conv::dt_single: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4076 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
|
4077 break; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4078 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4079 case oct_data_conv::dt_double: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4080 retval = NDArray (dims, val); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4081 break; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4082 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4083 default: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4084 error ("%s: invalid class name", fcn); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4085 break; |
5747 | 4086 } |
4087 | |
4088 return retval; | |
4089 } | |
4090 | |
4091 static octave_value | |
4092 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
|
4093 const char *fcn) |
5747 | 4094 { |
4095 octave_value retval; | |
4096 | |
4097 int nargin = args.length (); | |
4098 | |
4099 oct_data_conv::data_type dt = oct_data_conv::dt_double; | |
4100 | |
4101 dim_vector dims (1, 1); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
4102 |
5747 | 4103 if (nargin > 0 && args(nargin-1).is_string ()) |
4104 { | |
4105 std::string nm = args(nargin-1).string_value (); | |
4106 nargin--; | |
4107 | |
4108 dt = oct_data_conv::string_to_data_type (nm); | |
4109 } | |
4110 | |
4111 switch (nargin) | |
4112 { | |
4113 case 0: | |
4114 break; | |
4115 | |
4116 case 1: | |
4117 get_dimensions (args(0), fcn, dims); | |
4118 break; | |
4119 | |
4120 default: | |
4121 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4122 dims.resize (nargin); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4123 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4124 for (int i = 0; i < nargin; i++) |
20704
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
4125 dims(i) = (args(i).is_empty () |
20711
7b608fadc663
Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents:
20704
diff
changeset
|
4126 ? 0 : args(i).xidx_type_value ("%s: dimension arguments must be scalar integers", fcn)); |
5747 | 4127 } |
4128 break; | |
4129 } | |
4130 | |
20562
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4131 dims.chop_trailing_singletons (); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4132 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4133 check_dimensions (dims, fcn); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4134 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4135 // 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
|
4136 // NDArray to scalar. |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4137 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4138 switch (dt) |
5747 | 4139 { |
20562
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4140 case oct_data_conv::dt_single: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4141 retval = FloatComplexNDArray (dims, |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4142 static_cast<FloatComplex> (val)); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4143 break; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4144 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4145 case oct_data_conv::dt_double: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4146 retval = ComplexNDArray (dims, val); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4147 break; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4148 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4149 default: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4150 error ("%s: invalid class name", fcn); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4151 break; |
5747 | 4152 } |
4153 | |
4154 return retval; | |
4155 } | |
4156 | |
4157 static octave_value | |
4158 fill_matrix (const octave_value_list& args, bool val, const char *fcn) | |
4159 { | |
4160 octave_value retval; | |
4161 | |
4162 int nargin = args.length (); | |
4163 | |
4164 dim_vector dims (1, 1); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
4165 |
5747 | 4166 switch (nargin) |
4167 { | |
4168 case 0: | |
4169 break; | |
4170 | |
4171 case 1: | |
4172 get_dimensions (args(0), fcn, dims); | |
4173 break; | |
4174 | |
4175 default: | |
4176 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4177 dims.resize (nargin); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4178 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4179 for (int i = 0; i < nargin; i++) |
20704
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20700
diff
changeset
|
4180 dims(i) = (args(i).is_empty () |
20711
7b608fadc663
Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents:
20704
diff
changeset
|
4181 ? 0 : args(i).xidx_type_value ("%s: dimension arguments must be scalar integers", fcn)); |
5747 | 4182 } |
4183 break; | |
4184 } | |
4185 | |
20562
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4186 dims.chop_trailing_singletons (); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4187 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4188 check_dimensions (dims, fcn); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4189 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4190 // 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
|
4191 // NDArray to scalar. |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4192 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4193 retval = boolNDArray (dims, val); |
5747 | 4194 |
4195 return retval; | |
4196 } | |
4197 | |
3354 | 4198 DEFUN (ones, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
4199 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
4200 @deftypefn {} {} ones (@var{n})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
4201 @deftypefnx {} {} ones (@var{m}, @var{n})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
4202 @deftypefnx {} {} ones (@var{m}, @var{n}, @var{k}, @dots{})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
4203 @deftypefnx {} {} ones ([@var{m} @var{n} @dots{}])\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
4204 @deftypefnx {} {} ones (@dots{}, @var{class})\n\ |
4481 | 4205 Return a matrix or N-dimensional array whose elements are all 1.\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4206 \n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
4207 If invoked with a single scalar integer argument @var{n}, return a square\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4208 @nospell{NxN} matrix.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4209 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4210 If invoked with two or more scalar integer arguments, or a vector of integer\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4211 values, return an array with the given dimensions.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4212 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4213 To create a constant matrix whose values are all the same use an expression\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4214 such as\n\ |
3369 | 4215 \n\ |
4216 @example\n\ | |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
4217 val_matrix = val * ones (m, n)\n\ |
3369 | 4218 @end example\n\ |
4945 | 4219 \n\ |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
4220 The optional argument @var{class} specifies the class of the return array\n\ |
10840 | 4221 and defaults to double. For example:\n\ |
4945 | 4222 \n\ |
4223 @example\n\ | |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
4224 val = ones (m,n, \"uint8\")\n\ |
4945 | 4225 @end example\n\ |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
4226 @seealso{zeros}\n\ |
3369 | 4227 @end deftypefn") |
523 | 4228 { |
5747 | 4229 return fill_matrix (args, 1, "ones"); |
523 | 4230 } |
4231 | |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4232 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4233 %!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
|
4234 %!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
|
4235 %!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
|
4236 %!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
|
4237 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4238 %!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
|
4239 %!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
|
4240 %!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
|
4241 %!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
|
4242 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4243 %!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
|
4244 %!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
|
4245 %!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
|
4246 %!assert (size (ones (3, 4, 5, "int8")), [3, 4, 5]) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4247 */ |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4248 |
3354 | 4249 DEFUN (zeros, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
4250 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
4251 @deftypefn {} {} zeros (@var{n})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
4252 @deftypefnx {} {} zeros (@var{m}, @var{n})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
4253 @deftypefnx {} {} zeros (@var{m}, @var{n}, @var{k}, @dots{})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
4254 @deftypefnx {} {} zeros ([@var{m} @var{n} @dots{}])\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
4255 @deftypefnx {} {} zeros (@dots{}, @var{class})\n\ |
4481 | 4256 Return a matrix or N-dimensional array whose elements are all 0.\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4257 \n\ |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
4258 If invoked with a single scalar integer argument, return a square\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4259 @nospell{NxN} matrix.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4260 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4261 If invoked with two or more scalar integer arguments, or a vector of integer\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4262 values, return an array with the given dimensions.\n\ |
4945 | 4263 \n\ |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
4264 The optional argument @var{class} specifies the class of the return array\n\ |
10840 | 4265 and defaults to double. For example:\n\ |
4945 | 4266 \n\ |
4267 @example\n\ | |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
4268 val = zeros (m,n, \"uint8\")\n\ |
4945 | 4269 @end example\n\ |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
4270 @seealso{ones}\n\ |
3369 | 4271 @end deftypefn") |
523 | 4272 { |
5747 | 4273 return fill_matrix (args, 0, "zeros"); |
4274 } | |
4275 | |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4276 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4277 %!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
|
4278 %!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
|
4279 %!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
|
4280 %!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
|
4281 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4282 %!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
|
4283 %!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
|
4284 %!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
|
4285 %!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
|
4286 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4287 %!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
|
4288 %!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
|
4289 %!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
|
4290 %!assert (size (zeros (3, 4, 5, "int8")), [3, 4, 5]) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4291 */ |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4292 |
5747 | 4293 DEFUN (Inf, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
4294 "-*- texinfo -*-\n\ |
14171
2ced2f59f523
doc: miscellaneous documentation improvements
Rik <octave@nomad.inbox5.com>
parents:
14169
diff
changeset
|
4295 @c List other form of function in documentation index\n\ |
2ced2f59f523
doc: miscellaneous documentation improvements
Rik <octave@nomad.inbox5.com>
parents:
14169
diff
changeset
|
4296 @findex inf\n\ |
2ced2f59f523
doc: miscellaneous documentation improvements
Rik <octave@nomad.inbox5.com>
parents:
14169
diff
changeset
|
4297 \n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
4298 @deftypefn {} {} Inf\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
4299 @deftypefnx {} {} Inf (@var{n})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
4300 @deftypefnx {} {} Inf (@var{n}, @var{m})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
4301 @deftypefnx {} {} Inf (@var{n}, @var{m}, @var{k}, @dots{})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
4302 @deftypefnx {} {} Inf (@dots{}, @var{class})\n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4303 Return a scalar, matrix or N-dimensional array whose elements are all equal\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4304 to the IEEE representation for positive infinity.\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4305 \n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4306 Infinity is produced when results are too large to be represented using the\n\ |
20183
4e7f12a763cd
doc: Remove typo of same word twice in a row.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
4307 IEEE floating point format for numbers. Two common examples which produce\n\ |
4e7f12a763cd
doc: Remove typo of same word twice in a row.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
4308 infinity are division by zero and overflow.\n\ |
10840 | 4309 \n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4310 @example\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4311 @group\n\ |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
4312 [ 1/0 e^800 ]\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
4313 @result{} Inf Inf\n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4314 @end group\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4315 @end example\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4316 \n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4317 When called with no arguments, return a scalar with the value @samp{Inf}.\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4318 \n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4319 When called with a single argument, return a square matrix with the dimension\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4320 specified.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4321 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4322 When called with more than one scalar argument the first two arguments are\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4323 taken as the number of rows and columns and any further arguments specify\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4324 additional matrix dimensions.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4325 \n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4326 The optional argument @var{class} specifies the return type and may be\n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17268
diff
changeset
|
4327 either @qcode{\"double\"} or @qcode{\"single\"}.\n\ |
15034
1116864ee270
doc: Fix for bad cross-referencing due to use of aliases in Texinfo.
Rik <rik@octave.org>
parents:
15031
diff
changeset
|
4328 @seealso{isinf, NaN}\n\ |
5747 | 4329 @end deftypefn") |
4330 { | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
4331 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
|
4332 lo_ieee_float_inf_value (), "Inf"); |
5747 | 4333 } |
4334 | |
4335 DEFALIAS (inf, Inf); | |
4336 | |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4337 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4338 %!assert (inf (3), [Inf, Inf, Inf; Inf, Inf, Inf; Inf, Inf, Inf]) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4339 %!assert (inf (2, 3), [Inf, Inf, Inf; Inf, Inf, Inf]) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4340 %!assert (inf (3, 2), [Inf, Inf; Inf, Inf; Inf, Inf]) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4341 %!assert (size (inf (3, 4, 5)), [3, 4, 5]) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4342 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4343 %!assert (inf (3, "single"), single ([Inf, Inf, Inf; Inf, Inf, Inf; Inf, Inf, Inf])) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4344 %!assert (inf (2, 3, "single"), single ([Inf, Inf, Inf; Inf, Inf, Inf])) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4345 %!assert (inf (3, 2, "single"), single ([Inf, Inf; Inf, Inf; Inf, Inf])) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4346 %!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
|
4347 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4348 %!error (inf (3, "int8")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4349 %!error (inf (2, 3, "int8")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4350 %!error (inf (3, 2, "int8")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4351 %!error (inf (3, 4, 5, "int8")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4352 */ |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4353 |
5747 | 4354 DEFUN (NaN, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
4355 "-*- texinfo -*-\n\ |
14171
2ced2f59f523
doc: miscellaneous documentation improvements
Rik <octave@nomad.inbox5.com>
parents:
14169
diff
changeset
|
4356 @c List other form of function in documentation index\n\ |
2ced2f59f523
doc: miscellaneous documentation improvements
Rik <octave@nomad.inbox5.com>
parents:
14169
diff
changeset
|
4357 @findex nan\n\ |
2ced2f59f523
doc: miscellaneous documentation improvements
Rik <octave@nomad.inbox5.com>
parents:
14169
diff
changeset
|
4358 \n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
4359 @deftypefn {} {} NaN\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
4360 @deftypefnx {} {} NaN (@var{n})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
4361 @deftypefnx {} {} NaN (@var{n}, @var{m})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
4362 @deftypefnx {} {} NaN (@var{n}, @var{m}, @var{k}, @dots{})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
4363 @deftypefnx {} {} NaN (@dots{}, @var{class})\n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4364 Return a scalar, matrix, or N-dimensional array whose elements are all equal\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4365 to the IEEE symbol NaN (Not a Number).\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4366 \n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4367 NaN is the result of operations which do not produce a well defined numerical\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4368 result. Common operations which produce a NaN are arithmetic with infinity\n\ |
5747 | 4369 @tex\n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4370 ($\\infty - \\infty$), zero divided by zero ($0/0$),\n\ |
5747 | 4371 @end tex\n\ |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
8487
diff
changeset
|
4372 @ifnottex\n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4373 (Inf - Inf), zero divided by zero (0/0),\n\ |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
8487
diff
changeset
|
4374 @end ifnottex\n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4375 and any operation involving another NaN value (5 + NaN).\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4376 \n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4377 Note that NaN always compares not equal to NaN (NaN != NaN). This behavior\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4378 is specified by the IEEE standard for floating point arithmetic. To find\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4379 NaN values, use the @code{isnan} function.\n\ |
5747 | 4380 \n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4381 When called with no arguments, return a scalar with the value @samp{NaN}.\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4382 \n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4383 When called with a single argument, return a square matrix with the dimension\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4384 specified.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4385 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4386 When called with more than one scalar argument the first two arguments are\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4387 taken as the number of rows and columns and any further arguments specify\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4388 additional matrix dimensions.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4389 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4390 \n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4391 The optional argument @var{class} specifies the return type and may be\n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17268
diff
changeset
|
4392 either @qcode{\"double\"} or @qcode{\"single\"}.\n\ |
15034
1116864ee270
doc: Fix for bad cross-referencing due to use of aliases in Texinfo.
Rik <rik@octave.org>
parents:
15031
diff
changeset
|
4393 @seealso{isnan, Inf}\n\ |
5747 | 4394 @end deftypefn") |
4395 { | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
4396 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
|
4397 lo_ieee_float_nan_value (), "NaN"); |
5747 | 4398 } |
4399 | |
4400 DEFALIAS (nan, NaN); | |
4401 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
4402 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4403 %!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
|
4404 %!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
|
4405 %!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
|
4406 %!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
|
4407 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4408 %!assert (NaN (3, "single"), single ([NaN, NaN, NaN; NaN, NaN, NaN; NaN, NaN, NaN])) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4409 %!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
|
4410 %!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
|
4411 %!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
|
4412 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4413 %!error (NaN (3, "int8")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4414 %!error (NaN (2, 3, "int8")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4415 %!error (NaN (3, 2, "int8")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4416 %!error (NaN (3, 4, 5, "int8")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4417 */ |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4418 |
5747 | 4419 DEFUN (e, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
4420 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
4421 @deftypefn {} {} e\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
4422 @deftypefnx {} {} e (@var{n})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
4423 @deftypefnx {} {} e (@var{n}, @var{m})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
4424 @deftypefnx {} {} e (@var{n}, @var{m}, @var{k}, @dots{})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
4425 @deftypefnx {} {} e (@dots{}, @var{class})\n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4426 Return a scalar, matrix, or N-dimensional array whose elements are all equal\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4427 to the base of natural logarithms.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4428 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4429 The constant\n\ |
5747 | 4430 @tex\n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4431 $e$ satisfies the equation $\\log (e) = 1$.\n\ |
5747 | 4432 @end tex\n\ |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
8487
diff
changeset
|
4433 @ifnottex\n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4434 @samp{e} satisfies the equation @code{log} (e) = 1.\n\ |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
8487
diff
changeset
|
4435 @end ifnottex\n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4436 \n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4437 When called with no arguments, return a scalar with the value @math{e}.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4438 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4439 When called with a single argument, return a square matrix with the dimension\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4440 specified.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4441 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4442 When called with more than one scalar argument the first two arguments are\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4443 taken as the number of rows and columns and any further arguments specify\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4444 additional matrix dimensions.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4445 \n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4446 The optional argument @var{class} specifies the return type and may be\n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17268
diff
changeset
|
4447 either @qcode{\"double\"} or @qcode{\"single\"}.\n\ |
15175
5984aa619cd9
doc: Remove multiple seealso links to I (bug #37046).
Rik <rik@octave.org>
parents:
15111
diff
changeset
|
4448 @seealso{log, exp, pi, I}\n\ |
5747 | 4449 @end deftypefn") |
4450 { | |
4451 #if defined (M_E) | |
4452 double e_val = M_E; | |
4453 #else | |
4454 double e_val = exp (1.0); | |
4455 #endif | |
4456 | |
4457 return fill_matrix (args, e_val, "e"); | |
4458 } | |
4459 | |
4460 DEFUN (eps, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
4461 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
4462 @deftypefn {} {} eps\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
4463 @deftypefnx {} {} eps (@var{x})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
4464 @deftypefnx {} {} eps (@var{n}, @var{m})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
4465 @deftypefnx {} {} eps (@var{n}, @var{m}, @var{k}, @dots{})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
4466 @deftypefnx {} {} eps (@dots{}, @var{class})\n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4467 Return a scalar, matrix or N-dimensional array whose elements are all eps,\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4468 the machine precision.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4469 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4470 More precisely, @code{eps} is the relative spacing between any two adjacent\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4471 numbers in the machine's floating point system. This number is obviously\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4472 system dependent. On machines that support IEEE floating point arithmetic,\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4473 @code{eps} is approximately\n\ |
5747 | 4474 @tex\n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4475 $2.2204\\times10^{-16}$ for double precision and $1.1921\\times10^{-7}$\n\ |
5747 | 4476 @end tex\n\ |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
8487
diff
changeset
|
4477 @ifnottex\n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4478 2.2204e-16 for double precision and 1.1921e-07\n\ |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
8487
diff
changeset
|
4479 @end ifnottex\n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4480 for single precision.\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4481 \n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4482 When called with no arguments, return a scalar with the value\n\ |
14843
7d4f87c75dbb
data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents:
14635
diff
changeset
|
4483 @code{eps (1.0)}.\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4484 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4485 Given a single argument @var{x}, return the distance between @var{x} and the\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4486 next largest value.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4487 \n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4488 When called with more than one argument the first two arguments are taken as\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4489 the number of rows and columns and any further arguments specify additional\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4490 matrix dimensions. The optional argument @var{class} specifies the return\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4491 type and may be either @qcode{\"double\"} or @qcode{\"single\"}.\n\ |
20486 | 4492 @seealso{realmax, realmin, intmax, flintmax}\n\ |
5747 | 4493 @end deftypefn") |
4494 { | |
7795
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4495 octave_value retval; |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4496 |
20819
f428cbe7576f
eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents:
20816
diff
changeset
|
4497 if (args.length () == 1 && ! args(0).is_string ()) |
7795
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4498 { |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4499 if (args(0).is_single_type ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4500 { |
15509
f0dfdc7faa71
Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15467
diff
changeset
|
4501 Array<float> x = args(0).float_array_value (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4502 |
20562
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4503 Array<float> epsval (x.dims ()); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4504 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4505 for (octave_idx_type i = 0; i < x.numel (); i++) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
4506 { |
20562
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4507 float val = ::fabsf (x(i)); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4508 if (xisnan (val) || xisinf (val)) |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4509 epsval(i) = lo_ieee_nan_value (); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4510 else if (val < std::numeric_limits<float>::min ()) |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4511 epsval(i) = powf (2.0, -149e0); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4512 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4513 { |
20562
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4514 int expon; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4515 gnulib::frexpf (val, &expon); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4516 epsval(i) = std::pow (2.0f, |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4517 static_cast<float> (expon - 24)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4518 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4519 } |
20562
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4520 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4521 retval = epsval; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4522 } |
7795
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4523 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4524 { |
15509
f0dfdc7faa71
Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15467
diff
changeset
|
4525 Array<double> x = args(0).array_value (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4526 |
20562
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4527 Array<double> epsval (x.dims ()); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4528 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4529 for (octave_idx_type i = 0; i < x.numel (); i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4530 { |
20562
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4531 double val = ::fabs (x(i)); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4532 if (xisnan (val) || xisinf (val)) |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4533 epsval(i) = lo_ieee_nan_value (); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4534 else if (val < std::numeric_limits<double>::min ()) |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4535 epsval(i) = pow (2.0, -1074e0); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4536 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4537 { |
20562
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4538 int expon; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4539 gnulib::frexp (val, &expon); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4540 epsval(i) = std::pow (2.0, |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4541 static_cast<double> (expon - 53)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4542 } |
20562
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4543 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4544 retval = epsval; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4545 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4546 } |
7795
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4547 } |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4548 else |
15213
336f42406671
use numeric_limits functions instead of DBL_MIN, DBL_MAX, etc.
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
4549 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
|
4550 std::numeric_limits<float>::epsilon (), "eps"); |
7795
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4551 |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4552 return retval; |
5747 | 4553 } |
4554 | |
7795
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4555 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4556 %!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
|
4557 %!assert (eps (1), 2^(-52)) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4558 %!assert (eps (2), 2^(-51)) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4559 %!assert (eps (realmax), 2^971) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4560 %!assert (eps (0), 2^(-1074)) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4561 %!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
|
4562 %!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
|
4563 %!assert (eps (Inf), NaN) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4564 %!assert (eps (NaN), NaN) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
4565 %!assert (eps ([1/2 1 2 realmax 0 realmin/2 realmin/16 Inf NaN]), |
15509
f0dfdc7faa71
Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15467
diff
changeset
|
4566 %! [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
|
4567 %!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
|
4568 %!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
|
4569 %!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
|
4570 %!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
|
4571 %!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
|
4572 %!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
|
4573 %!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
|
4574 %!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
|
4575 %!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
|
4576 %!assert (eps (single ([1/2 1 2 realmax("single") 0 realmin("single")/2 realmin("single")/16 Inf NaN])), |
15509
f0dfdc7faa71
Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15467
diff
changeset
|
4577 %! single ([2^(-24) 2^(-23) 2^(-22) 2^104 2^(-149) 2^(-149) 2^(-149) NaN NaN])) |
f0dfdc7faa71
Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15467
diff
changeset
|
4578 |
7795
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4579 */ |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4580 |
5747 | 4581 DEFUN (pi, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
4582 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
4583 @deftypefn {} {} pi\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
4584 @deftypefnx {} {} pi (@var{n})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
4585 @deftypefnx {} {} pi (@var{n}, @var{m})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
4586 @deftypefnx {} {} pi (@var{n}, @var{m}, @var{k}, @dots{})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
4587 @deftypefnx {} {} pi (@dots{}, @var{class})\n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4588 Return a scalar, matrix, or N-dimensional array whose elements are all equal\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4589 to the ratio of the circumference of a circle to its\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4590 @tex\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4591 diameter($\\pi$).\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4592 @end tex\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4593 @ifnottex\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4594 diameter.\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4595 @end ifnottex\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4596 \n\ |
5747 | 4597 Internally, @code{pi} is computed as @samp{4.0 * atan (1.0)}.\n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4598 \n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4599 When called with no arguments, return a scalar with the value of\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4600 @tex\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4601 $\\pi$.\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4602 @end tex\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4603 @ifnottex\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4604 pi.\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4605 @end ifnottex\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4606 \n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4607 When called with a single argument, return a square matrix with the dimension\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4608 specified.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4609 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4610 When called with more than one scalar argument the first two arguments are\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4611 taken as the number of rows and columns and any further arguments specify\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4612 additional matrix dimensions.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4613 \n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4614 The optional argument @var{class} specifies the return type and may be\n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17268
diff
changeset
|
4615 either @qcode{\"double\"} or @qcode{\"single\"}.\n\ |
15175
5984aa619cd9
doc: Remove multiple seealso links to I (bug #37046).
Rik <rik@octave.org>
parents:
15111
diff
changeset
|
4616 @seealso{e, I}\n\ |
5747 | 4617 @end deftypefn") |
4618 { | |
4619 #if defined (M_PI) | |
4620 double pi_val = M_PI; | |
4621 #else | |
4622 double pi_val = 4.0 * atan (1.0); | |
4623 #endif | |
4624 | |
4625 return fill_matrix (args, pi_val, "pi"); | |
4626 } | |
4627 | |
4628 DEFUN (realmax, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
4629 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
4630 @deftypefn {} {} realmax\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
4631 @deftypefnx {} {} realmax (@var{n})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
4632 @deftypefnx {} {} realmax (@var{n}, @var{m})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
4633 @deftypefnx {} {} realmax (@var{n}, @var{m}, @var{k}, @dots{})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
4634 @deftypefnx {} {} realmax (@dots{}, @var{class})\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4635 Return a scalar, matrix, or N-dimensional array whose elements are all equal\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4636 to the largest floating point number that is representable.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4637 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4638 The actual value is system dependent. On machines that support IEEE\n\ |
5747 | 4639 floating point arithmetic, @code{realmax} is approximately\n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4640 @tex\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4641 $1.7977\\times10^{308}$ for double precision and $3.4028\\times10^{38}$\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4642 @end tex\n\ |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
8487
diff
changeset
|
4643 @ifnottex\n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4644 1.7977e+308 for double precision and 3.4028e+38\n\ |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
8487
diff
changeset
|
4645 @end ifnottex\n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4646 for single precision.\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4647 \n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4648 When called with no arguments, return a scalar with the value\n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17268
diff
changeset
|
4649 @code{realmax (@qcode{\"double\"})}.\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4650 \n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4651 When called with a single argument, return a square matrix with the dimension\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4652 specified.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4653 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4654 When called with more than one scalar argument the first two arguments are\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4655 taken as the number of rows and columns and any further arguments specify\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4656 additional matrix dimensions.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4657 \n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4658 The optional argument @var{class} specifies the return type and may be\n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17268
diff
changeset
|
4659 either @qcode{\"double\"} or @qcode{\"single\"}.\n\ |
20486 | 4660 @seealso{realmin, intmax, flintmax, eps}\n\ |
5747 | 4661 @end deftypefn") |
4662 { | |
15213
336f42406671
use numeric_limits functions instead of DBL_MIN, DBL_MAX, etc.
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
4663 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
|
4664 std::numeric_limits<float>::max (), "realmax"); |
5747 | 4665 } |
4666 | |
4667 DEFUN (realmin, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
4668 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
4669 @deftypefn {} {} realmin\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
4670 @deftypefnx {} {} realmin (@var{n})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
4671 @deftypefnx {} {} realmin (@var{n}, @var{m})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
4672 @deftypefnx {} {} realmin (@var{n}, @var{m}, @var{k}, @dots{})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
4673 @deftypefnx {} {} realmin (@dots{}, @var{class})\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4674 Return a scalar, matrix, or N-dimensional array whose elements are all equal\n\ |
5747 | 4675 to the smallest normalized floating point number that is representable.\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4676 \n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4677 The actual value is system dependent. On machines that support\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4678 IEEE floating point arithmetic, @code{realmin} is approximately\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4679 @tex\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4680 $2.2251\\times10^{-308}$ for double precision and $1.1755\\times10^{-38}$\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4681 @end tex\n\ |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
8487
diff
changeset
|
4682 @ifnottex\n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4683 2.2251e-308 for double precision and 1.1755e-38\n\ |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
8487
diff
changeset
|
4684 @end ifnottex\n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4685 for single precision.\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4686 \n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4687 When called with no arguments, return a scalar with the value\n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17268
diff
changeset
|
4688 @code{realmin (@qcode{\"double\"})}.\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4689 \n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4690 When called with a single argument, return a square matrix with the dimension\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4691 specified.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4692 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4693 When called with more than one scalar argument the first two arguments are\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4694 taken as the number of rows and columns and any further arguments specify\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4695 additional matrix dimensions.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4696 \n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4697 The optional argument @var{class} specifies the return type and may be\n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17268
diff
changeset
|
4698 either @qcode{\"double\"} or @qcode{\"single\"}.\n\ |
15028
397f0d80bd47
Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents:
15024
diff
changeset
|
4699 @seealso{realmax, intmin, eps}\n\ |
5747 | 4700 @end deftypefn") |
4701 { | |
15213
336f42406671
use numeric_limits functions instead of DBL_MIN, DBL_MAX, etc.
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
4702 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
|
4703 std::numeric_limits<float>::min (), "realmin"); |
5747 | 4704 } |
4705 | |
4706 DEFUN (I, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
4707 "-*- texinfo -*-\n\ |
14100
8a2dc08886ea
Fix Info referencing for i, I, j, J (Bug #35157)
Rik <octave@nomad.inbox5.com>
parents:
14085
diff
changeset
|
4708 @c List other forms of function in documentation index\n\ |
8a2dc08886ea
Fix Info referencing for i, I, j, J (Bug #35157)
Rik <octave@nomad.inbox5.com>
parents:
14085
diff
changeset
|
4709 @findex i\n\ |
8a2dc08886ea
Fix Info referencing for i, I, j, J (Bug #35157)
Rik <octave@nomad.inbox5.com>
parents:
14085
diff
changeset
|
4710 @findex j\n\ |
8a2dc08886ea
Fix Info referencing for i, I, j, J (Bug #35157)
Rik <octave@nomad.inbox5.com>
parents:
14085
diff
changeset
|
4711 @findex J\n\ |
8a2dc08886ea
Fix Info referencing for i, I, j, J (Bug #35157)
Rik <octave@nomad.inbox5.com>
parents:
14085
diff
changeset
|
4712 \n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
4713 @deftypefn {} {} I\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
4714 @deftypefnx {} {} I (@var{n})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
4715 @deftypefnx {} {} I (@var{n}, @var{m})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
4716 @deftypefnx {} {} I (@var{n}, @var{m}, @var{k}, @dots{})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
4717 @deftypefnx {} {} I (@dots{}, @var{class})\n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4718 Return a scalar, matrix, or N-dimensional array whose elements are all equal\n\ |
5747 | 4719 to the pure imaginary unit, defined as\n\ |
4720 @tex\n\ | |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4721 $\\sqrt{-1}$.\n\ |
5747 | 4722 @end tex\n\ |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
8487
diff
changeset
|
4723 @ifnottex\n\ |
20569
c6059134f5d3
data.cc: Add @w{} around @code segments in docstrings to prevent line breaks.
Rik <rik@octave.org>
parents:
20398
diff
changeset
|
4724 @w{@code{sqrt (-1)}}.\n\ |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
8487
diff
changeset
|
4725 @end ifnottex\n\ |
15028
397f0d80bd47
Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents:
15024
diff
changeset
|
4726 \n\ |
15034
1116864ee270
doc: Fix for bad cross-referencing due to use of aliases in Texinfo.
Rik <rik@octave.org>
parents:
15031
diff
changeset
|
4727 I, and its equivalents i, j, and J, are functions so any of the names may\n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4728 be reused for other purposes (such as i for a counter variable).\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4729 \n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4730 When called with no arguments, return a scalar with the value @math{i}.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4731 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4732 When called with a single argument, return a square matrix with the dimension\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4733 specified.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4734 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4735 When called with more than one scalar argument the first two arguments are\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4736 taken as the number of rows and columns and any further arguments specify\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4737 additional matrix dimensions.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4738 \n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4739 The optional argument @var{class} specifies the return type and may be\n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17268
diff
changeset
|
4740 either @qcode{\"double\"} or @qcode{\"single\"}.\n\ |
15175
5984aa619cd9
doc: Remove multiple seealso links to I (bug #37046).
Rik <rik@octave.org>
parents:
15111
diff
changeset
|
4741 @seealso{e, pi, log, exp}\n\ |
5747 | 4742 @end deftypefn") |
4743 { | |
4744 return fill_matrix (args, Complex (0.0, 1.0), "I"); | |
4745 } | |
4746 | |
4747 DEFALIAS (i, I); | |
4748 DEFALIAS (J, I); | |
4749 DEFALIAS (j, I); | |
4750 | |
4751 DEFUN (NA, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
4752 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
4753 @deftypefn {} {} NA\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
4754 @deftypefnx {} {} NA (@var{n})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
4755 @deftypefnx {} {} NA (@var{n}, @var{m})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
4756 @deftypefnx {} {} NA (@var{n}, @var{m}, @var{k}, @dots{})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
4757 @deftypefnx {} {} NA (@dots{}, @var{class})\n\ |
9308
f2bf62f62286
Update documentation for NA and isna functions
Rik <rdrider0-list@yahoo.com>
parents:
9198
diff
changeset
|
4758 Return a scalar, matrix, or N-dimensional array whose elements are all equal\n\ |
5747 | 4759 to the special constant used to designate missing values.\n\ |
9308
f2bf62f62286
Update documentation for NA and isna functions
Rik <rdrider0-list@yahoo.com>
parents:
9198
diff
changeset
|
4760 \n\ |
f2bf62f62286
Update documentation for NA and isna functions
Rik <rdrider0-list@yahoo.com>
parents:
9198
diff
changeset
|
4761 Note that NA always compares not equal to NA (NA != NA).\n\ |
f2bf62f62286
Update documentation for NA and isna functions
Rik <rdrider0-list@yahoo.com>
parents:
9198
diff
changeset
|
4762 To find NA values, use the @code{isna} function.\n\ |
f2bf62f62286
Update documentation for NA and isna functions
Rik <rdrider0-list@yahoo.com>
parents:
9198
diff
changeset
|
4763 \n\ |
f2bf62f62286
Update documentation for NA and isna functions
Rik <rdrider0-list@yahoo.com>
parents:
9198
diff
changeset
|
4764 When called with no arguments, return a scalar with the value @samp{NA}.\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4765 \n\ |
9308
f2bf62f62286
Update documentation for NA and isna functions
Rik <rdrider0-list@yahoo.com>
parents:
9198
diff
changeset
|
4766 When called with a single argument, return a square matrix with the dimension\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4767 specified.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4768 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4769 When called with more than one scalar argument the first two arguments are\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4770 taken as the number of rows and columns and any further arguments specify\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4771 additional matrix dimensions.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4772 \n\ |
9308
f2bf62f62286
Update documentation for NA and isna functions
Rik <rdrider0-list@yahoo.com>
parents:
9198
diff
changeset
|
4773 The optional argument @var{class} specifies the return type and may be\n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17268
diff
changeset
|
4774 either @qcode{\"double\"} or @qcode{\"single\"}.\n\ |
9308
f2bf62f62286
Update documentation for NA and isna functions
Rik <rdrider0-list@yahoo.com>
parents:
9198
diff
changeset
|
4775 @seealso{isna}\n\ |
5747 | 4776 @end deftypefn") |
4777 { | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
4778 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
|
4779 lo_ieee_float_na_value (), "NA"); |
5747 | 4780 } |
4781 | |
7991
139f47cf17ab
Change NA value to support single to double precision conversion
David Bateman <dbateman@free.fr>
parents:
7919
diff
changeset
|
4782 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4783 %!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
|
4784 %!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
|
4785 */ |
7991
139f47cf17ab
Change NA value to support single to double precision conversion
David Bateman <dbateman@free.fr>
parents:
7919
diff
changeset
|
4786 |
5747 | 4787 DEFUN (false, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
4788 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
4789 @deftypefn {} {} false (@var{x})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
4790 @deftypefnx {} {} false (@var{n}, @var{m})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
4791 @deftypefnx {} {} false (@var{n}, @var{m}, @var{k}, @dots{})\n\ |
5747 | 4792 Return a matrix or N-dimensional array whose elements are all logical 0.\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4793 \n\ |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
4794 If invoked with a single scalar integer argument, return a square\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4795 matrix of the specified size.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4796 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4797 If invoked with two or more scalar integer arguments, or a vector of integer\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4798 values, return an array with given dimensions.\n\ |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
4799 @seealso{true}\n\ |
5747 | 4800 @end deftypefn") |
4801 { | |
4802 return fill_matrix (args, false, "false"); | |
4803 } | |
4804 | |
4805 DEFUN (true, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
4806 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
4807 @deftypefn {} {} true (@var{x})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
4808 @deftypefnx {} {} true (@var{n}, @var{m})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
4809 @deftypefnx {} {} true (@var{n}, @var{m}, @var{k}, @dots{})\n\ |
5747 | 4810 Return a matrix or N-dimensional array whose elements are all logical 1.\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4811 \n\ |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
4812 If invoked with a single scalar integer argument, return a square\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4813 matrix of the specified size.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4814 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4815 If invoked with two or more scalar integer arguments, or a vector of integer\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4816 values, return an array with given dimensions.\n\ |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
4817 @seealso{false}\n\ |
5747 | 4818 @end deftypefn") |
4819 { | |
4820 return fill_matrix (args, true, "true"); | |
3354 | 4821 } |
523 | 4822 |
4946 | 4823 template <class MT> |
4824 octave_value | |
4825 identity_matrix (int nr, int nc) | |
4826 { | |
4827 octave_value retval; | |
4828 | |
9685 | 4829 typename MT::element_type one (1); |
4946 | 4830 |
4831 if (nr == 1 && nc == 1) | |
4832 retval = one; | |
4833 else | |
4834 { | |
4835 dim_vector dims (nr, nc); | |
4836 | |
9685 | 4837 typename MT::element_type zero (0); |
4946 | 4838 |
4839 MT m (dims, zero); | |
4840 | |
4841 if (nr > 0 && nc > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4842 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4843 int n = std::min (nr, nc); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4844 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4845 for (int i = 0; i < n; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4846 m(i,i) = one; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4847 } |
4946 | 4848 |
4849 retval = m; | |
4850 } | |
4851 | |
4852 return retval; | |
4853 } | |
4854 | |
5058 | 4855 #define INSTANTIATE_EYE(T) \ |
4856 template octave_value identity_matrix<T> (int, int) | |
4857 | |
4858 INSTANTIATE_EYE (int8NDArray); | |
4859 INSTANTIATE_EYE (uint8NDArray); | |
4860 INSTANTIATE_EYE (int16NDArray); | |
4861 INSTANTIATE_EYE (uint16NDArray); | |
4862 INSTANTIATE_EYE (int32NDArray); | |
4863 INSTANTIATE_EYE (uint32NDArray); | |
4864 INSTANTIATE_EYE (int64NDArray); | |
4865 INSTANTIATE_EYE (uint64NDArray); | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7743
diff
changeset
|
4866 INSTANTIATE_EYE (FloatNDArray); |
5058 | 4867 INSTANTIATE_EYE (NDArray); |
4868 INSTANTIATE_EYE (boolNDArray); | |
4869 | |
4945 | 4870 static octave_value |
4948 | 4871 identity_matrix (int nr, int nc, oct_data_conv::data_type dt) |
4945 | 4872 { |
4873 octave_value retval; | |
4874 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
4875 // FIXME: perhaps this should be made extensible by using |
4946 | 4876 // the class name to lookup a function to call to create the new |
4877 // value. | |
4878 | |
20562
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4879 switch (dt) |
4946 | 4880 { |
20562
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4881 case oct_data_conv::dt_int8: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4882 retval = identity_matrix<int8NDArray> (nr, nc); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4883 break; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4884 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4885 case oct_data_conv::dt_uint8: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4886 retval = identity_matrix<uint8NDArray> (nr, nc); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4887 break; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4888 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4889 case oct_data_conv::dt_int16: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4890 retval = identity_matrix<int16NDArray> (nr, nc); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4891 break; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4892 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4893 case oct_data_conv::dt_uint16: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4894 retval = identity_matrix<uint16NDArray> (nr, nc); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4895 break; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4896 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4897 case oct_data_conv::dt_int32: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4898 retval = identity_matrix<int32NDArray> (nr, nc); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4899 break; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4900 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4901 case oct_data_conv::dt_uint32: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4902 retval = identity_matrix<uint32NDArray> (nr, nc); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4903 break; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4904 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4905 case oct_data_conv::dt_int64: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4906 retval = identity_matrix<int64NDArray> (nr, nc); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4907 break; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4908 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4909 case oct_data_conv::dt_uint64: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4910 retval = identity_matrix<uint64NDArray> (nr, nc); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4911 break; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4912 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4913 case oct_data_conv::dt_single: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4914 retval = FloatDiagMatrix (nr, nc, 1.0f); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4915 break; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4916 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4917 case oct_data_conv::dt_double: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4918 retval = DiagMatrix (nr, nc, 1.0); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4919 break; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4920 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4921 case oct_data_conv::dt_logical: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4922 retval = identity_matrix<boolNDArray> (nr, nc); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4923 break; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4924 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4925 default: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4926 error ("eye: invalid class name"); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
4927 break; |
4945 | 4928 } |
4929 | |
4930 return retval; | |
4931 } | |
4932 | |
4946 | 4933 #undef INT_EYE_MATRIX |
4934 | |
1957 | 4935 DEFUN (eye, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
4936 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
4937 @deftypefn {} {} eye (@var{n})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
4938 @deftypefnx {} {} eye (@var{m}, @var{n})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
4939 @deftypefnx {} {} eye ([@var{m} @var{n}])\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
4940 @deftypefnx {} {} eye (@dots{}, @var{class})\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4941 Return an identity matrix.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4942 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4943 If invoked with a single scalar argument @var{n}, return a square\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4944 @nospell{NxN} identity matrix.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4945 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4946 If supplied two scalar arguments (@var{m}, @var{n}), @code{eye} takes them\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4947 to be the number of rows and columns. If given a vector with two elements,\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4948 @code{eye} uses the values of the elements as the number of rows and\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4949 columns, respectively. For example:\n\ |
3369 | 4950 \n\ |
4951 @example\n\ | |
4952 @group\n\ | |
4953 eye (3)\n\ | |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
4954 @result{} 1 0 0\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
4955 0 1 0\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
4956 0 0 1\n\ |
3369 | 4957 @end group\n\ |
4958 @end example\n\ | |
4959 \n\ | |
4960 The following expressions all produce the same result:\n\ | |
4961 \n\ | |
4962 @example\n\ | |
4963 @group\n\ | |
4964 eye (2)\n\ | |
4965 @equiv{}\n\ | |
4966 eye (2, 2)\n\ | |
4967 @equiv{}\n\ | |
18679
a142f35f3cb6
doc: Fix unbalanced parentheses in documentation.
Rik <rik@octave.org>
parents:
18678
diff
changeset
|
4968 eye (size ([1, 2; 3, 4]))\n\ |
3369 | 4969 @end group\n\ |
4970 @end example\n\ | |
4971 \n\ | |
4945 | 4972 The optional argument @var{class}, allows @code{eye} to return an array of\n\ |
4973 the specified type, like\n\ | |
4974 \n\ | |
4975 @example\n\ | |
4976 val = zeros (n,m, \"uint8\")\n\ | |
4977 @end example\n\ | |
4978 \n\ | |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4979 Calling @code{eye} with no arguments is equivalent to calling it with an\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4980 argument of 1. Any negative dimensions are treated as zero. These odd\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
4981 definitions are for compatibility with @sc{matlab}.\n\ |
15028
397f0d80bd47
Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents:
15024
diff
changeset
|
4982 @seealso{speye, ones, zeros}\n\ |
3369 | 4983 @end deftypefn") |
523 | 4984 { |
4948 | 4985 int nargin = args.length (); |
4945 | 4986 |
4948 | 4987 oct_data_conv::data_type dt = oct_data_conv::dt_double; |
523 | 4988 |
4945 | 4989 // Check for type information. |
4990 | |
4991 if (nargin > 0 && args(nargin-1).is_string ()) | |
4992 { | |
4948 | 4993 std::string nm = args(nargin-1).string_value (); |
4945 | 4994 nargin--; |
4948 | 4995 |
4996 dt = oct_data_conv::string_to_data_type (nm); | |
4945 | 4997 } |
4998 | |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
4999 if (nargin > 2) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
5000 print_usage (); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
5001 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
5002 octave_value retval; |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
5003 |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
5004 if (nargin == 0) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
5005 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
|
5006 else if (nargin == 1) |
523 | 5007 { |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
5008 octave_idx_type nr, nc; |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
5009 get_dimensions (args(0), "eye", nr, nc); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
5010 |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
5011 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
|
5012 } |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
5013 else |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
5014 { |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
5015 octave_idx_type nr, nc; |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
5016 get_dimensions (args(0), args(1), "eye", nr, nc); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
5017 |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
5018 retval = identity_matrix (nr, nc, dt); |
523 | 5019 } |
5020 | |
5021 return retval; | |
5022 } | |
5023 | |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5024 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5025 %!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
|
5026 %!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
|
5027 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5028 %!assert (full (eye (3,"single")), single ([1, 0, 0; 0, 1, 0; 0, 0, 1])) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5029 %!assert (full (eye (2, 3,"single")), single ([1, 0, 0; 0, 1, 0])) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5030 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5031 %!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
|
5032 %!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
|
5033 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5034 %!error eye (1, 2, 3) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5035 */ |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5036 |
9658
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5037 template <class MT> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
5038 static octave_value |
9658
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5039 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
|
5040 octave_idx_type n) |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5041 { |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5042 typedef typename MT::column_vector_type CVT; |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5043 typedef typename MT::element_type T; |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5044 |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5045 octave_value retval; |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5046 |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5047 if (base.is_scalar_type ()) |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5048 { |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5049 T bs = octave_value_extract<T> (base); |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5050 if (limit.is_scalar_type ()) |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5051 { |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5052 T ls = octave_value_extract<T> (limit); |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5053 retval = linspace (bs, ls, n); |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5054 } |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5055 else |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5056 { |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5057 CVT lv = octave_value_extract<CVT> (limit); |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20218
diff
changeset
|
5058 CVT bv (lv.numel (), bs); |
9658
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5059 retval = linspace (bv, lv, n); |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5060 } |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5061 } |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5062 else |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5063 { |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5064 CVT bv = octave_value_extract<CVT> (base); |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5065 if (limit.is_scalar_type ()) |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5066 { |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5067 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
|
5068 CVT lv (bv.numel (), ls); |
9658
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5069 retval = linspace (bv, lv, n); |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5070 } |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5071 else |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5072 { |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5073 CVT lv = octave_value_extract<CVT> (limit); |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5074 retval = linspace (bv, lv, n); |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5075 } |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5076 } |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5077 |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5078 return retval; |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5079 } |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5080 |
1957 | 5081 DEFUN (linspace, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
5082 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
5083 @deftypefn {} {} linspace (@var{base}, @var{limit})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
5084 @deftypefnx {} {} linspace (@var{base}, @var{limit}, @var{n})\n\ |
3369 | 5085 Return a row vector with @var{n} linearly spaced elements between\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
5086 @var{base} and @var{limit}.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
5087 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
5088 If the number of elements is greater than one, then the endpoints @var{base}\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
5089 and @var{limit} are always included in the range. If @var{base} is greater\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
5090 than @var{limit}, the elements are stored in decreasing order. If the\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
5091 number of points is not specified, a value of 100 is used.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
5092 \n\ |
20466
16b9ec39ff46
Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents:
20405
diff
changeset
|
5093 The @code{linspace} function returns a row vector when both @var{base}\n\ |
16b9ec39ff46
Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents:
20405
diff
changeset
|
5094 and @var{limit} are scalars. If one, or both, inputs are vectors, then\n\ |
16b9ec39ff46
Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents:
20405
diff
changeset
|
5095 @code{linspace} transforms them to column vectors and returns a matrix where\n\ |
16b9ec39ff46
Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents:
20405
diff
changeset
|
5096 each row is an independent sequence between\n\ |
16b9ec39ff46
Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents:
20405
diff
changeset
|
5097 @w{@code{@var{base}(@var{row_n}), @var{limit}(@var{row_n})}}.\n\ |
6630 | 5098 \n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
5099 For compatibility with @sc{matlab}, return the second argument (@var{limit})\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
5100 if fewer than two values are requested.\n\ |
15028
397f0d80bd47
Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents:
15024
diff
changeset
|
5101 @seealso{logspace}\n\ |
3369 | 5102 @end deftypefn") |
1100 | 5103 { |
20816
b16bcd7a2a33
Use int rather than octave_idx_type for nargin data type.
Rik <rik@octave.org>
parents:
20815
diff
changeset
|
5104 int nargin = args.length (); |
1100 | 5105 |
1940 | 5106 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
|
5107 print_usage (); |
1940 | 5108 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
5109 octave_idx_type npoints = 100; |
1100 | 5110 if (nargin == 3) |
16077
39129305b914
provide some undocumented matlab behavior for linspace (bug #38151)
John W. Eaton <jwe@octave.org>
parents:
15623
diff
changeset
|
5111 { |
39129305b914
provide some undocumented matlab behavior for linspace (bug #38151)
John W. Eaton <jwe@octave.org>
parents:
15623
diff
changeset
|
5112 // 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
|
5113 // 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
|
5114 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
|
5115 |
39129305b914
provide some undocumented matlab behavior for linspace (bug #38151)
John W. Eaton <jwe@octave.org>
parents:
15623
diff
changeset
|
5116 if (arg_3.is_numeric_type () && arg_3.is_empty ()) |
39129305b914
provide some undocumented matlab behavior for linspace (bug #38151)
John W. Eaton <jwe@octave.org>
parents:
15623
diff
changeset
|
5117 npoints = 1; |
20466
16b9ec39ff46
Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents:
20405
diff
changeset
|
5118 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
|
5119 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
|
5120 else |
20573
32a0bf9906c1
linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents:
20562
diff
changeset
|
5121 // 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
|
5122 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
|
5123 } |
1100 | 5124 |
20573
32a0bf9906c1
linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents:
20562
diff
changeset
|
5125 octave_value arg_1 = args(0); |
32a0bf9906c1
linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents:
20562
diff
changeset
|
5126 octave_value arg_2 = args(1); |
32a0bf9906c1
linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents:
20562
diff
changeset
|
5127 |
32a0bf9906c1
linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents:
20562
diff
changeset
|
5128 dim_vector sz1 = arg_1.dims (); |
32a0bf9906c1
linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents:
20562
diff
changeset
|
5129 bool isvector1 = sz1.length () == 2 && (sz1(0) == 1 || sz1(1) == 1); |
32a0bf9906c1
linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents:
20562
diff
changeset
|
5130 dim_vector sz2 = arg_2.dims (); |
32a0bf9906c1
linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents:
20562
diff
changeset
|
5131 bool isvector2 = sz2.length () == 2 && (sz2(0) == 1 || sz2(1) == 1); |
32a0bf9906c1
linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents:
20562
diff
changeset
|
5132 |
32a0bf9906c1
linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents:
20562
diff
changeset
|
5133 if (! isvector1 || ! isvector2) |
32a0bf9906c1
linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents:
20562
diff
changeset
|
5134 error ("linspace: A, B must be scalars or vectors"); |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
5135 |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
5136 octave_value retval; |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
5137 |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
5138 if (arg_1.is_single_type () || arg_2.is_single_type ()) |
1100 | 5139 { |
20573
32a0bf9906c1
linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents:
20562
diff
changeset
|
5140 if (arg_1.is_complex_type () || arg_2.is_complex_type ()) |
32a0bf9906c1
linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents:
20562
diff
changeset
|
5141 retval = do_linspace<FloatComplexMatrix> (arg_1, arg_2, npoints); |
1100 | 5142 else |
20573
32a0bf9906c1
linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents:
20562
diff
changeset
|
5143 retval = do_linspace<FloatMatrix> (arg_1, arg_2, npoints); |
1100 | 5144 } |
4732 | 5145 else |
20573
32a0bf9906c1
linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents:
20562
diff
changeset
|
5146 { |
32a0bf9906c1
linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents:
20562
diff
changeset
|
5147 if (arg_1.is_complex_type () || arg_2.is_complex_type ()) |
32a0bf9906c1
linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents:
20562
diff
changeset
|
5148 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
|
5149 else |
32a0bf9906c1
linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents:
20562
diff
changeset
|
5150 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
|
5151 } |
1100 | 5152 |
5153 return retval; | |
5154 } | |
5155 | |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5156 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5157 /* |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5158 %!test |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5159 %! 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
|
5160 %! 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
|
5161 %! 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
|
5162 %! assert (size (x1) == [1, 100] && x1(1) == 1 && x1(100) == 2); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5163 %! assert (size (x2) == [1, 10] && x2(1) == 1 && x2(10) == 2); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5164 %! assert (size (x3) == [1, 10] && x3(1) == 1 && x3(10) == -2); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5165 |
20466
16b9ec39ff46
Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents:
20405
diff
changeset
|
5166 ## Test complex values |
16b9ec39ff46
Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents:
20405
diff
changeset
|
5167 %!test |
16b9ec39ff46
Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents:
20405
diff
changeset
|
5168 %! 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
|
5169 %! 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
|
5170 %! assert (obs, exp); |
16b9ec39ff46
Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents:
20405
diff
changeset
|
5171 |
20574
780431fc4137
linspace: add tests for the use of vectors as base and limit.
Carnë Draug <carandraug@octave.org>
parents:
20573
diff
changeset
|
5172 ## Test support for vectors in BASE and LIMIT |
780431fc4137
linspace: add tests for the use of vectors as base and limit.
Carnë Draug <carandraug@octave.org>
parents:
20573
diff
changeset
|
5173 %!assert (linspace ([1 2 3], [7 8 9]), |
780431fc4137
linspace: add tests for the use of vectors as base and limit.
Carnë Draug <carandraug@octave.org>
parents:
20573
diff
changeset
|
5174 %! [linspace(1, 7); linspace(2, 8); linspace(3, 9)]) |
780431fc4137
linspace: add tests for the use of vectors as base and limit.
Carnë Draug <carandraug@octave.org>
parents:
20573
diff
changeset
|
5175 %!assert (linspace ([1 2 3]', [7 8 9]'), |
780431fc4137
linspace: add tests for the use of vectors as base and limit.
Carnë Draug <carandraug@octave.org>
parents:
20573
diff
changeset
|
5176 %! [linspace(1, 7); linspace(2, 8); linspace(3, 9)]) |
780431fc4137
linspace: add tests for the use of vectors as base and limit.
Carnë Draug <carandraug@octave.org>
parents:
20573
diff
changeset
|
5177 %!assert (linspace ([1 2 3], 9), |
780431fc4137
linspace: add tests for the use of vectors as base and limit.
Carnë Draug <carandraug@octave.org>
parents:
20573
diff
changeset
|
5178 %! [linspace(1, 9); linspace(2, 9); linspace(3, 9)]) |
780431fc4137
linspace: add tests for the use of vectors as base and limit.
Carnë Draug <carandraug@octave.org>
parents:
20573
diff
changeset
|
5179 %!assert (linspace ([1 2 3]', 9), |
780431fc4137
linspace: add tests for the use of vectors as base and limit.
Carnë Draug <carandraug@octave.org>
parents:
20573
diff
changeset
|
5180 %! [linspace(1, 9); linspace(2, 9); linspace(3, 9)]) |
780431fc4137
linspace: add tests for the use of vectors as base and limit.
Carnë Draug <carandraug@octave.org>
parents:
20573
diff
changeset
|
5181 %!assert (linspace (1, [7 8 9]), |
780431fc4137
linspace: add tests for the use of vectors as base and limit.
Carnë Draug <carandraug@octave.org>
parents:
20573
diff
changeset
|
5182 %! [linspace(1, 7); linspace(1, 8); linspace(1, 9)]) |
780431fc4137
linspace: add tests for the use of vectors as base and limit.
Carnë Draug <carandraug@octave.org>
parents:
20573
diff
changeset
|
5183 %!assert (linspace (1, [7 8 9]'), |
780431fc4137
linspace: add tests for the use of vectors as base and limit.
Carnë Draug <carandraug@octave.org>
parents:
20573
diff
changeset
|
5184 %! [linspace(1, 7); linspace(1, 8); linspace(1, 9)]) |
780431fc4137
linspace: add tests for the use of vectors as base and limit.
Carnë Draug <carandraug@octave.org>
parents:
20573
diff
changeset
|
5185 |
20466
16b9ec39ff46
Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents:
20405
diff
changeset
|
5186 ## Test class of output |
16b9ec39ff46
Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents:
20405
diff
changeset
|
5187 %!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
|
5188 %!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
|
5189 %!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
|
5190 |
16b9ec39ff46
Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents:
20405
diff
changeset
|
5191 ## 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
|
5192 %!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
|
5193 %!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
|
5194 %!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
|
5195 %!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
|
5196 %!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
|
5197 %!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
|
5198 %!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
|
5199 %!assert (linspace (10, 20, 2.1), [10 20]) |
32a0bf9906c1
linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents:
20562
diff
changeset
|
5200 %!assert (linspace (10, 20, 2.9), [10 20]) |
16077
39129305b914
provide some undocumented matlab behavior for linspace (bug #38151)
John W. Eaton <jwe@octave.org>
parents:
15623
diff
changeset
|
5201 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5202 %!error linspace () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5203 %!error linspace (1, 2, 3, 4) |
20466
16b9ec39ff46
Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents:
20405
diff
changeset
|
5204 %!error <N must be a scalar> linspace (1, 2, [3, 4]) |
16b9ec39ff46
Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents:
20405
diff
changeset
|
5205 %!error <must be scalars or vectors> linspace (ones (2,2), 2, 3) |
16b9ec39ff46
Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents:
20405
diff
changeset
|
5206 %!error <must be scalars or vectors> linspace (2, ones (2,2), 3) |
16b9ec39ff46
Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents:
20405
diff
changeset
|
5207 %!error <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
|
5208 */ |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5209 |
20726
25d676f9619c
Preface error() messages with name of function when possible.
Rik <rik@octave.org>
parents:
20720
diff
changeset
|
5210 // 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
|
5211 // arrays as well as 1-D and 2-D arrays. |
5734 | 5212 |
5731 | 5213 DEFUN (resize, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
5214 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
5215 @deftypefn {} {} resize (@var{x}, @var{m})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
5216 @deftypefnx {} {} resize (@var{x}, @var{m}, @var{n}, @dots{})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
5217 @deftypefnx {} {} resize (@var{x}, [@var{m} @var{n} @dots{}])\n\ |
8799
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
5218 Resize @var{x} cutting off elements as necessary.\n\ |
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
5219 \n\ |
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
5220 In the result, element with certain indices is equal to the corresponding\n\ |
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
5221 element of @var{x} if the indices are within the bounds of @var{x};\n\ |
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
5222 otherwise, the element is set to zero.\n\ |
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
5223 \n\ |
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
5224 In other words, the statement\n\ |
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
5225 \n\ |
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
5226 @example\n\ |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
5227 y = resize (x, dv)\n\ |
8799
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
5228 @end example\n\ |
6174 | 5229 \n\ |
8799
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
5230 @noindent\n\ |
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
5231 is equivalent to the following code:\n\ |
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
5232 \n\ |
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
5233 @example\n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
9041
diff
changeset
|
5234 @group\n\ |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
5235 y = zeros (dv, class (x));\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
5236 sz = min (dv, size (x));\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
5237 for i = 1:length (sz)\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
5238 idx@{i@} = 1:sz(i);\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
5239 endfor\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
5240 y(idx@{:@}) = x(idx@{:@});\n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
9041
diff
changeset
|
5241 @end group\n\ |
8799
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
5242 @end example\n\ |
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
5243 \n\ |
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
5244 @noindent\n\ |
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
5245 but is performed more efficiently.\n\ |
6174 | 5246 \n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
5247 If only @var{m} is supplied, and it is a scalar, the dimension of the\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
5248 result is @var{m}-by-@var{m}.\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
5249 If @var{m}, @var{n}, @dots{} are all scalars, then the dimensions of\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
5250 the result are @var{m}-by-@var{n}-by-@dots{}.\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
5251 If given a vector as input, then the\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
5252 dimensions of the result are given by the elements of that vector.\n\ |
8799
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
5253 \n\ |
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
5254 An object can be resized to more dimensions than it has;\n\ |
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
5255 in such case the missing dimensions are assumed to be 1.\n\ |
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
5256 Resizing an object to fewer dimensions is not possible.\n\ |
15028
397f0d80bd47
Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents:
15024
diff
changeset
|
5257 @seealso{reshape, postpad, prepad, cat}\n\ |
5731 | 5258 @end deftypefn") |
5259 { | |
5260 int nargin = args.length (); | |
5261 | |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
5262 if (nargin < 2) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
5263 print_usage (); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
5264 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
5265 octave_value retval; |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
5266 |
5731 | 5267 if (nargin == 2) |
5268 { | |
5269 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
|
5270 int ndim = vec.numel (); |
5731 | 5271 if (ndim == 1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5272 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5273 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
|
5274 retval = args(0); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5275 retval = retval.resize (dim_vector (m, m), true); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5276 } |
5731 | 5277 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5278 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5279 dim_vector dv; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5280 dv.resize (ndim); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5281 for (int i = 0; i < ndim; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5282 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
|
5283 retval = args(0); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5284 retval = retval.resize (dv, true); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5285 } |
5731 | 5286 } |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
5287 else |
5731 | 5288 { |
8799
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
5289 dim_vector dv; |
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
5290 dv.resize (nargin - 1); |
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
5291 for (octave_idx_type i = 1; i < nargin; i++) |
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
5292 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
|
5293 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
5294 retval = args(0); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
5295 retval = retval.resize (dv, true); |
5731 | 5296 } |
20562
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
5297 |
5731 | 5298 return retval; |
5299 } | |
5300 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
5301 // FIXME: should use octave_idx_type for dimensions. |
5734 | 5302 |
4567 | 5303 DEFUN (reshape, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
5304 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
5305 @deftypefn {} {} reshape (@var{A}, @var{m}, @var{n}, @dots{})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
5306 @deftypefnx {} {} reshape (@var{A}, [@var{m} @var{n} @dots{}])\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
5307 @deftypefnx {} {} reshape (@var{A}, @dots{}, [], @dots{})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
5308 @deftypefnx {} {} reshape (@var{A}, @var{size})\n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
5309 Return a matrix with the specified dimensions (@var{m}, @var{n}, @dots{})\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
5310 whose elements are taken from the matrix @var{A}.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
5311 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
5312 The elements of the matrix are accessed in column-major order (like Fortran\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
5313 arrays are stored).\n\ |
4567 | 5314 \n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
5315 The following code demonstrates reshaping a 1x4 row vector into a 2x2 square\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
5316 matrix.\n\ |
4567 | 5317 \n\ |
5318 @example\n\ | |
5319 @group\n\ | |
5320 reshape ([1, 2, 3, 4], 2, 2)\n\ | |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
5321 @result{} 1 3\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
5322 2 4\n\ |
4567 | 5323 @end group\n\ |
5324 @end example\n\ | |
5325 \n\ | |
5326 @noindent\n\ | |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
5327 Note that the total number of elements in the original matrix\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
5328 (@code{prod (size (@var{A}))}) must match the total number of elements\n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
5329 in the new matrix (@code{prod ([@var{m} @var{n} @dots{}])}).\n\ |
5013 | 5330 \n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
5331 A single dimension of the return matrix may be left unspecified and Octave\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
5332 will determine its size automatically. An empty matrix ([]) is used to flag\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
5333 the unspecified dimension.\n\ |
15028
397f0d80bd47
Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents:
15024
diff
changeset
|
5334 @seealso{resize, vec, postpad, cat, squeeze}\n\ |
4567 | 5335 @end deftypefn") |
5336 { | |
5337 int nargin = args.length (); | |
5338 | |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
5339 if (nargin < 2) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
5340 print_usage (); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
5341 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
5342 octave_value retval; |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
5343 |
10693 | 5344 dim_vector new_dims; |
4567 | 5345 |
5346 if (nargin == 2) | |
10693 | 5347 { |
5348 Array<octave_idx_type> new_size = args(1).octave_idx_type_vector_value (); | |
5349 | |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20218
diff
changeset
|
5350 if (new_size.numel () < 2) |
20893
384ff5aa9437
2015 Code Sprint: Eliminate useless return statements after error ().
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
5351 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
|
5352 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20218
diff
changeset
|
5353 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
|
5354 |
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20218
diff
changeset
|
5355 for (octave_idx_type i = 0; i < new_size.numel (); i++) |
10693 | 5356 { |
5357 if (new_size(i) < 0) | |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
5358 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
|
5359 |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
5360 new_dims(i) = new_size(i); |
10693 | 5361 } |
5362 } | |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
5363 else |
4567 | 5364 { |
10693 | 5365 new_dims = dim_vector::alloc (nargin-1); |
5013 | 5366 int empty_dim = -1; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
5367 |
4567 | 5368 for (int i = 1; i < nargin; i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5369 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5370 if (args(i).is_empty ()) |
10693 | 5371 { |
5372 if (empty_dim > 0) | |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
5373 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
|
5374 |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
5375 empty_dim = i; |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
5376 new_dims(i-1) = 1; |
10693 | 5377 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5378 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5379 { |
10693 | 5380 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
|
5381 |
20562
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
5382 if (new_dims(i-1) < 0) |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
5383 error ("reshape: SIZE must be non-negative"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5384 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5385 } |
5013 | 5386 |
20562
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
5387 if (empty_dim > 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5388 { |
10693 | 5389 octave_idx_type nel = new_dims.numel (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5390 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5391 if (nel == 0) |
10693 | 5392 new_dims(empty_dim-1) = 0; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5393 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5394 { |
10693 | 5395 octave_idx_type a_nel = args(0).numel (); |
5396 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
|
5397 |
10693 | 5398 if (a_nel != size_empty_dim * nel) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
5399 error ("reshape: SIZE is not divisible by the product of known dimensions (= %d)", |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
5400 nel); |
20980
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
5401 |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
5402 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
|
5403 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5404 } |
4567 | 5405 } |
5406 | |
20562
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
5407 retval = args(0).reshape (new_dims); |
4567 | 5408 |
5409 return retval; | |
5410 } | |
5411 | |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5412 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5413 %!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
|
5414 %!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
|
5415 %!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
|
5416 %!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
|
5417 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5418 %!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
|
5419 %!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
|
5420 %!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
|
5421 %!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
|
5422 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5423 %!test |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5424 %! s.a = 1; |
17915
56d2b6838405
Issue an error if reshape called with just a single dimension.
Rik <rik@octave.org>
parents:
17843
diff
changeset
|
5425 %! 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
|
5426 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5427 %!error reshape () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5428 %!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
|
5429 %!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
|
5430 %!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
|
5431 %!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
|
5432 %!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
|
5433 %!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
|
5434 */ |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5435 |
10694
d97165928d05
implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents:
10693
diff
changeset
|
5436 DEFUN (vec, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
5437 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
5438 @deftypefn {} {@var{v} =} vec (@var{x})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
5439 @deftypefnx {} {@var{v} =} vec (@var{x}, @var{dim})\n\ |
10694
d97165928d05
implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents:
10693
diff
changeset
|
5440 Return the vector obtained by stacking the columns of the matrix @var{x}\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
5441 one above the other.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
5442 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
5443 Without @var{dim} this is equivalent to @code{@var{x}(:)}.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
5444 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
5445 If @var{dim} is supplied, the dimensions of @var{v} are set to @var{dim}\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
5446 with all elements along the last dimension. This is equivalent to\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
5447 @code{shiftdim (@var{x}(:), 1-@var{dim})}.\n\ |
15028
397f0d80bd47
Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents:
15024
diff
changeset
|
5448 @seealso{vech, resize, cat}\n\ |
10694
d97165928d05
implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents:
10693
diff
changeset
|
5449 @end deftypefn") |
d97165928d05
implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents:
10693
diff
changeset
|
5450 { |
11402
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
5451 int nargin = args.length (); |
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
5452 |
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
5453 if (nargin < 1 || nargin > 2) |
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
5454 print_usage () ; |
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
5455 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
5456 int dim = 1; |
20562
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
5457 if (nargin == 2) |
11402
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
5458 { |
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
5459 dim = args(1).idx_type_value (); |
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
5460 |
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
5461 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
|
5462 error ("vec: DIM must be greater than zero"); |
11402
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
5463 } |
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
5464 |
20562
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
5465 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
|
5466 octave_value arg = args(0); |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
5467 |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
5468 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
|
5469 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
5470 if (dim > 1) |
10694
d97165928d05
implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents:
10693
diff
changeset
|
5471 { |
20562
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
5472 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
|
5473 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
5474 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
|
5475 new_dims(i) = 1; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
5476 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
5477 new_dims(dim-1) = retval.numel (); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
5478 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
5479 retval = retval.reshape (new_dims); |
10694
d97165928d05
implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents:
10693
diff
changeset
|
5480 } |
d97165928d05
implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents:
10693
diff
changeset
|
5481 |
d97165928d05
implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents:
10693
diff
changeset
|
5482 return retval; |
d97165928d05
implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents:
10693
diff
changeset
|
5483 } |
d97165928d05
implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents:
10693
diff
changeset
|
5484 |
d97165928d05
implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents:
10693
diff
changeset
|
5485 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5486 %!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
|
5487 %!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
|
5488 %!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
|
5489 %!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
|
5490 %!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
|
5491 %!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
|
5492 %!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
|
5493 %!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
|
5494 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5495 %!error vec () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5496 %!error vec (1, 2, 3) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5497 %!error vec ([1, 2; 3, 4], 0) |
10694
d97165928d05
implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents:
10693
diff
changeset
|
5498 */ |
d97165928d05
implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents:
10693
diff
changeset
|
5499 |
4532 | 5500 DEFUN (squeeze, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
5501 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
5502 @deftypefn {} {} squeeze (@var{x})\n\ |
4532 | 5503 Remove singleton dimensions from @var{x} and return the result.\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
5504 \n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
9041
diff
changeset
|
5505 Note that for compatibility with @sc{matlab}, all objects have\n\ |
7007 | 5506 a minimum of two dimensions and row vectors are left unchanged.\n\ |
15028
397f0d80bd47
Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents:
15024
diff
changeset
|
5507 @seealso{reshape}\n\ |
4532 | 5508 @end deftypefn") |
5509 { | |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
5510 if (args.length () != 1) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
5511 print_usage (); |
4532 | 5512 |
21127
df7891224709
maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents:
21121
diff
changeset
|
5513 return ovl (args(0).squeeze ()); |
4532 | 5514 } |
5515 | |
8458
d254a21e0120
reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents:
8433
diff
changeset
|
5516 DEFUN (full, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
5517 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
5518 @deftypefn {} {@var{FM} =} full (@var{SM})\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
5519 Return a full storage matrix from a sparse, diagonal, or permutation matrix,\n\ |
10846
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10840
diff
changeset
|
5520 or a range.\n\ |
18809
53af80da6781
doc: Update documentation of sparse functions including seealso links.
Rik <rik@octave.org>
parents:
18789
diff
changeset
|
5521 @seealso{sparse, issparse}\n\ |
8458
d254a21e0120
reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents:
8433
diff
changeset
|
5522 @end deftypefn") |
d254a21e0120
reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents:
8433
diff
changeset
|
5523 { |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
5524 if (args.length () != 1) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
5525 print_usage (); |
8458
d254a21e0120
reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents:
8433
diff
changeset
|
5526 |
21127
df7891224709
maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents:
21121
diff
changeset
|
5527 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
|
5528 } |
d254a21e0120
reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents:
8433
diff
changeset
|
5529 |
6945 | 5530 // Compute various norms of the vector X. |
5531 | |
6953 | 5532 DEFUN (norm, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
5533 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
5534 @deftypefn {} {} norm (@var{A})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
5535 @deftypefnx {} {} norm (@var{A}, @var{p})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
5536 @deftypefnx {} {} norm (@var{A}, @var{p}, @var{opt})\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
5537 Compute the p-norm of the matrix @var{A}.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
5538 \n\ |
20569
c6059134f5d3
data.cc: Add @w{} around @code segments in docstrings to prevent line breaks.
Rik <rik@octave.org>
parents:
20398
diff
changeset
|
5539 If the second argument is missing, @w{@code{p = 2}} is assumed.\n\ |
6953 | 5540 \n\ |
12584
7ef7e20057fa
Improve documentation strings in Linear Algebra chapter.
Rik <octave@nomad.inbox5.com>
parents:
12578
diff
changeset
|
5541 If @var{A} is a matrix (or sparse matrix):\n\ |
6953 | 5542 \n\ |
5543 @table @asis\n\ | |
5544 @item @var{p} = @code{1}\n\ | |
12584
7ef7e20057fa
Improve documentation strings in Linear Algebra chapter.
Rik <octave@nomad.inbox5.com>
parents:
12578
diff
changeset
|
5545 1-norm, the largest column sum of the absolute values of @var{A}.\n\ |
6953 | 5546 \n\ |
5547 @item @var{p} = @code{2}\n\ | |
12584
7ef7e20057fa
Improve documentation strings in Linear Algebra chapter.
Rik <octave@nomad.inbox5.com>
parents:
12578
diff
changeset
|
5548 Largest singular value of @var{A}.\n\ |
6953 | 5549 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17268
diff
changeset
|
5550 @item @var{p} = @code{Inf} or @qcode{\"inf\"}\n\ |
6953 | 5551 @cindex infinity norm\n\ |
12584
7ef7e20057fa
Improve documentation strings in Linear Algebra chapter.
Rik <octave@nomad.inbox5.com>
parents:
12578
diff
changeset
|
5552 Infinity norm, the largest row sum of the absolute values of @var{A}.\n\ |
6953 | 5553 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17268
diff
changeset
|
5554 @item @var{p} = @qcode{\"fro\"}\n\ |
6953 | 5555 @cindex Frobenius norm\n\ |
12584
7ef7e20057fa
Improve documentation strings in Linear Algebra chapter.
Rik <octave@nomad.inbox5.com>
parents:
12578
diff
changeset
|
5556 Frobenius norm of @var{A}, @code{sqrt (sum (diag (@var{A}' * @var{A})))}.\n\ |
8303
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
5557 \n\ |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
5558 @item other @var{p}, @code{@var{p} > 1}\n\ |
12642
f96b9b9f141b
doc: Periodic grammarcheck and spellcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
5559 @cindex general p-norm\n\ |
8303
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
5560 maximum @code{norm (A*x, p)} such that @code{norm (x, p) == 1}\n\ |
6953 | 5561 @end table\n\ |
5562 \n\ | |
12584
7ef7e20057fa
Improve documentation strings in Linear Algebra chapter.
Rik <octave@nomad.inbox5.com>
parents:
12578
diff
changeset
|
5563 If @var{A} is a vector or a scalar:\n\ |
6953 | 5564 \n\ |
5565 @table @asis\n\ | |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17268
diff
changeset
|
5566 @item @var{p} = @code{Inf} or @qcode{\"inf\"}\n\ |
12584
7ef7e20057fa
Improve documentation strings in Linear Algebra chapter.
Rik <octave@nomad.inbox5.com>
parents:
12578
diff
changeset
|
5567 @code{max (abs (@var{A}))}.\n\ |
6953 | 5568 \n\ |
5569 @item @var{p} = @code{-Inf}\n\ | |
12584
7ef7e20057fa
Improve documentation strings in Linear Algebra chapter.
Rik <octave@nomad.inbox5.com>
parents:
12578
diff
changeset
|
5570 @code{min (abs (@var{A}))}.\n\ |
6953 | 5571 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17268
diff
changeset
|
5572 @item @var{p} = @qcode{\"fro\"}\n\ |
12584
7ef7e20057fa
Improve documentation strings in Linear Algebra chapter.
Rik <octave@nomad.inbox5.com>
parents:
12578
diff
changeset
|
5573 Frobenius norm of @var{A}, @code{sqrt (sumsq (abs (A)))}.\n\ |
7189 | 5574 \n\ |
8303
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
5575 @item @var{p} = 0\n\ |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
5576 Hamming norm - the number of nonzero elements.\n\ |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
5577 \n\ |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
5578 @item other @var{p}, @code{@var{p} > 1}\n\ |
12584
7ef7e20057fa
Improve documentation strings in Linear Algebra chapter.
Rik <octave@nomad.inbox5.com>
parents:
12578
diff
changeset
|
5579 p-norm of @var{A}, @code{(sum (abs (@var{A}) .^ @var{p})) ^ (1/@var{p})}.\n\ |
8303
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
5580 \n\ |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
5581 @item other @var{p} @code{@var{p} < 1}\n\ |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
5582 the p-pseudonorm defined as above.\n\ |
6953 | 5583 @end table\n\ |
8303
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
5584 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17268
diff
changeset
|
5585 If @var{opt} is the value @qcode{\"rows\"}, treat each row as a vector and\n\ |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
5586 compute its norm. The result is returned as a column vector.\n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17268
diff
changeset
|
5587 Similarly, if @var{opt} is @qcode{\"columns\"} or @qcode{\"cols\"} then\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17268
diff
changeset
|
5588 compute the norms of each column and return a row vector.\n\ |
6953 | 5589 @seealso{cond, svd}\n\ |
6508 | 5590 @end deftypefn") |
5591 { | |
5592 int nargin = args.length (); | |
5593 | |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
5594 if (nargin < 1 && nargin > 3) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
5595 print_usage (); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
5596 |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
5597 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
|
5598 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
5599 if (x_arg.ndims () != 2) |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
5600 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
|
5601 |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
5602 enum { sfmatrix, sfcols, sfrows, sffrob, sfinf } strflag = sfmatrix; |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
5603 if (nargin > 1 && args(nargin-1).is_string ()) |
6508 | 5604 { |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
5605 std::string str = args(nargin-1).string_value (); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
5606 if (str == "cols" || str == "columns") |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
5607 strflag = sfcols; |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
5608 else if (str == "rows") |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
5609 strflag = sfrows; |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
5610 else if (str == "fro") |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
5611 strflag = sffrob; |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
5612 else if (str == "inf") |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
5613 strflag = sfinf; |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
5614 else |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
5615 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
|
5616 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
5617 // 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
|
5618 nargin--; |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
5619 } |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
5620 |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
5621 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
|
5622 |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
5623 if (p_arg.is_empty ()) |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
5624 p_arg = octave_value (2); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
5625 else if (p_arg.is_string ()) |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
5626 { |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
5627 std::string str = p_arg.string_value (); |
20980
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
5628 if (strflag != sfcols && strflag != sfrows) |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
5629 error ("norm: invalid combination of options"); |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
5630 |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
5631 if (str == "cols" || str == "columns" || str == "rows") |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
5632 error ("norm: invalid combination of options"); |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
5633 |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
5634 if (str == "fro") |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
5635 p_arg = octave_value (2); |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
5636 else if (str == "inf") |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
5637 p_arg = octave_Inf; |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
5638 else |
20980
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
5639 error ("norm: unrecognized option: %s", str.c_str ()); |
6508 | 5640 } |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
5641 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
|
5642 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
|
5643 |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
5644 octave_value retval; |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
5645 |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
5646 switch (strflag) |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
5647 { |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
5648 case sfmatrix: |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
5649 retval = xnorm (x_arg, p_arg); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
5650 break; |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
5651 |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
5652 case sfcols: |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
5653 retval = xcolnorms (x_arg, p_arg); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
5654 break; |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
5655 |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
5656 case sfrows: |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
5657 retval = xrownorms (x_arg, p_arg); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
5658 break; |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
5659 |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
5660 case sffrob: |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
5661 retval = xfrobnorm (x_arg); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
5662 break; |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
5663 |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
5664 case sfinf: |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
5665 retval = xnorm (x_arg, octave_Inf); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
5666 break; |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
5667 } |
6508 | 5668 |
5669 return retval; | |
5670 } | |
5671 | |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5672 /* |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5673 %!shared x |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5674 %! x = [1, -3, 4, 5, -7]; |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5675 %!assert (norm (x,1), 20) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5676 %!assert (norm (x,2), 10) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5677 %!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
|
5678 %!assert (norm (x,Inf), 7) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5679 %!assert (norm (x,-Inf), 1) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5680 %!assert (norm (x,"inf"), 7) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5681 %!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
|
5682 %!assert (norm (x), 10) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5683 %!assert (norm ([1e200, 1]), 1e200) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5684 %!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
|
5685 %!shared m |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5686 %! m = magic (4); |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5687 %!assert (norm (m,1), 34) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5688 %!assert (norm (m,2), 34, -eps) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5689 %!assert (norm (m,Inf), 34) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5690 %!assert (norm (m,"inf"), 34) |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5691 %!shared m2, flo, fhi |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5692 %! m2 = [1,2;3,4]; |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5693 %! flo = 1e-300; |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5694 %! fhi = 1e+300; |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5695 %!assert (norm (flo*m2,"fro"), sqrt (30)*flo, -eps) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5696 %!assert (norm (fhi*m2,"fro"), sqrt (30)*fhi, -eps) |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5697 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5698 %!shared x |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5699 %! x = single ([1, -3, 4, 5, -7]); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5700 %!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
|
5701 %!assert (norm (x,2), single (10)) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5702 %!assert (norm (x,3), single (8.24257059961711), -4*eps ("single")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5703 %!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
|
5704 %!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
|
5705 %!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
|
5706 %!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
|
5707 %!assert (norm (x), single (10)) |
18676
5bd1ca29c5f0
Clean up questionable code bits identified by clang sanitize.
Rik <rik@octave.org>
parents:
18212
diff
changeset
|
5708 %!assert (norm (single ([1e38, 1])), single (1e38)) |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5709 %!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
|
5710 %!shared m |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5711 %! m = single (magic (4)); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5712 %!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
|
5713 %!assert (norm (m,2), single (34), -eps ("single")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5714 %!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
|
5715 %!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
|
5716 %!shared m2, flo, fhi |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5717 %! 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
|
5718 %! flo = single (1e-300); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5719 %! fhi = single (1e+300); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5720 %!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
|
5721 %!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
|
5722 |
17115
00985134145e
norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents:
16892
diff
changeset
|
5723 %!shared q |
00985134145e
norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents:
16892
diff
changeset
|
5724 %! q = rand (1e3, 3); |
00985134145e
norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents:
16892
diff
changeset
|
5725 %!assert (norm (q, 3, "rows"), sum (q.^3, 2).^(1/3), sqrt (eps)); |
00985134145e
norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents:
16892
diff
changeset
|
5726 %!assert (norm (q, "fro", "rows"), sum (q.^2, 2).^(1/2), sqrt (eps)); |
00985134145e
norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents:
16892
diff
changeset
|
5727 %!assert (norm (q, "fro", "rows"), sqrt (sumsq (q, 2)), sqrt (eps)); |
00985134145e
norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents:
16892
diff
changeset
|
5728 %!assert (norm (q, "fro", "cols"), sqrt (sumsq (q, 1)), sqrt (eps)); |
00985134145e
norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents:
16892
diff
changeset
|
5729 %!assert (norm (q, 3, "cols"), sum (q.^3, 1).^(1/3), sqrt (eps)); |
00985134145e
norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents:
16892
diff
changeset
|
5730 %!assert (norm (q, "inf", "rows"), norm (q, Inf, "rows")); |
00985134145e
norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents:
16892
diff
changeset
|
5731 %!assert (norm (q, "inf", "cols"), norm (q, Inf, "cols")); |
00985134145e
norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents:
16892
diff
changeset
|
5732 %!assert (norm (q, [], "rows"), norm (q, 2, "rows")); |
00985134145e
norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents:
16892
diff
changeset
|
5733 %!assert (norm (q, [], "cols"), norm (q, 2, "cols")); |
00985134145e
norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents:
16892
diff
changeset
|
5734 |
14520
c4ed0fdf2b62
Fix initialization in Higham's method for norm estimate (bug #36031).
Marco Caliari <marco.caliari@univr.it>
parents:
14491
diff
changeset
|
5735 %!test |
c4ed0fdf2b62
Fix initialization in Higham's method for norm estimate (bug #36031).
Marco Caliari <marco.caliari@univr.it>
parents:
14491
diff
changeset
|
5736 %! ## Test for norm returning NaN on sparse matrix (bug #30631) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
5737 %! 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
|
5738 %! 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
|
5739 %! assert (norm (A), 1); |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5740 */ |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5741 |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5742 static octave_value |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5743 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
|
5744 const octave_value_list& args) |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5745 { |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
5746 if (args.length () != 1) |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5747 print_usage (); |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5748 |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
5749 return do_unary_op (op, args(0)); |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5750 } |
6518 | 5751 |
5752 DEFUN (not, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
5753 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
5754 @deftypefn {} {@var{z} =} not (@var{x})\n\ |
19188
c3611856cdd4
xor.m: Extend to handle more than 2 arguments as a reduction operator.
Rik <rik@octave.org>
parents:
19152
diff
changeset
|
5755 Return the logical NOT of @var{x}.\n\ |
c3611856cdd4
xor.m: Extend to handle more than 2 arguments as a reduction operator.
Rik <rik@octave.org>
parents:
19152
diff
changeset
|
5756 \n\ |
c3611856cdd4
xor.m: Extend to handle more than 2 arguments as a reduction operator.
Rik <rik@octave.org>
parents:
19152
diff
changeset
|
5757 This function is equivalent to the operator syntax @w{@code{! x}}.\n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
5758 @seealso{and, or, xor}\n\ |
6518 | 5759 @end deftypefn") |
5760 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5761 return unary_op_defun_body (octave_value::op_not, args); |
6518 | 5762 } |
5763 | |
5764 DEFUN (uplus, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
5765 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
5766 @deftypefn {} {} uplus (@var{x})\n\ |
17268
1c21f264d26f
doc: Rename @xcode macro to @tcode (transpose code) for clarity.
Rik <rik@octave.org>
parents:
17206
diff
changeset
|
5767 This function and @w{@tcode{+ x}} are equivalent.\n\ |
15028
397f0d80bd47
Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents:
15024
diff
changeset
|
5768 @seealso{uminus, plus, minus}\n\ |
6518 | 5769 @end deftypefn") |
5770 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5771 return unary_op_defun_body (octave_value::op_uplus, args); |
6518 | 5772 } |
5773 | |
5774 DEFUN (uminus, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
5775 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
5776 @deftypefn {} {} uminus (@var{x})\n\ |
17268
1c21f264d26f
doc: Rename @xcode macro to @tcode (transpose code) for clarity.
Rik <rik@octave.org>
parents:
17206
diff
changeset
|
5777 This function and @w{@tcode{- x}} are equivalent.\n\ |
15028
397f0d80bd47
Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents:
15024
diff
changeset
|
5778 @seealso{uplus, minus}\n\ |
6518 | 5779 @end deftypefn") |
5780 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5781 return unary_op_defun_body (octave_value::op_uminus, args); |
6518 | 5782 } |
5783 | |
5784 DEFUN (transpose, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
5785 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
5786 @deftypefn {} {} transpose (@var{x})\n\ |
13780
990762e784fe
Fix confusing interaction between @code macro and transpose operator (') in documentation (Bug #34661).
Rik <octave@nomad.inbox5.com>
parents:
13760
diff
changeset
|
5787 Return the transpose of @var{x}.\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
5788 \n\ |
17268
1c21f264d26f
doc: Rename @xcode macro to @tcode (transpose code) for clarity.
Rik <rik@octave.org>
parents:
17206
diff
changeset
|
5789 This function and @tcode{x.'} are equivalent.\n\ |
11422
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
5790 @seealso{ctranspose}\n\ |
6518 | 5791 @end deftypefn") |
5792 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5793 return unary_op_defun_body (octave_value::op_transpose, args); |
6518 | 5794 } |
5795 | |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5796 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5797 %!assert (2.', 2) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5798 %!assert (2i.', 2i) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5799 %!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
|
5800 %!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
|
5801 %!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
|
5802 %!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
|
5803 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5804 %!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
|
5805 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5806 %!assert (single (2).', single (2)) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5807 %!assert (single (2i).', single (2i)) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5808 %!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
|
5809 %!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
|
5810 %!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
|
5811 %!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
|
5812 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5813 %!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
|
5814 */ |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5815 |
6518 | 5816 DEFUN (ctranspose, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
5817 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
5818 @deftypefn {} {} ctranspose (@var{x})\n\ |
13780
990762e784fe
Fix confusing interaction between @code macro and transpose operator (') in documentation (Bug #34661).
Rik <octave@nomad.inbox5.com>
parents:
13760
diff
changeset
|
5819 Return the complex conjugate transpose of @var{x}.\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
5820 \n\ |
17268
1c21f264d26f
doc: Rename @xcode macro to @tcode (transpose code) for clarity.
Rik <rik@octave.org>
parents:
17206
diff
changeset
|
5821 This function and @tcode{x'} are equivalent.\n\ |
11422
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
5822 @seealso{transpose}\n\ |
6518 | 5823 @end deftypefn") |
5824 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5825 return unary_op_defun_body (octave_value::op_hermitian, args); |
6518 | 5826 } |
5827 | |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5828 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5829 %!assert (2', 2) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5830 %!assert (2i', -2i) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5831 %!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
|
5832 %!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
|
5833 %!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
|
5834 %!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
|
5835 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5836 %!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
|
5837 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5838 %!assert (single (2)', single (2)) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5839 %!assert (single (2i)', single (-2i)) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5840 %!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
|
5841 %!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
|
5842 %!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
|
5843 %!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
|
5844 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5845 %!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
|
5846 */ |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5847 |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5848 static octave_value |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5849 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
|
5850 const octave_value_list& args) |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5851 { |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
5852 if (args.length () != 2) |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5853 print_usage (); |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5854 |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
5855 return do_binary_op (op, args(0), args(1)); |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5856 } |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5857 |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5858 static octave_value |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5859 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
|
5860 octave_value::assign_op aop, |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5861 const octave_value_list& args) |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5862 { |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5863 int nargin = args.length (); |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5864 |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
5865 if (nargin == 0) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
5866 print_usage (); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
5867 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
5868 octave_value retval; |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
5869 |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
5870 if (nargin == 1) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
5871 retval = args(0); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
5872 else if (nargin == 2) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
5873 retval = do_binary_op (op, args(0), args(1)); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
5874 else |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5875 { |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5876 retval = do_binary_op (op, args(0), args(1)); |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
5877 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
5878 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
|
5879 retval.assign (aop, args(i)); |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5880 } |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5881 |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5882 return retval; |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5883 } |
9339
c0b104835d0d
allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
5884 |
6518 | 5885 DEFUN (plus, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
5886 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
5887 @deftypefn {} {} plus (@var{x}, @var{y})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
5888 @deftypefnx {} {} plus (@var{x1}, @var{x2}, @dots{})\n\ |
17268
1c21f264d26f
doc: Rename @xcode macro to @tcode (transpose code) for clarity.
Rik <rik@octave.org>
parents:
17206
diff
changeset
|
5889 This function and @w{@tcode{x + y}} are equivalent.\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
5890 \n\ |
9339
c0b104835d0d
allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
5891 If more arguments are given, the summation is applied\n\ |
c0b104835d0d
allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
5892 cumulatively from left to right:\n\ |
c0b104835d0d
allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
5893 \n\ |
c0b104835d0d
allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
5894 @example\n\ |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
5895 (@dots{}((x1 + x2) + x3) + @dots{})\n\ |
9339
c0b104835d0d
allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
5896 @end example\n\ |
c0b104835d0d
allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
5897 \n\ |
11422
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
5898 At least one argument is required.\n\ |
15028
397f0d80bd47
Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents:
15024
diff
changeset
|
5899 @seealso{minus, uplus}\n\ |
6518 | 5900 @end deftypefn") |
5901 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5902 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
|
5903 octave_value::op_add_eq, args); |
6518 | 5904 } |
5905 | |
5906 DEFUN (minus, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
5907 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
5908 @deftypefn {} {} minus (@var{x}, @var{y})\n\ |
17268
1c21f264d26f
doc: Rename @xcode macro to @tcode (transpose code) for clarity.
Rik <rik@octave.org>
parents:
17206
diff
changeset
|
5909 This function and @w{@tcode{x - y}} are equivalent.\n\ |
15028
397f0d80bd47
Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents:
15024
diff
changeset
|
5910 @seealso{plus, uminus}\n\ |
6518 | 5911 @end deftypefn") |
5912 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5913 return binary_op_defun_body (octave_value::op_sub, args); |
6518 | 5914 } |
5915 | |
5916 DEFUN (mtimes, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
5917 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
5918 @deftypefn {} {} mtimes (@var{x}, @var{y})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
5919 @deftypefnx {} {} mtimes (@var{x1}, @var{x2}, @dots{})\n\ |
11575
d6619410e79c
Spellcheck documentation before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents:
11572
diff
changeset
|
5920 Return the matrix multiplication product of inputs.\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
5921 \n\ |
17268
1c21f264d26f
doc: Rename @xcode macro to @tcode (transpose code) for clarity.
Rik <rik@octave.org>
parents:
17206
diff
changeset
|
5922 This function and @w{@tcode{x * y}} are equivalent.\n\ |
9339
c0b104835d0d
allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
5923 If more arguments are given, the multiplication is applied\n\ |
c0b104835d0d
allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
5924 cumulatively from left to right:\n\ |
c0b104835d0d
allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
5925 \n\ |
c0b104835d0d
allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
5926 @example\n\ |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
5927 (@dots{}((x1 * x2) * x3) * @dots{})\n\ |
9339
c0b104835d0d
allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
5928 @end example\n\ |
c0b104835d0d
allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
5929 \n\ |
11575
d6619410e79c
Spellcheck documentation before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents:
11572
diff
changeset
|
5930 At least one argument is required.\n\ |
15028
397f0d80bd47
Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents:
15024
diff
changeset
|
5931 @seealso{times, plus, minus, rdivide, mrdivide, mldivide, mpower}\n\ |
6518 | 5932 @end deftypefn") |
5933 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5934 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
|
5935 octave_value::op_mul_eq, args); |
6518 | 5936 } |
5937 | |
5938 DEFUN (mrdivide, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
5939 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
5940 @deftypefn {} {} mrdivide (@var{x}, @var{y})\n\ |
11422
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
5941 Return the matrix right division of @var{x} and @var{y}.\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
5942 \n\ |
17268
1c21f264d26f
doc: Rename @xcode macro to @tcode (transpose code) for clarity.
Rik <rik@octave.org>
parents:
17206
diff
changeset
|
5943 This function and @w{@tcode{x / y}} are equivalent.\n\ |
15028
397f0d80bd47
Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents:
15024
diff
changeset
|
5944 @seealso{mldivide, rdivide, plus, minus}\n\ |
6518 | 5945 @end deftypefn") |
5946 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5947 return binary_op_defun_body (octave_value::op_div, args); |
6518 | 5948 } |
5949 | |
5950 DEFUN (mpower, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
5951 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
5952 @deftypefn {} {} mpower (@var{x}, @var{y})\n\ |
11422
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
5953 Return the matrix power operation of @var{x} raised to the @var{y} power.\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
5954 \n\ |
17268
1c21f264d26f
doc: Rename @xcode macro to @tcode (transpose code) for clarity.
Rik <rik@octave.org>
parents:
17206
diff
changeset
|
5955 This function and @w{@tcode{x ^ y}} are equivalent.\n\ |
15034
1116864ee270
doc: Fix for bad cross-referencing due to use of aliases in Texinfo.
Rik <rik@octave.org>
parents:
15031
diff
changeset
|
5956 @seealso{power, mtimes, plus, minus}\n\ |
6518 | 5957 @end deftypefn") |
5958 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5959 return binary_op_defun_body (octave_value::op_pow, args); |
6518 | 5960 } |
5961 | |
5962 DEFUN (mldivide, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
5963 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
5964 @deftypefn {} {} mldivide (@var{x}, @var{y})\n\ |
11422
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
5965 Return the matrix left division of @var{x} and @var{y}.\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
5966 \n\ |
17268
1c21f264d26f
doc: Rename @xcode macro to @tcode (transpose code) for clarity.
Rik <rik@octave.org>
parents:
17206
diff
changeset
|
5967 This function and @w{@tcode{x @xbackslashchar{} y}} are equivalent.\n\ |
15028
397f0d80bd47
Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents:
15024
diff
changeset
|
5968 @seealso{mrdivide, ldivide, rdivide}\n\ |
6518 | 5969 @end deftypefn") |
5970 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5971 return binary_op_defun_body (octave_value::op_ldiv, args); |
6518 | 5972 } |
5973 | |
5974 DEFUN (lt, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
5975 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
5976 @deftypefn {} {} lt (@var{x}, @var{y})\n\ |
11422
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
5977 This function is equivalent to @w{@code{x < y}}.\n\ |
15028
397f0d80bd47
Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents:
15024
diff
changeset
|
5978 @seealso{le, eq, ge, gt, ne}\n\ |
6518 | 5979 @end deftypefn") |
5980 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5981 return binary_op_defun_body (octave_value::op_lt, args); |
6518 | 5982 } |
5983 | |
5984 DEFUN (le, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
5985 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
5986 @deftypefn {} {} le (@var{x}, @var{y})\n\ |
11422
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
5987 This function is equivalent to @w{@code{x <= y}}.\n\ |
15028
397f0d80bd47
Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents:
15024
diff
changeset
|
5988 @seealso{eq, ge, gt, ne, lt}\n\ |
6518 | 5989 @end deftypefn") |
5990 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5991 return binary_op_defun_body (octave_value::op_le, args); |
6518 | 5992 } |
5993 | |
5994 DEFUN (eq, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
5995 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
5996 @deftypefn {} {} eq (@var{x}, @var{y})\n\ |
11422
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
5997 Return true if the two inputs are equal.\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
5998 \n\ |
11422
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
5999 This function is equivalent to @w{@code{x == y}}.\n\ |
15028
397f0d80bd47
Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents:
15024
diff
changeset
|
6000 @seealso{ne, isequal, le, ge, gt, ne, lt}\n\ |
6518 | 6001 @end deftypefn") |
6002 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
6003 return binary_op_defun_body (octave_value::op_eq, args); |
6518 | 6004 } |
6005 | |
6006 DEFUN (ge, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
6007 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
6008 @deftypefn {} {} ge (@var{x}, @var{y})\n\ |
11422
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
6009 This function is equivalent to @w{@code{x >= y}}.\n\ |
15028
397f0d80bd47
Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents:
15024
diff
changeset
|
6010 @seealso{le, eq, gt, ne, lt}\n\ |
6518 | 6011 @end deftypefn") |
6012 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
6013 return binary_op_defun_body (octave_value::op_ge, args); |
6518 | 6014 } |
6015 | |
6016 DEFUN (gt, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
6017 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
6018 @deftypefn {} {} gt (@var{x}, @var{y})\n\ |
11422
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
6019 This function is equivalent to @w{@code{x > y}}.\n\ |
15028
397f0d80bd47
Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents:
15024
diff
changeset
|
6020 @seealso{le, eq, ge, ne, lt}\n\ |
6518 | 6021 @end deftypefn") |
6022 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
6023 return binary_op_defun_body (octave_value::op_gt, args); |
6518 | 6024 } |
6025 | |
6026 DEFUN (ne, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
6027 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
6028 @deftypefn {} {} ne (@var{x}, @var{y})\n\ |
11422
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
6029 Return true if the two inputs are not equal.\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
6030 \n\ |
11422
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
6031 This function is equivalent to @w{@code{x != y}}.\n\ |
15028
397f0d80bd47
Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents:
15024
diff
changeset
|
6032 @seealso{eq, isequal, le, ge, lt}\n\ |
6518 | 6033 @end deftypefn") |
6034 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
6035 return binary_op_defun_body (octave_value::op_ne, args); |
6518 | 6036 } |
6037 | |
6038 DEFUN (times, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
6039 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
6040 @deftypefn {} {} times (@var{x}, @var{y})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
6041 @deftypefnx {} {} times (@var{x1}, @var{x2}, @dots{})\n\ |
11422
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
6042 Return the element-by-element multiplication product of inputs.\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
6043 \n\ |
17268
1c21f264d26f
doc: Rename @xcode macro to @tcode (transpose code) for clarity.
Rik <rik@octave.org>
parents:
17206
diff
changeset
|
6044 This function and @w{@tcode{x .* y}} are equivalent.\n\ |
9339
c0b104835d0d
allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
6045 If more arguments are given, the multiplication is applied\n\ |
c0b104835d0d
allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
6046 cumulatively from left to right:\n\ |
c0b104835d0d
allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
6047 \n\ |
c0b104835d0d
allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
6048 @example\n\ |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
6049 (@dots{}((x1 .* x2) .* x3) .* @dots{})\n\ |
9339
c0b104835d0d
allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
6050 @end example\n\ |
c0b104835d0d
allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
6051 \n\ |
11422
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
6052 At least one argument is required.\n\ |
15028
397f0d80bd47
Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents:
15024
diff
changeset
|
6053 @seealso{mtimes, rdivide}\n\ |
6518 | 6054 @end deftypefn") |
6055 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
6056 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
|
6057 octave_value::op_el_mul_eq, args); |
6518 | 6058 } |
6059 | |
6060 DEFUN (rdivide, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
6061 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
6062 @deftypefn {} {} rdivide (@var{x}, @var{y})\n\ |
11422
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
6063 Return the element-by-element right division of @var{x} and @var{y}.\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
6064 \n\ |
17268
1c21f264d26f
doc: Rename @xcode macro to @tcode (transpose code) for clarity.
Rik <rik@octave.org>
parents:
17206
diff
changeset
|
6065 This function and @w{@tcode{x ./ y}} are equivalent.\n\ |
15028
397f0d80bd47
Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents:
15024
diff
changeset
|
6066 @seealso{ldivide, mrdivide, times, plus}\n\ |
6518 | 6067 @end deftypefn") |
6068 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
6069 return binary_op_defun_body (octave_value::op_el_div, args); |
6518 | 6070 } |
6071 | |
6072 DEFUN (power, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
6073 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
6074 @deftypefn {} {} power (@var{x}, @var{y})\n\ |
11422
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
6075 Return the element-by-element operation of @var{x} raised to the\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
6076 @var{y} power.\n\ |
14169
c0ca47ab7641
doc: Better explain which complex result is chosen by .^
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
6077 \n\ |
17268
1c21f264d26f
doc: Rename @xcode macro to @tcode (transpose code) for clarity.
Rik <rik@octave.org>
parents:
17206
diff
changeset
|
6078 This function and @w{@tcode{x .^ y}} are equivalent.\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
6079 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
6080 If several complex results are possible, returns the one with smallest\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
6081 non-negative argument (angle). Use @code{realpow}, @code{realsqrt},\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
6082 @code{cbrt}, or @code{nthroot} if a real result is preferred.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
6083 \n\ |
14169
c0ca47ab7641
doc: Better explain which complex result is chosen by .^
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
6084 @seealso{mpower, realpow, realsqrt, cbrt, nthroot}\n\ |
6518 | 6085 @end deftypefn") |
6086 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
6087 return binary_op_defun_body (octave_value::op_el_pow, args); |
6518 | 6088 } |
6089 | |
6090 DEFUN (ldivide, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
6091 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
6092 @deftypefn {} {} ldivide (@var{x}, @var{y})\n\ |
11422
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
6093 Return the element-by-element left division of @var{x} and @var{y}.\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
6094 \n\ |
17268
1c21f264d26f
doc: Rename @xcode macro to @tcode (transpose code) for clarity.
Rik <rik@octave.org>
parents:
17206
diff
changeset
|
6095 This function and @w{@tcode{x .@xbackslashchar{} y}} are equivalent.\n\ |
15028
397f0d80bd47
Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents:
15024
diff
changeset
|
6096 @seealso{rdivide, mldivide, times, plus}\n\ |
6518 | 6097 @end deftypefn") |
6098 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
6099 return binary_op_defun_body (octave_value::op_el_ldiv, args); |
6518 | 6100 } |
6101 | |
6102 DEFUN (and, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
6103 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
6104 @deftypefn {} {@var{z} =} and (@var{x}, @var{y})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
6105 @deftypefnx {} {@var{z} =} and (@var{x1}, @var{x2}, @dots{})\n\ |
11422
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
6106 Return the logical AND of @var{x} and @var{y}.\n\ |
19188
c3611856cdd4
xor.m: Extend to handle more than 2 arguments as a reduction operator.
Rik <rik@octave.org>
parents:
19152
diff
changeset
|
6107 \n\ |
c3611856cdd4
xor.m: Extend to handle more than 2 arguments as a reduction operator.
Rik <rik@octave.org>
parents:
19152
diff
changeset
|
6108 This function is equivalent to the operator syntax @w{@code{x & y}}. If\n\ |
c3611856cdd4
xor.m: Extend to handle more than 2 arguments as a reduction operator.
Rik <rik@octave.org>
parents:
19152
diff
changeset
|
6109 more than two arguments are given, the logical AND is applied cumulatively\n\ |
c3611856cdd4
xor.m: Extend to handle more than 2 arguments as a reduction operator.
Rik <rik@octave.org>
parents:
19152
diff
changeset
|
6110 from left to right:\n\ |
9339
c0b104835d0d
allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
6111 \n\ |
c0b104835d0d
allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
6112 @example\n\ |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
6113 (@dots{}((x1 & x2) & x3) & @dots{})\n\ |
9339
c0b104835d0d
allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
6114 @end example\n\ |
c0b104835d0d
allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
6115 \n\ |
11422
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
6116 At least one argument is required.\n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
6117 @seealso{or, not, xor}\n\ |
6518 | 6118 @end deftypefn") |
6119 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
6120 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
|
6121 octave_value::op_el_and_eq, args); |
6518 | 6122 } |
6123 | |
6124 DEFUN (or, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
6125 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
6126 @deftypefn {} {@var{z} =} or (@var{x}, @var{y})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
6127 @deftypefnx {} {@var{z} =} or (@var{x1}, @var{x2}, @dots{})\n\ |
11422
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
6128 Return the logical OR of @var{x} and @var{y}.\n\ |
19188
c3611856cdd4
xor.m: Extend to handle more than 2 arguments as a reduction operator.
Rik <rik@octave.org>
parents:
19152
diff
changeset
|
6129 \n\ |
c3611856cdd4
xor.m: Extend to handle more than 2 arguments as a reduction operator.
Rik <rik@octave.org>
parents:
19152
diff
changeset
|
6130 This function is equivalent to the operator syntax @w{@code{x | y}}. If\n\ |
c3611856cdd4
xor.m: Extend to handle more than 2 arguments as a reduction operator.
Rik <rik@octave.org>
parents:
19152
diff
changeset
|
6131 more than two arguments are given, the logical OR is applied cumulatively\n\ |
c3611856cdd4
xor.m: Extend to handle more than 2 arguments as a reduction operator.
Rik <rik@octave.org>
parents:
19152
diff
changeset
|
6132 from left to right:\n\ |
9339
c0b104835d0d
allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
6133 \n\ |
c0b104835d0d
allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
6134 @example\n\ |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
6135 (@dots{}((x1 | x2) | x3) | @dots{})\n\ |
9339
c0b104835d0d
allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
6136 @end example\n\ |
c0b104835d0d
allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
6137 \n\ |
11422
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
6138 At least one argument is required.\n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
6139 @seealso{and, not, xor}\n\ |
6518 | 6140 @end deftypefn") |
6141 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
6142 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
|
6143 octave_value::op_el_or_eq, args); |
6518 | 6144 } |
6145 | |
19749
c913247c85a8
make colon function work (bug #44290)
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
6146 DEFUN (colon, args, , |
c913247c85a8
make colon function work (bug #44290)
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
6147 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
6148 @deftypefn {} {@var{r} =} colon (@var{base}, @var{limit})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
6149 @deftypefnx {} {@var{r} =} colon (@var{base}, @var{increment}, @var{limit})\n\ |
19795
ca7599ae464d
doc: Grammarcheck documentation ahead of 4.0 release.
Rik <rik@octave.org>
parents:
19749
diff
changeset
|
6150 Return the result of the colon expression corresponding to @var{base},\n\ |
ca7599ae464d
doc: Grammarcheck documentation ahead of 4.0 release.
Rik <rik@octave.org>
parents:
19749
diff
changeset
|
6151 @var{limit}, and optionally, @var{increment}.\n\ |
19749
c913247c85a8
make colon function work (bug #44290)
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
6152 \n\ |
c913247c85a8
make colon function work (bug #44290)
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
6153 This function is equivalent to the operator syntax @w{@code{base : limit}}\n\ |
c913247c85a8
make colon function work (bug #44290)
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
6154 or @w{@code{base : increment : limit}}.\n\ |
c913247c85a8
make colon function work (bug #44290)
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
6155 @end deftypefn") |
c913247c85a8
make colon function work (bug #44290)
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
6156 { |
c913247c85a8
make colon function work (bug #44290)
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
6157 int nargin = args.length (); |
c913247c85a8
make colon function work (bug #44290)
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
6158 |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6159 if (nargin < 2 || nargin > 3) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6160 print_usage (); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6161 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
6162 return (nargin == 2) ? do_colon_op (args(0), args(1)) |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
6163 : do_colon_op (args(0), args(1), args(2)); |
19749
c913247c85a8
make colon function work (bug #44290)
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
6164 } |
c913247c85a8
make colon function work (bug #44290)
John W. Eaton <jwe@octave.org>
parents:
19743
diff
changeset
|
6165 |
7065 | 6166 static double tic_toc_timestamp = -1.0; |
7045 | 6167 |
6168 DEFUN (tic, args, nargout, | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
6169 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
6170 @deftypefn {} {} tic ()\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
6171 @deftypefnx {} {@var{id} =} tic ()\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
6172 @deftypefnx {} {} toc ()\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
6173 @deftypefnx {} {} toc (@var{id})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
6174 @deftypefnx {} {@var{val} =} toc (@dots{})\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
6175 Set or check a wall-clock timer.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
6176 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
6177 Calling @code{tic} without an output argument sets the internal timer state.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
6178 Subsequent calls to @code{toc} return the number of seconds since the timer\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
6179 was set.\n\ |
14635
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
6180 For example,\n\ |
7045 | 6181 \n\ |
6182 @example\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
9041
diff
changeset
|
6183 @group\n\ |
7045 | 6184 tic ();\n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
9041
diff
changeset
|
6185 # many computations later@dots{}\n\ |
7045 | 6186 elapsed_time = toc ();\n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
9041
diff
changeset
|
6187 @end group\n\ |
7045 | 6188 @end example\n\ |
6189 \n\ | |
6190 @noindent\n\ | |
6191 will set the variable @code{elapsed_time} to the number of seconds since\n\ | |
6192 the most recent call to the function @code{tic}.\n\ | |
6193 \n\ | |
14635
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
6194 If called with one output argument, @code{tic} returns a scalar\n\ |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
6195 of type @code{uint64} that may be later passed to @code{toc}.\n\ |
7045 | 6196 \n\ |
6197 @example\n\ | |
6198 @group\n\ | |
20923
58263bea2fdf
Unified "sleep" functions to "octave_sleep" in C++ and "pause" in Octave.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
20921
diff
changeset
|
6199 id = tic; pause (5); toc (id)\n\ |
14635
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
6200 @result{} 5.0010\n\ |
7045 | 6201 @end group\n\ |
6202 @end example\n\ | |
6203 \n\ | |
14635
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
6204 Calling @code{tic} and @code{toc} this way allows nested timing calls.\n\ |
7045 | 6205 \n\ |
6206 If you are more interested in the CPU time that your process used, you\n\ | |
6207 should use the @code{cputime} function instead. The @code{tic} and\n\ | |
6208 @code{toc} functions report the actual wall clock time that elapsed\n\ | |
6209 between the calls. This may include time spent processing other jobs or\n\ | |
14635
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
6210 doing nothing at all.\n\ |
15028
397f0d80bd47
Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents:
15024
diff
changeset
|
6211 @seealso{toc, cputime}\n\ |
7045 | 6212 @end deftypefn") |
6213 { | |
20819
f428cbe7576f
eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents:
20816
diff
changeset
|
6214 if (args.length () != 0) |
7045 | 6215 warning ("tic: ignoring extra arguments"); |
6216 | |
21078
49852ff04747
maint: Remove unnecessary declarations of retval.
Rik <rik@octave.org>
parents:
21062
diff
changeset
|
6217 octave_value retval; |
7065 | 6218 octave_time now; |
6219 double tmp = now.double_value (); | |
6220 | |
7045 | 6221 if (nargout > 0) |
14635
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
6222 { |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
6223 double ip = 0.0; |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
6224 double frac = modf (tmp, &ip); |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
6225 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
|
6226 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
|
6227 retval = octave_uint64 (microsecs); |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
6228 } |
7045 | 6229 else |
7065 | 6230 tic_toc_timestamp = tmp; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
6231 |
7045 | 6232 return retval; |
6233 } | |
6234 | |
6235 DEFUN (toc, args, nargout, | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
6236 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
6237 @deftypefn {} {} toc ()\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
6238 @deftypefnx {} {} toc (@var{id})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
6239 @deftypefnx {} {@var{val} =} toc (@dots{})\n\ |
15028
397f0d80bd47
Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents:
15024
diff
changeset
|
6240 @seealso{tic, cputime}\n\ |
7045 | 6241 @end deftypefn") |
6242 { | |
6243 int nargin = args.length (); | |
6244 | |
14635
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
6245 if (nargin > 1) |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
6246 print_usage (); |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6247 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
6248 double start_time = tic_toc_timestamp; |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
6249 |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6250 if (nargin == 1) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6251 { |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6252 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
|
6253 |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6254 uint64_t val = id.value (); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6255 |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6256 start_time |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6257 = (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
|
6258 + 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
|
6259 / CLOCKS_PER_SEC); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6260 |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6261 // 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
|
6262 // time is after the beginning of this Octave session? |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6263 } |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6264 |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6265 if (start_time < 0) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6266 error ("toc called before timer set"); |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
6267 |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
6268 octave_time now; |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
6269 |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
6270 double etime = now.double_value () - start_time; |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
6271 |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
6272 octave_value retval; |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
6273 if (nargout > 0) |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
6274 retval = etime; |
7045 | 6275 else |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
6276 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
|
6277 |
7045 | 6278 return retval; |
6279 } | |
6280 | |
14635
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
6281 /* |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
6282 %!shared id |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
6283 %! id = tic (); |
14849
f6d3d5b0bd42
test: Use Octave coding conventions for tests for line() and toc().
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
6284 %!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
|
6285 %!assert (isa (toc (id), "double")) |
14635
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
6286 */ |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
6287 |
7045 | 6288 DEFUN (cputime, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
6289 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
6290 @deftypefn {} {[@var{total}, @var{user}, @var{system}] =} cputime ();\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
6291 Return the CPU time used by your Octave session.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
6292 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
6293 The first output is the total time spent executing your process and is equal\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
6294 to the sum of second and third outputs, which are the number of CPU seconds\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
6295 spent executing in user mode and the number of CPU seconds spent executing\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
6296 in system mode, respectively.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
6297 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
6298 If your system does not have a way to report CPU time usage, @code{cputime}\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
6299 returns 0 for each of its output values.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
6300 \n\ |
7045 | 6301 Note that because Octave used some CPU time to start, it is reasonable\n\ |
6302 to check to see if @code{cputime} works by checking to see if the total\n\ | |
6303 CPU time used is nonzero.\n\ | |
15028
397f0d80bd47
Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents:
15024
diff
changeset
|
6304 @seealso{tic, toc}\n\ |
7045 | 6305 @end deftypefn") |
6306 { | |
21078
49852ff04747
maint: Remove unnecessary declarations of retval.
Rik <rik@octave.org>
parents:
21062
diff
changeset
|
6307 if (args.length () != 0) |
49852ff04747
maint: Remove unnecessary declarations of retval.
Rik <rik@octave.org>
parents:
21062
diff
changeset
|
6308 warning ("cputime: ignoring extra arguments"); |
49852ff04747
maint: Remove unnecessary declarations of retval.
Rik <rik@octave.org>
parents:
21062
diff
changeset
|
6309 |
7045 | 6310 double usr = 0.0; |
6311 double sys = 0.0; | |
6312 | |
6313 #if defined (HAVE_GETRUSAGE) | |
6314 | |
6315 struct rusage ru; | |
6316 | |
6317 getrusage (RUSAGE_SELF, &ru); | |
6318 | |
6319 usr = static_cast<double> (ru.ru_utime.tv_sec) + | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
6320 static_cast<double> (ru.ru_utime.tv_usec) * 1e-6; |
7045 | 6321 |
6322 sys = static_cast<double> (ru.ru_stime.tv_sec) + | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
6323 static_cast<double> (ru.ru_stime.tv_usec) * 1e-6; |
7045 | 6324 |
10240
fa7b5751730c
use gnulib time, sys_time, and sys_times modules
John W. Eaton <jwe@octave.org>
parents:
10185
diff
changeset
|
6325 #else |
7045 | 6326 |
6327 struct tms t; | |
6328 | |
6329 times (&t); | |
6330 | |
6331 unsigned long ticks; | |
6332 unsigned long seconds; | |
6333 unsigned long fraction; | |
6334 | |
6335 ticks = t.tms_utime + t.tms_cutime; | |
10303
e4899d6320b6
data.cc: use CLOCKS_PER_SEC instead of HZ
John W. Eaton <jwe@octave.org>
parents:
10302
diff
changeset
|
6336 fraction = ticks % CLOCKS_PER_SEC; |
e4899d6320b6
data.cc: use CLOCKS_PER_SEC instead of HZ
John W. Eaton <jwe@octave.org>
parents:
10302
diff
changeset
|
6337 seconds = ticks / CLOCKS_PER_SEC; |
7045 | 6338 |
6339 usr = static_cast<double> (seconds) + static_cast<double>(fraction) / | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
6340 static_cast<double>(CLOCKS_PER_SEC); |
7045 | 6341 |
6342 ticks = t.tms_stime + t.tms_cstime; | |
10303
e4899d6320b6
data.cc: use CLOCKS_PER_SEC instead of HZ
John W. Eaton <jwe@octave.org>
parents:
10302
diff
changeset
|
6343 fraction = ticks % CLOCKS_PER_SEC; |
e4899d6320b6
data.cc: use CLOCKS_PER_SEC instead of HZ
John W. Eaton <jwe@octave.org>
parents:
10302
diff
changeset
|
6344 seconds = ticks / CLOCKS_PER_SEC; |
7045 | 6345 |
6346 sys = static_cast<double> (seconds) + static_cast<double>(fraction) / | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
6347 static_cast<double>(CLOCKS_PER_SEC); |
7045 | 6348 |
6349 #endif | |
6350 | |
21078
49852ff04747
maint: Remove unnecessary declarations of retval.
Rik <rik@octave.org>
parents:
21062
diff
changeset
|
6351 return ovl (sys + usr, usr, sys); |
7045 | 6352 } |
6353 | |
7433 | 6354 DEFUN (sort, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
6355 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
6356 @deftypefn {} {[@var{s}, @var{i}] =} sort (@var{x})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
6357 @deftypefnx {} {[@var{s}, @var{i}] =} sort (@var{x}, @var{dim})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
6358 @deftypefnx {} {[@var{s}, @var{i}] =} sort (@var{x}, @var{mode})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
6359 @deftypefnx {} {[@var{s}, @var{i}] =} sort (@var{x}, @var{dim}, @var{mode})\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
6360 Return a copy of @var{x} with the elements arranged in increasing order.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
6361 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
6362 For matrices, @code{sort} orders the elements within columns\n\ |
7433 | 6363 \n\ |
10840 | 6364 For example:\n\ |
7433 | 6365 \n\ |
6366 @example\n\ | |
6367 @group\n\ | |
6368 sort ([1, 2; 2, 3; 3, 1])\n\ | |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
6369 @result{} 1 1\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
6370 2 2\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
6371 3 3\n\ |
7433 | 6372 @end group\n\ |
6373 @end example\n\ | |
6374 \n\ | |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
6375 If the optional argument @var{dim} is given, then the matrix is sorted\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
6376 along the dimension defined by @var{dim}. The optional argument @code{mode}\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
6377 defines the order in which the values will be sorted. Valid values of\n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17268
diff
changeset
|
6378 @code{mode} are @qcode{\"ascend\"} or @qcode{\"descend\"}.\n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
6379 \n\ |
7433 | 6380 The @code{sort} function may also be used to produce a matrix\n\ |
6381 containing the original row indices of the elements in the sorted\n\ | |
10840 | 6382 matrix. For example:\n\ |
7433 | 6383 \n\ |
6384 @example\n\ | |
6385 @group\n\ | |
6386 [s, i] = sort ([1, 2; 2, 3; 3, 1])\n\ | |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
6387 @result{} s = 1 1\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
6388 2 2\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
6389 3 3\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
6390 @result{} i = 1 3\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
6391 2 1\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
6392 3 2\n\ |
7433 | 6393 @end group\n\ |
6394 @end example\n\ | |
6395 \n\ | |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
6396 For equal elements, the indices are such that equal elements are listed\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
6397 in the order in which they appeared in the original list.\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
6398 \n\ |
20569
c6059134f5d3
data.cc: Add @w{} around @code segments in docstrings to prevent line breaks.
Rik <rik@octave.org>
parents:
20398
diff
changeset
|
6399 Sorting of complex entries is done first by magnitude\n\ |
c6059134f5d3
data.cc: Add @w{} around @code segments in docstrings to prevent line breaks.
Rik <rik@octave.org>
parents:
20398
diff
changeset
|
6400 (@w{@code{abs (@var{z})}}) and for any ties by phase angle\n\ |
c6059134f5d3
data.cc: Add @w{} around @code segments in docstrings to prevent line breaks.
Rik <rik@octave.org>
parents:
20398
diff
changeset
|
6401 (@w{@code{angle (z)}}). For example:\n\ |
7433 | 6402 \n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
6403 @example\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
6404 @group\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
6405 sort ([1+i; 1; 1-i])\n\ |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
6406 @result{} 1 + 0i\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
6407 1 - 1i\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
6408 1 + 1i\n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
6409 @end group\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
6410 @end example\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
6411 \n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
6412 NaN values are treated as being greater than any other value and are sorted\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
6413 to the end of the list.\n\ |
7433 | 6414 \n\ |
6415 The @code{sort} function may also be used to sort strings and cell arrays\n\ | |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
6416 of strings, in which case ASCII dictionary order (uppercase 'A' precedes\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
6417 lowercase 'a') of the strings is used.\n\ |
7433 | 6418 \n\ |
6419 The algorithm used in @code{sort} is optimized for the sorting of partially\n\ | |
6420 ordered lists.\n\ | |
15028
397f0d80bd47
Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents:
15024
diff
changeset
|
6421 @seealso{sortrows, issorted}\n\ |
7433 | 6422 @end deftypefn") |
6423 { | |
6424 int nargin = args.length (); | |
6425 | |
6426 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
|
6427 print_usage (); |
7433 | 6428 |
20884
f1b2a2dbc0e1
2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents:
20853
diff
changeset
|
6429 sortmode smode = ASCENDING; |
f1b2a2dbc0e1
2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents:
20853
diff
changeset
|
6430 bool return_idx = (nargout > 1); |
20921
4d3daf7e43f3
eliminate trailing whitespace in source files
John W. Eaton <jwe@octave.org>
parents:
20918
diff
changeset
|
6431 bool have_sortmode = (nargin > 1 && args(1).is_string ()); |
7433 | 6432 octave_value arg = args(0); |
6433 | |
6434 int dim = 0; | |
6435 if (nargin > 1) | |
6436 { | |
20884
f1b2a2dbc0e1
2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents:
20853
diff
changeset
|
6437 if (have_sortmode) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
6438 { |
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
|
6439 std::string mode = args(1).string_value (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
6440 if (mode == "ascend") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
6441 smode = ASCENDING; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
6442 else if (mode == "descend") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
6443 smode = DESCENDING; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
6444 else |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6445 error ("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
|
6446 } |
7433 | 6447 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
6448 dim = args(1).nint_value () - 1; |
7433 | 6449 } |
6450 | |
6451 if (nargin > 2) | |
6452 { | |
20884
f1b2a2dbc0e1
2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents:
20853
diff
changeset
|
6453 if (have_sortmode) |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6454 error ("sort: DIM must be a valid dimension"); |
7433 | 6455 |
20700
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20652
diff
changeset
|
6456 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
|
6457 |
7433 | 6458 if (mode == "ascend") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
6459 smode = ASCENDING; |
7433 | 6460 else if (mode == "descend") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
6461 smode = DESCENDING; |
7433 | 6462 else |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6463 error ("sort: MODE must be either \"ascend\" or \"descend\""); |
7433 | 6464 } |
6465 | |
10285
22a7913bbeb5
optimize return values of find and sort
Jaroslav Hajek <highegg@gmail.com>
parents:
10277
diff
changeset
|
6466 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
|
6467 if (nargin == 1 || have_sortmode) |
7433 | 6468 { |
10285
22a7913bbeb5
optimize return values of find and sort
Jaroslav Hajek <highegg@gmail.com>
parents:
10277
diff
changeset
|
6469 dim = dv.first_non_singleton (); |
7433 | 6470 } |
6471 else | |
6472 { | |
10703
5eb420d92307
fix sort and nth_element when trailing singleton dim is specified
Jaroslav Hajek <highegg@gmail.com>
parents:
10695
diff
changeset
|
6473 if (dim < 0) |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6474 error ("sort: DIM must be a valid dimension"); |
7433 | 6475 } |
6476 | |
20884
f1b2a2dbc0e1
2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents:
20853
diff
changeset
|
6477 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
|
6478 |
7433 | 6479 if (return_idx) |
6480 { | |
6481 Array<octave_idx_type> sidx; | |
6482 | |
20884
f1b2a2dbc0e1
2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents:
20853
diff
changeset
|
6483 // 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
|
6484 // 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
|
6485 retval(0) = arg.sort (sidx, dim, smode); |
20884
f1b2a2dbc0e1
2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents:
20853
diff
changeset
|
6486 retval(1) = idx_vector (sidx, dv(dim)); // No checking, extent is known. |
7433 | 6487 } |
6488 else | |
20884
f1b2a2dbc0e1
2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents:
20853
diff
changeset
|
6489 retval = ovl (arg.sort (dim, smode)); |
7433 | 6490 |
6491 return retval; | |
6492 } | |
6493 | |
6494 /* | |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6495 ## Double |
7433 | 6496 %!assert (sort ([NaN, 1, -1, 2, Inf]), [-1, 1, 2, Inf, NaN]) |
6497 %!assert (sort ([NaN, 1, -1, 2, Inf], 1), [NaN, 1, -1, 2, Inf]) | |
6498 %!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
|
6499 %!assert (sort ([NaN, 1, -1, 2, Inf], 3), [NaN, 1, -1, 2, Inf]) |
7433 | 6500 %!assert (sort ([NaN, 1, -1, 2, Inf], "ascend"), [-1, 1, 2, Inf, NaN]) |
6501 %!assert (sort ([NaN, 1, -1, 2, Inf], 2, "ascend"), [-1, 1, 2, Inf, NaN]) | |
6502 %!assert (sort ([NaN, 1, -1, 2, Inf], "descend"), [NaN, Inf, 2, 1, -1]) | |
6503 %!assert (sort ([NaN, 1, -1, 2, Inf], 2, "descend"), [NaN, Inf, 2, 1, -1]) | |
6504 %!assert (sort ([3, 1, 7, 5; 8, 2, 6, 4]), [3, 1, 6, 4; 8, 2, 7, 5]) | |
6505 %!assert (sort ([3, 1, 7, 5; 8, 2, 6, 4], 1), [3, 1, 6, 4; 8, 2, 7, 5]) | |
6506 %!assert (sort ([3, 1, 7, 5; 8, 2, 6, 4], 2), [1, 3, 5, 7; 2, 4, 6, 8]) | |
6507 %!assert (sort (1), 1) | |
6508 | |
6509 %!test | |
6510 %! [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
|
6511 %! 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
|
6512 %! 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
|
6513 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6514 ## Complex |
7433 | 6515 %!assert (sort ([NaN, 1i, -1, 2, Inf]), [1i, -1, 2, Inf, NaN]) |
6516 %!assert (sort ([NaN, 1i, -1, 2, Inf], 1), [NaN, 1i, -1, 2, Inf]) | |
6517 %!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
|
6518 %!assert (sort ([NaN, 1i, -1, 2, Inf], 3), [NaN, 1i, -1, 2, Inf]) |
7433 | 6519 %!assert (sort ([NaN, 1i, -1, 2, Inf], "ascend"), [1i, -1, 2, Inf, NaN]) |
6520 %!assert (sort ([NaN, 1i, -1, 2, Inf], 2, "ascend"), [1i, -1, 2, Inf, NaN]) | |
6521 %!assert (sort ([NaN, 1i, -1, 2, Inf], "descend"), [NaN, Inf, 2, -1, 1i]) | |
6522 %!assert (sort ([NaN, 1i, -1, 2, Inf], 2, "descend"), [NaN, Inf, 2, -1, 1i]) | |
6523 %!assert (sort ([3, 1i, 7, 5; 8, 2, 6, 4]), [3, 1i, 6, 4; 8, 2, 7, 5]) | |
6524 %!assert (sort ([3, 1i, 7, 5; 8, 2, 6, 4], 1), [3, 1i, 6, 4; 8, 2, 7, 5]) | |
6525 %!assert (sort ([3, 1i, 7, 5; 8, 2, 6, 4], 2), [1i, 3, 5, 7; 2, 4, 6, 8]) | |
6526 %!assert (sort (1i), 1i) | |
6527 | |
6528 %!test | |
6529 %! [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
|
6530 %! 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
|
6531 %! 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
|
6532 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6533 ## Single |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6534 %!assert (sort (single ([NaN, 1, -1, 2, Inf])), single ([-1, 1, 2, Inf, NaN])) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6535 %!assert (sort (single ([NaN, 1, -1, 2, Inf]), 1), single ([NaN, 1, -1, 2, Inf])) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6536 %!assert (sort (single ([NaN, 1, -1, 2, Inf]), 2), single ([-1, 1, 2, Inf, NaN])) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6537 %!assert (sort (single ([NaN, 1, -1, 2, Inf]), 3), single ([NaN, 1, -1, 2, Inf])) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6538 %!assert (sort (single ([NaN, 1, -1, 2, Inf]), "ascend"), single ([-1, 1, 2, Inf, NaN])) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6539 %!assert (sort (single ([NaN, 1, -1, 2, Inf]), 2, "ascend"), single ([-1, 1, 2, Inf, NaN])) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6540 %!assert (sort (single ([NaN, 1, -1, 2, Inf]), "descend"), single ([NaN, Inf, 2, 1, -1])) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6541 %!assert (sort (single ([NaN, 1, -1, 2, Inf]), 2, "descend"), single ([NaN, Inf, 2, 1, -1])) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6542 %!assert (sort (single ([3, 1, 7, 5; 8, 2, 6, 4])), single ([3, 1, 6, 4; 8, 2, 7, 5])) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6543 %!assert (sort (single ([3, 1, 7, 5; 8, 2, 6, 4]), 1), single ([3, 1, 6, 4; 8, 2, 7, 5])) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6544 %!assert (sort (single ([3, 1, 7, 5; 8, 2, 6, 4]), 2), single ([1, 3, 5, 7; 2, 4, 6, 8])) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6545 %!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
|
6546 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
6547 %!test |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6548 %! [v, i] = sort (single ([NaN, 1, -1, Inf, 1])); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6549 %! 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
|
6550 %! 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
|
6551 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6552 ## Single Complex |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6553 %!assert (sort (single ([NaN, 1i, -1, 2, Inf])), single ([1i, -1, 2, Inf, NaN])) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6554 %!assert (sort (single ([NaN, 1i, -1, 2, Inf]), 1), single ([NaN, 1i, -1, 2, Inf])) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6555 %!assert (sort (single ([NaN, 1i, -1, 2, Inf]), 2), single ([1i, -1, 2, Inf, NaN])) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6556 %!assert (sort (single ([NaN, 1i, -1, 2, Inf]), 3), single ([NaN, 1i, -1, 2, Inf])) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6557 %!assert (sort (single ([NaN, 1i, -1, 2, Inf]), "ascend"), single ([1i, -1, 2, Inf, NaN])) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6558 %!assert (sort (single ([NaN, 1i, -1, 2, Inf]), 2, "ascend"), single ([1i, -1, 2, Inf, NaN])) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6559 %!assert (sort (single ([NaN, 1i, -1, 2, Inf]), "descend"), single ([NaN, Inf, 2, -1, 1i])) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6560 %!assert (sort (single ([NaN, 1i, -1, 2, Inf]), 2, "descend"), single ([NaN, Inf, 2, -1, 1i])) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6561 %!assert (sort (single ([3, 1i, 7, 5; 8, 2, 6, 4])), single ([3, 1i, 6, 4; 8, 2, 7, 5])) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6562 %!assert (sort (single ([3, 1i, 7, 5; 8, 2, 6, 4]), 1), single ([3, 1i, 6, 4; 8, 2, 7, 5])) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6563 %!assert (sort (single ([3, 1i, 7, 5; 8, 2, 6, 4]), 2), single ([1i, 3, 5, 7; 2, 4, 6, 8])) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6564 %!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
|
6565 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
6566 %!test |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6567 %! [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
|
6568 %! 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
|
6569 %! 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
|
6570 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6571 ## Bool |
7433 | 6572 %!assert (sort ([true, false, true, false]), [false, false, true, true]) |
6573 %!assert (sort ([true, false, true, false], 1), [true, false, true, false]) | |
6574 %!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
|
6575 %!assert (sort ([true, false, true, false], 3), [true, false, true, false]) |
7433 | 6576 %!assert (sort ([true, false, true, false], "ascend"), [false, false, true, true]) |
6577 %!assert (sort ([true, false, true, false], 2, "ascend"), [false, false, true, true]) | |
6578 %!assert (sort ([true, false, true, false], "descend"), [true, true, false, false]) | |
6579 %!assert (sort ([true, false, true, false], 2, "descend"), [true, true, false, false]) | |
6580 %!assert (sort (true), true) | |
6581 | |
6582 %!test | |
6583 %! [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
|
6584 %! 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
|
6585 %! 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
|
6586 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6587 ## Sparse Double |
7433 | 6588 %!assert (sort (sparse ([0, NaN, 1, 0, -1, 2, Inf])), sparse ([-1, 0, 0, 1, 2, Inf, NaN])) |
6589 %!assert (sort (sparse ([0, NaN, 1, 0, -1, 2, Inf]), 1), sparse ([0, NaN, 1, 0, -1, 2, Inf])) | |
6590 %!assert (sort (sparse ([0, NaN, 1, 0, -1, 2, Inf]), 2), sparse ([-1, 0, 0, 1, 2, Inf, NaN])) | |
10707
69c5f5ec55d7
fix invalid sort tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10703
diff
changeset
|
6591 %!assert (sort (sparse ([0, NaN, 1, 0, -1, 2, Inf]), 3), sparse ([0, NaN, 1, 0, -1, 2, Inf])) |
7433 | 6592 %!assert (sort (sparse ([0, NaN, 1, 0, -1, 2, Inf]), "ascend"), sparse ([-1, 0, 0, 1, 2, Inf, NaN])) |
6593 %!assert (sort (sparse ([0, NaN, 1, 0, -1, 2, Inf]), 2, "ascend"), sparse ([-1, 0, 0, 1, 2, Inf, NaN])) | |
6594 %!assert (sort (sparse ([0, NaN, 1, 0, -1, 2, Inf]), "descend"), sparse ([NaN, Inf, 2, 1, 0, 0, -1])) | |
6595 %!assert (sort (sparse ([0, NaN, 1, 0, -1, 2, Inf]), 2, "descend"), sparse ([NaN, Inf, 2, 1, 0, 0, -1])) | |
6596 | |
6597 %!shared a | |
6598 %! a = randn (10, 10); | |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6599 %! a(a < 0) = 0; |
7433 | 6600 %!assert (sort (sparse (a)), sparse (sort (a))) |
6601 %!assert (sort (sparse (a), 1), sparse (sort (a, 1))) | |
6602 %!assert (sort (sparse (a), 2), sparse (sort (a, 2))) | |
6603 %!test | |
6604 %! [v, i] = sort (a); | |
6605 %! [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
|
6606 %! assert (vs, sparse (v)); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6607 %! assert (is, i); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6608 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6609 ## Sparse Complex |
7433 | 6610 %!assert (sort (sparse ([0, NaN, 1i, 0, -1, 2, Inf])), sparse ([0, 0, 1i, -1, 2, Inf, NaN])) |
6611 %!assert (sort (sparse ([0, NaN, 1i, 0, -1, 2, Inf]), 1), sparse ([0, NaN, 1i, 0, -1, 2, Inf])) | |
6612 %!assert (sort (sparse ([0, NaN, 1i, 0, -1, 2, Inf]), 2), sparse ([0, 0, 1i, -1, 2, Inf, NaN])) | |
10707
69c5f5ec55d7
fix invalid sort tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10703
diff
changeset
|
6613 %!assert (sort (sparse ([0, NaN, 1i, 0, -1, 2, Inf]), 3), sparse ([0, NaN, 1i, 0, -1, 2, Inf])) |
7433 | 6614 %!assert (sort (sparse ([0, NaN, 1i, 0, -1, 2, Inf]), "ascend"), sparse ([0, 0, 1i, -1, 2, Inf, NaN])) |
6615 %!assert (sort (sparse ([0, NaN, 1i, 0, -1, 2, Inf]), 2, "ascend"), sparse ([0, 0, 1i, -1, 2, Inf, NaN])) | |
6616 %!assert (sort (sparse ([0, NaN, 1i, 0, -1, 2, Inf]), "descend"), sparse ([NaN, Inf, 2, -1, 1i, 0, 0])) | |
6617 %!assert (sort (sparse ([0, NaN, 1i, 0, -1, 2, Inf]), 2, "descend"), sparse ([NaN, Inf, 2, -1, 1i, 0, 0])) | |
6618 | |
6619 %!shared a | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
6620 %! a = randn (10, 10); |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6621 %! a(a < 0) = 0; |
7433 | 6622 %! a = 1i * a; |
6623 %!assert (sort (sparse (a)), sparse (sort (a))) | |
6624 %!assert (sort (sparse (a), 1), sparse (sort (a, 1))) | |
6625 %!assert (sort (sparse (a), 2), sparse (sort (a, 2))) | |
6626 %!test | |
6627 %! [v, i] = sort (a); | |
6628 %! [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
|
6629 %! assert (vs, sparse (v)); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6630 %! assert (is, i); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6631 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6632 ## Sparse Bool |
7433 | 6633 %!assert (sort (sparse ([true, false, true, false])), sparse ([false, false, true, true])) |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6634 %!assert (sort (sparse ([true, false, true, false]), 1), sparse ([true, false, true, false])) |
7433 | 6635 %!assert (sort (sparse ([true, false, true, false]), 2), sparse ([false, false, true, true])) |
10707
69c5f5ec55d7
fix invalid sort tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10703
diff
changeset
|
6636 %!assert (sort (sparse ([true, false, true, false]), 3), sparse ([true, false, true, false])) |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6637 %!assert (sort (sparse ([true, false, true, false]), "ascend"), sparse ([false, false, true, true])) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6638 %!assert (sort (sparse ([true, false, true, false]), 2, "ascend"), sparse ([false, false, true, true])) |
7433 | 6639 %!assert (sort (sparse ([true, false, true, false]), "descend"), sparse ([true, true, false, false])) |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6640 %!assert (sort (sparse ([true, false, true, false]), 2, "descend"), sparse ([true, true, false, false])) |
7433 | 6641 |
6642 %!test | |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6643 %! [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
|
6644 %! 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
|
6645 %! 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
|
6646 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6647 ## Cell string array |
7433 | 6648 %!shared a, b, c |
6649 %! a = {"Alice", "Cecile", "Eric", "Barry", "David"}; | |
6650 %! b = {"Alice", "Barry", "Cecile", "David", "Eric"}; | |
6651 %! 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
|
6652 %!assert (sort (a), b) |
7433 | 6653 %!assert (sort (a, 1), a) |
6654 %!assert (sort (a, 2), b) | |
10707
69c5f5ec55d7
fix invalid sort tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10703
diff
changeset
|
6655 %!assert (sort (a, 3), a) |
7433 | 6656 %!assert (sort (a, "ascend"), b) |
6657 %!assert (sort (a, 2, "ascend"), b) | |
6658 %!assert (sort (a, "descend"), c) | |
6659 %!assert (sort (a, 2, "descend"), c) | |
6660 | |
6661 %!test | |
6662 %! [v, i] = sort (a); | |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6663 %! 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
|
6664 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6665 %!error sort () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6666 %!error sort (1, 2, 3, 4) |
7433 | 6667 */ |
6668 | |
8812
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
8799
diff
changeset
|
6669 // Sort the rows of the matrix @var{a} according to the order |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
15428
diff
changeset
|
6670 // specified by @var{mode}, which can either be 'ascend' or 'descend' |
8812
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
8799
diff
changeset
|
6671 // and return the index vector corresponding to the sort order. |
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
8799
diff
changeset
|
6672 // |
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
8799
diff
changeset
|
6673 // This function does not yet support sparse matrices. |
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
8799
diff
changeset
|
6674 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
6675 // FIXME: Is this function used anymore? 12/14/2015 |
8733
3ef774603887
rename all uses of sortrows_idx to sort_rows_idx
John W. Eaton <jwe@octave.org>
parents:
8721
diff
changeset
|
6676 DEFUN (__sort_rows_idx__, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
6677 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
6678 @deftypefn {} {} __sort_rows_idx__ (@var{a}, @var{mode})\n\ |
8812
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
8799
diff
changeset
|
6679 Undocumented internal function.\n\ |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6680 @end deftypefn\n") |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6681 { |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6682 int nargin = args.length (); |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6683 |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6684 if (nargin < 1 || nargin > 2) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6685 print_usage (); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6686 |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6687 if (nargin == 2 && ! args(1).is_string ()) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6688 error ("__sort_rows_idx__: second argument must be a string"); |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6689 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
6690 sortmode smode = ASCENDING; |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6691 if (nargin > 1) |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6692 { |
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
|
6693 std::string mode = args(1).string_value (); |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6694 if (mode == "ascend") |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6695 smode = ASCENDING; |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6696 else if (mode == "descend") |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6697 smode = DESCENDING; |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6698 else |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
6699 error ("__sort_rows_idx__: MODE must be either \"ascend\" or \"descend\""); |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6700 } |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6701 |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6702 octave_value arg = args(0); |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6703 |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6704 if (arg.is_sparse_type ()) |
8733
3ef774603887
rename all uses of sortrows_idx to sort_rows_idx
John W. Eaton <jwe@octave.org>
parents:
8721
diff
changeset
|
6705 error ("__sort_rows_idx__: sparse matrices not yet supported"); |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
6706 |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
6707 if (arg.ndims () != 2) |
21014
b9d4c3615e89
maint: Capitalize D for dimension in messages and comments.
Rik <rik@octave.org>
parents:
20980
diff
changeset
|
6708 error ("__sort_rows_idx__: needs a 2-D object"); |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6709 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
6710 Array<octave_idx_type> idx = arg.sort_rows_idx (smode); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
6711 |
21127
df7891224709
maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents:
21121
diff
changeset
|
6712 // This cannot be ovl(), relies on special overloaded octave_value call. |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
6713 return octave_value (idx, true, true); |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6714 } |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6715 |
9765
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6716 static sortmode |
20720
7c21b151b8b4
build: Fix warning messages from compiler.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
6717 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
|
6718 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
6719 // 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
|
6720 // about possibly using sortmode uninitialized. |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
6721 // 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
|
6722 sortmode smode = UNSORTED; |
9765
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6723 |
20711
7b608fadc663
Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents:
20704
diff
changeset
|
6724 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
|
6725 |
ba2b07c13913
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20574
diff
changeset
|
6726 if (mode == "ascending") |
ba2b07c13913
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20574
diff
changeset
|
6727 smode = ASCENDING; |
ba2b07c13913
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20574
diff
changeset
|
6728 else if (mode == "descending") |
ba2b07c13913
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20574
diff
changeset
|
6729 smode = DESCENDING; |
ba2b07c13913
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20574
diff
changeset
|
6730 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
|
6731 smode = UNSORTED; |
9765
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6732 else |
20582
ba2b07c13913
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20574
diff
changeset
|
6733 error ("issorted: MODE must be \"ascending\", \"descending\", or \"either\""); |
9765
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6734 |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6735 return smode; |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6736 } |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6737 |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6738 DEFUN (issorted, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
6739 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
6740 @deftypefn {} {} issorted (@var{a})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
6741 @deftypefnx {} {} issorted (@var{a}, @var{mode})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
6742 @deftypefnx {} {} issorted (@var{a}, \"rows\", @var{mode})\n\ |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11422
diff
changeset
|
6743 Return true if the array is sorted according to @var{mode}, which\n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17268
diff
changeset
|
6744 may be either @qcode{\"ascending\"}, @qcode{\"descending\"}, or\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
6745 @qcode{\"either\"}.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
6746 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
6747 By default, @var{mode} is @qcode{\"ascending\"}. NaNs are treated in the\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
6748 same manner as @code{sort}.\n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17268
diff
changeset
|
6749 \n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17268
diff
changeset
|
6750 If the optional argument @qcode{\"rows\"} is supplied, check whether\n\ |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11422
diff
changeset
|
6751 the array is sorted by rows as output by the function @code{sortrows}\n\ |
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11422
diff
changeset
|
6752 (with no options).\n\ |
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11422
diff
changeset
|
6753 \n\ |
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11422
diff
changeset
|
6754 This function does not support sparse matrices.\n\ |
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11422
diff
changeset
|
6755 @seealso{sort, sortrows}\n\ |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6756 @end deftypefn\n") |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6757 { |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6758 int nargin = args.length (); |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6759 |
9765
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6760 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
|
6761 print_usage (); |
9765
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6762 |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6763 bool by_rows = false; |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6764 |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6765 sortmode smode = ASCENDING; |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6766 |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6767 if (nargin > 1) |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6768 { |
9765
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6769 if (nargin == 3) |
20720
7c21b151b8b4
build: Fix warning messages from compiler.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
6770 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
|
6771 |
20700
68e3a747ca02
rename octave_value value extractors that accept error message args
John W. Eaton <jwe@octave.org>
parents:
20652
diff
changeset
|
6772 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
|
6773 if (tmp == "rows") |
ba2b07c13913
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20574
diff
changeset
|
6774 by_rows = true; |
9765
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6775 else |
20720
7c21b151b8b4
build: Fix warning messages from compiler.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
6776 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
|
6777 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
6778 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
6779 octave_value retval; |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
6780 |
9765
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6781 octave_value arg = args(0); |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6782 |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6783 if (by_rows) |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6784 { |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6785 if (arg.is_sparse_type ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
6786 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
|
6787 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
6788 if (arg.ndims () != 2) |
21014
b9d4c3615e89
maint: Capitalize D for dimension in messages and comments.
Rik <rik@octave.org>
parents:
20980
diff
changeset
|
6789 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
|
6790 |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
6791 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
|
6792 } |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6793 else |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6794 { |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
6795 if (! arg.dims ().is_vector ()) |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6796 error ("issorted: needs a vector"); |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
6797 |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
6798 retval = args(0).is_sorted (smode) != UNSORTED; |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6799 } |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6800 |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6801 return retval; |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6802 } |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6803 |
9765
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6804 /* |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6805 %!shared sm, um, sv, uv |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6806 %! sm = [1, 2; 3, 4]; |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6807 %! um = [3, 1; 2, 4]; |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6808 %! sv = [1, 2, 3, 4]; |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6809 %! uv = [2, 1, 4, 3]; |
20809 | 6810 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6811 %!assert (issorted (sm, "rows")) |
20809 | 6812 %!assert (! issorted (um, "rows")) |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6813 %!assert (issorted (sv)) |
20809 | 6814 %!assert (! issorted (uv)) |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6815 %!assert (issorted (sv')) |
20809 | 6816 %!assert (! issorted (uv')) |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6817 %!assert (issorted (sm, "rows", "ascending")) |
20809 | 6818 %!assert (! issorted (um, "rows", "ascending")) |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6819 %!assert (issorted (sv, "ascending")) |
20809 | 6820 %!assert (! issorted (uv, "ascending")) |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6821 %!assert (issorted (sv', "ascending")) |
20809 | 6822 %!assert (! issorted (uv', "ascending")) |
6823 %!assert (! issorted (sm, "rows", "descending")) | |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6824 %!assert (issorted (flipud (sm), "rows", "descending")) |
20809 | 6825 %!assert (! issorted (sv, "descending")) |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6826 %!assert (issorted (fliplr (sv), "descending")) |
20809 | 6827 %!assert (! issorted (sv', "descending")) |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6828 %!assert (issorted (fliplr (sv)', "descending")) |
20809 | 6829 %!assert (! issorted (um, "rows", "either")) |
6830 %!assert (! issorted (uv, "either")) | |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6831 %!assert (issorted (sm, "rows", "either")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6832 %!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
|
6833 %!assert (issorted (sv, "either")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6834 %!assert (issorted (fliplr (sv), "either")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6835 %!assert (issorted (sv', "either")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6836 %!assert (issorted (fliplr (sv)', "either")) |
20809 | 6837 |
6838 %!error <needs a vector> issorted ([]) | |
6839 | |
6840 ## 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
|
6841 %!error issorted () |
f1b2a2dbc0e1
2015 Code Sprint: use ovl () in C++ files.
José Luis García Pallero <jgpallero@gmail.com>
parents:
20853
diff
changeset
|
6842 %!error issorted (1,2,3,4) |
20809 | 6843 %!error <second argument must be a string> issorted (1, 2) |
6844 %!error <second argument must be a string> issorted (1, {"rows"}) | |
6845 %!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
|
6846 %!error <A must be a 2-D object> issorted (rand (2,2,2), "rows") |
20809 | 6847 %!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
|
6848 */ |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6849 |
9725 | 6850 DEFUN (nth_element, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
6851 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
6852 @deftypefn {} {} nth_element (@var{x}, @var{n})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
6853 @deftypefnx {} {} nth_element (@var{x}, @var{n}, @var{dim})\n\ |
10840 | 6854 Select the n-th smallest element of a vector, using the ordering defined by\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
6855 @code{sort}.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
6856 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
6857 The result is equivalent to @code{sort(@var{x})(@var{n})}.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
6858 \n\ |
9725 | 6859 @var{n} can also be a contiguous range, either ascending @code{l:u}\n\ |
6860 or descending @code{u:-1:l}, in which case a range of elements is returned.\n\ | |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
6861 \n\ |
10846
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10840
diff
changeset
|
6862 If @var{x} is an array, @code{nth_element} operates along the dimension\n\ |
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10840
diff
changeset
|
6863 defined by @var{dim}, or the first non-singleton dimension if @var{dim} is\n\ |
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10840
diff
changeset
|
6864 not given.\n\ |
9725 | 6865 \n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
6866 Programming Note: nth_element encapsulates the C++ standard library\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
6867 algorithms nth_element and partial_sort. On average, the complexity of the\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
6868 operation is O(M*log(K)), where @w{@code{M = size (@var{x}, @var{dim})}} and\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
6869 @w{@code{K = length (@var{n})}}. This function is intended for cases where\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
6870 the ratio K/M is small; otherwise, it may be better to use @code{sort}.\n\ |
9725 | 6871 @seealso{sort, min, max}\n\ |
6872 @end deftypefn") | |
6873 { | |
6874 int nargin = args.length (); | |
6875 | |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6876 if (nargin < 2 || nargin > 3) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6877 print_usage (); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6878 |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6879 int dim = -1; |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6880 if (nargin == 3) |
9725 | 6881 { |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6882 dim = args(2).int_value (true) - 1; |
9725 | 6883 if (dim < 0) |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6884 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
|
6885 } |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
6886 |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
6887 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
|
6888 if (dim < 0) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6889 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
|
6890 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
6891 octave_value retval; |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
6892 |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6893 try |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6894 { |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6895 idx_vector n = args(1).index_vector (); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6896 |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6897 switch (argx.builtin_type ()) |
9725 | 6898 { |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6899 case btyp_double: |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6900 retval = argx.array_value ().nth_element (n, dim); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6901 break; |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6902 case btyp_float: |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6903 retval = argx.float_array_value ().nth_element (n, dim); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6904 break; |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6905 case btyp_complex: |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6906 retval = argx.complex_array_value ().nth_element (n, dim); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6907 break; |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6908 case btyp_float_complex: |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6909 retval = argx.float_complex_array_value ().nth_element (n, dim); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6910 break; |
9725 | 6911 #define MAKE_INT_BRANCH(X) \ |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6912 case btyp_ ## X: \ |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6913 retval = argx.X ## _array_value ().nth_element (n, dim); \ |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6914 break; |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6915 |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6916 MAKE_INT_BRANCH (int8); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6917 MAKE_INT_BRANCH (int16); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6918 MAKE_INT_BRANCH (int32); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6919 MAKE_INT_BRANCH (int64); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6920 MAKE_INT_BRANCH (uint8); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6921 MAKE_INT_BRANCH (uint16); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6922 MAKE_INT_BRANCH (uint32); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6923 MAKE_INT_BRANCH (uint64); |
9725 | 6924 #undef MAKE_INT_BRANCH |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6925 default: |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6926 if (argx.is_cellstr ()) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6927 retval = argx.cellstr_value ().nth_element (n, dim); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6928 else |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21078
diff
changeset
|
6929 err_wrong_type_arg ("nth_element", argx); |
9725 | 6930 } |
6931 } | |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6932 catch (const index_exception& e) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6933 { |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6934 index_error ("nth_element: invalid N value %s. %s", |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6935 e.idx (), e.details ()); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6936 } |
9725 | 6937 |
6938 return retval; | |
6939 } | |
6940 | |
8934
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6941 template <class NDT> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
6942 static NDT |
8934
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6943 do_accumarray_sum (const idx_vector& idx, const NDT& vals, |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6944 octave_idx_type n = -1) |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6945 { |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6946 typedef typename NDT::element_type T; |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6947 if (n < 0) |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6948 n = idx.extent (0); |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6949 else if (idx.extent (n) > n) |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6950 error ("accumarray: index out of range"); |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6951 |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14843
diff
changeset
|
6952 NDT retval (dim_vector (n, 1), T ()); |
8934
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6953 |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6954 if (vals.numel () == 1) |
9858
47c5af1868df
move idx_add methods to MArrayN
Jaroslav Hajek <highegg@gmail.com>
parents:
9856
diff
changeset
|
6955 retval.idx_add (idx, vals (0)); |
47c5af1868df
move idx_add methods to MArrayN
Jaroslav Hajek <highegg@gmail.com>
parents:
9856
diff
changeset
|
6956 else if (vals.numel () == idx.length (n)) |
47c5af1868df
move idx_add methods to MArrayN
Jaroslav Hajek <highegg@gmail.com>
parents:
9856
diff
changeset
|
6957 retval.idx_add (idx, vals); |
8934
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6958 else |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6959 error ("accumarray: dimensions mismatch"); |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6960 |
9858
47c5af1868df
move idx_add methods to MArrayN
Jaroslav Hajek <highegg@gmail.com>
parents:
9856
diff
changeset
|
6961 return retval; |
8934
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6962 } |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6963 |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6964 DEFUN (__accumarray_sum__, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
6965 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
6966 @deftypefn {} {} __accumarray_sum__ (@var{idx}, @var{vals}, @var{n})\n\ |
8934
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6967 Undocumented internal function.\n\ |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6968 @end deftypefn") |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6969 { |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6970 int nargin = args.length (); |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6971 |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6972 if (nargin < 2 && nargin > 3) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6973 print_usage (); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6974 |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6975 if (! args(0).is_numeric_type ()) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6976 error ("__accumarray_sum__: first argument must be numeric"); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6977 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
6978 octave_value retval; |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
6979 |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6980 try |
8934
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6981 { |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6982 idx_vector idx = args(0).index_vector (); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6983 octave_idx_type n = -1; |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6984 if (nargin == 3) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6985 n = args(2).idx_type_value (true); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6986 |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6987 octave_value vals = args(1); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6988 |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6989 if (vals.is_range ()) |
8934
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6990 { |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6991 Range r = vals.range_value (); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6992 if (r.inc () == 0) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6993 vals = r.base (); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6994 } |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6995 |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6996 if (vals.is_single_type ()) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6997 { |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6998 if (vals.is_complex_type ()) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6999 retval = do_accumarray_sum (idx, |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7000 vals.float_complex_array_value (), |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7001 n); |
8934
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
7002 else |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7003 retval = do_accumarray_sum (idx, vals.float_array_value (), n); |
8934
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
7004 } |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7005 else if (vals.is_numeric_type () || vals.is_bool_type ()) |
20562
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
7006 { |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7007 if (vals.is_complex_type ()) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7008 retval = do_accumarray_sum (idx, |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7009 vals.complex_array_value (), |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7010 n); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7011 else |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7012 retval = do_accumarray_sum (idx, vals.array_value (), n); |
20562
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
7013 } |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7014 else |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21078
diff
changeset
|
7015 err_wrong_type_arg ("accumarray", vals); |
8934
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
7016 } |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7017 catch (const index_exception& e) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7018 { |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7019 index_error ("__accumarray_sum__: invalid IDX %s. %s", |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7020 e.idx (), e.details ()); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7021 } |
8934
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
7022 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
7023 return retval; |
8934
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
7024 } |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
7025 |
9473
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7026 template <class NDT> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
7027 static NDT |
10268
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7028 do_accumarray_minmax (const idx_vector& idx, const NDT& vals, |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7029 octave_idx_type n, bool ismin, |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7030 const typename NDT::element_type& zero_val) |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7031 { |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7032 typedef typename NDT::element_type T; |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7033 if (n < 0) |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7034 n = idx.extent (0); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7035 else if (idx.extent (n) > n) |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7036 error ("accumarray: index out of range"); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7037 |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7038 NDT retval (dim_vector (n, 1), zero_val); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7039 |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7040 // Pick minimizer or maximizer. |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
7041 void (MArray<T>::*op) (const idx_vector&, const MArray<T>&) = |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
7042 ismin ? (&MArray<T>::idx_min) : (&MArray<T>::idx_max); |
10268
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7043 |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7044 octave_idx_type l = idx.length (n); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7045 if (vals.numel () == 1) |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7046 (retval.*op) (idx, NDT (dim_vector (l, 1), vals(0))); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7047 else if (vals.numel () == l) |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7048 (retval.*op) (idx, vals); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7049 else |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7050 error ("accumarray: dimensions mismatch"); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7051 |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7052 return retval; |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7053 } |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7054 |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7055 static octave_value_list |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7056 do_accumarray_minmax_fun (const octave_value_list& args, |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7057 bool ismin) |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7058 { |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7059 int nargin = args.length (); |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7060 |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7061 if (nargin < 3 && nargin > 4) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7062 print_usage (); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7063 |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7064 if (! args(0).is_numeric_type ()) |
20811 | 7065 error ("accumarray: first argument must be numeric"); |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7066 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
7067 octave_value retval; |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
7068 |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7069 try |
10268
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7070 { |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7071 idx_vector idx = args(0).index_vector (); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7072 octave_idx_type n = -1; |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7073 if (nargin == 4) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7074 n = args(3).idx_type_value (true); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7075 |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7076 octave_value vals = args(1); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7077 octave_value zero = args(2); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7078 |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7079 switch (vals.builtin_type ()) |
10268
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7080 { |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7081 case btyp_double: |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7082 retval = do_accumarray_minmax (idx, vals.array_value (), n, ismin, |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7083 zero.double_value ()); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7084 break; |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7085 |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7086 case btyp_float: |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7087 retval = do_accumarray_minmax (idx, vals.float_array_value (), n, |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7088 ismin, zero.float_value ()); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7089 break; |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7090 |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7091 case btyp_complex: |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7092 retval = do_accumarray_minmax (idx, vals.complex_array_value (), |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7093 n, ismin, zero.complex_value ()); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7094 break; |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7095 |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7096 case btyp_float_complex: |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7097 retval = do_accumarray_minmax (idx, |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7098 vals.float_complex_array_value (), |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7099 n, ismin, |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7100 zero.float_complex_value ()); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7101 break; |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7102 |
10268
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7103 #define MAKE_INT_BRANCH(X) \ |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7104 case btyp_ ## X: \ |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7105 retval = do_accumarray_minmax (idx, vals.X ## _array_value (), \ |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7106 n, ismin, zero.X ## _scalar_value ()); \ |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7107 break; |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7108 |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7109 MAKE_INT_BRANCH (int8); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7110 MAKE_INT_BRANCH (int16); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7111 MAKE_INT_BRANCH (int32); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7112 MAKE_INT_BRANCH (int64); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7113 MAKE_INT_BRANCH (uint8); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7114 MAKE_INT_BRANCH (uint16); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7115 MAKE_INT_BRANCH (uint32); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7116 MAKE_INT_BRANCH (uint64); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7117 |
10268
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7118 #undef MAKE_INT_BRANCH |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7119 |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7120 case btyp_bool: |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7121 retval = do_accumarray_minmax (idx, vals.array_value (), n, ismin, |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7122 zero.bool_value ()); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7123 break; |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7124 |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7125 default: |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21078
diff
changeset
|
7126 err_wrong_type_arg ("accumarray", vals); |
10268
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7127 } |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7128 } |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7129 catch (const index_exception& e) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7130 { |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7131 index_error ("do_accumarray_minmax_fun: invalid index %s. %s", |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7132 e.idx (), e.details ()); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7133 } |
10268
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7134 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
7135 return retval; |
10268
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7136 } |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7137 |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7138 DEFUN (__accumarray_min__, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
7139 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
7140 @deftypefn {} {} __accumarray_min__ (@var{idx}, @var{vals}, @var{zero}, @var{n})\n\ |
10268
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7141 Undocumented internal function.\n\ |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7142 @end deftypefn") |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7143 { |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7144 return do_accumarray_minmax_fun (args, true); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7145 } |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7146 |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7147 DEFUN (__accumarray_max__, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
7148 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
7149 @deftypefn {} {} __accumarray_max__ (@var{idx}, @var{vals}, @var{zero}, @var{n})\n\ |
10268
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7150 Undocumented internal function.\n\ |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7151 @end deftypefn") |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7152 { |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7153 return do_accumarray_minmax_fun (args, false); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7154 } |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7155 |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7156 template <class NDT> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
7157 static NDT |
10396
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7158 do_accumdim_sum (const idx_vector& idx, const NDT& vals, |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7159 int dim = -1, octave_idx_type n = -1) |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7160 { |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7161 typedef typename NDT::element_type T; |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7162 if (n < 0) |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7163 n = idx.extent (0); |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7164 else if (idx.extent (n) > n) |
14113
dac62c415e8b
Do more error checking on accumarray and accumdim input.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14100
diff
changeset
|
7165 error ("accumdim: index out of range"); |
dac62c415e8b
Do more error checking on accumarray and accumdim input.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14100
diff
changeset
|
7166 |
18100
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17915
diff
changeset
|
7167 dim_vector vals_dim = vals.dims (); |
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17915
diff
changeset
|
7168 dim_vector rdv = vals_dim; |
14113
dac62c415e8b
Do more error checking on accumarray and accumdim input.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14100
diff
changeset
|
7169 |
10396
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7170 if (dim < 0) |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7171 dim = vals.dims ().first_non_singleton (); |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7172 else if (dim >= rdv.length ()) |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7173 rdv.resize (dim+1, 1); |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7174 |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7175 rdv(dim) = n; |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7176 |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14843
diff
changeset
|
7177 NDT retval (rdv, T ()); |
10396
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7178 |
14113
dac62c415e8b
Do more error checking on accumarray and accumdim input.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14100
diff
changeset
|
7179 if (idx.length () != vals_dim(dim)) |
dac62c415e8b
Do more error checking on accumarray and accumdim input.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14100
diff
changeset
|
7180 error ("accumdim: dimension mismatch"); |
dac62c415e8b
Do more error checking on accumarray and accumdim input.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14100
diff
changeset
|
7181 |
10396
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7182 retval.idx_add_nd (idx, vals, dim); |
14113
dac62c415e8b
Do more error checking on accumarray and accumdim input.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14100
diff
changeset
|
7183 |
10396
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7184 return retval; |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7185 } |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7186 |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7187 DEFUN (__accumdim_sum__, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
7188 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
7189 @deftypefn {} {} __accumdim_sum__ (@var{idx}, @var{vals}, @var{dim}, @var{n})\n\ |
10396
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7190 Undocumented internal function.\n\ |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7191 @end deftypefn") |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7192 { |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7193 int nargin = args.length (); |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7194 |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7195 if (nargin < 2 && nargin > 4) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7196 print_usage (); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7197 |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7198 if (! args(0).is_numeric_type ()) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7199 error ("__accumdim_sum__: first argument must be numeric"); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7200 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
7201 octave_value retval; |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
7202 |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7203 try |
10396
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7204 { |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7205 idx_vector idx = args(0).index_vector (); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7206 int dim = -1; |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7207 if (nargin >= 3) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7208 dim = args(2).int_value () - 1; |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7209 |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7210 octave_idx_type n = -1; |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7211 if (nargin == 4) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7212 n = args(3).idx_type_value (true); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7213 |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7214 octave_value vals = args(1); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7215 |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7216 if (vals.is_single_type ()) |
10396
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7217 { |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7218 if (vals.is_complex_type ()) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7219 retval = do_accumdim_sum (idx, |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7220 vals.float_complex_array_value (), |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7221 dim, n); |
10396
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7222 else |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7223 retval = do_accumdim_sum (idx, vals.float_array_value (), |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7224 dim, n); |
10396
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7225 } |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7226 else if (vals.is_numeric_type () || vals.is_bool_type ()) |
20542
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20486
diff
changeset
|
7227 { |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7228 if (vals.is_complex_type ()) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7229 retval = do_accumdim_sum (idx, vals.complex_array_value (), |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7230 dim, n); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7231 else |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7232 retval = do_accumdim_sum (idx, vals.array_value (), dim, n); |
10396
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7233 } |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7234 else |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21078
diff
changeset
|
7235 err_wrong_type_arg ("accumdim", vals); |
10396
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7236 } |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7237 catch (const index_exception& e) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7238 { |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7239 index_error ("__accumdim_sum__: invalid IDX %s. %s", |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7240 e.idx (), e.details ()); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7241 } |
10396
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7242 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
7243 return retval; |
10396
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7244 } |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7245 |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7246 template <class NDT> |
9473
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7247 static NDT |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7248 do_merge (const Array<bool>& mask, |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7249 const NDT& tval, const NDT& fval) |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7250 { |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7251 typedef typename NDT::element_type T; |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7252 dim_vector dv = mask.dims (); |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7253 NDT retval (dv); |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7254 |
18100
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17915
diff
changeset
|
7255 bool tscl = tval.numel () == 1; |
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17915
diff
changeset
|
7256 bool fscl = fval.numel () == 1; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
7257 |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21053
diff
changeset
|
7258 if ((! tscl && tval.dims () != dv) || (! fscl && fval.dims () != dv)) |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11591
diff
changeset
|
7259 error ("merge: MASK, TVAL, and FVAL dimensions must match"); |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21053
diff
changeset
|
7260 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21053
diff
changeset
|
7261 T *rv = retval.fortran_vec (); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21053
diff
changeset
|
7262 octave_idx_type n = retval.numel (); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21053
diff
changeset
|
7263 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21053
diff
changeset
|
7264 const T *tv = tval.data (); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21053
diff
changeset
|
7265 const T *fv = fval.data (); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21053
diff
changeset
|
7266 const bool *mv = mask.data (); |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21053
diff
changeset
|
7267 |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21053
diff
changeset
|
7268 if (tscl) |
9473
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7269 { |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21053
diff
changeset
|
7270 if (fscl) |
9473
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7271 { |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21053
diff
changeset
|
7272 T ts = tv[0]; |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21053
diff
changeset
|
7273 T fs = fv[0]; |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21053
diff
changeset
|
7274 for (octave_idx_type i = 0; i < n; i++) |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21053
diff
changeset
|
7275 rv[i] = mv[i] ? ts : fs; |
9473
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7276 } |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7277 else |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7278 { |
21055
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21053
diff
changeset
|
7279 T ts = tv[0]; |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21053
diff
changeset
|
7280 for (octave_idx_type i = 0; i < n; i++) |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21053
diff
changeset
|
7281 rv[i] = mv[i] ? ts : fv[i]; |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21053
diff
changeset
|
7282 } |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21053
diff
changeset
|
7283 } |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21053
diff
changeset
|
7284 else |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21053
diff
changeset
|
7285 { |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21053
diff
changeset
|
7286 if (fscl) |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21053
diff
changeset
|
7287 { |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21053
diff
changeset
|
7288 T fs = fv[0]; |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21053
diff
changeset
|
7289 for (octave_idx_type i = 0; i < n; i++) |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21053
diff
changeset
|
7290 rv[i] = mv[i] ? tv[i] : fs; |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21053
diff
changeset
|
7291 } |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21053
diff
changeset
|
7292 else |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21053
diff
changeset
|
7293 { |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21053
diff
changeset
|
7294 for (octave_idx_type i = 0; i < n; i++) |
5e00ed38a58b
maint: Replace if/error/else paradigm with just if/error.
Rik <rik@octave.org>
parents:
21053
diff
changeset
|
7295 rv[i] = mv[i] ? tv[i] : fv[i]; |
9473
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7296 } |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7297 } |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7298 |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7299 return retval; |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7300 } |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7301 |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7302 #define MAKE_INT_BRANCH(INTX) \ |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7303 else if (tval.is_ ## INTX ## _type () && fval.is_ ## INTX ## _type ()) \ |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7304 { \ |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7305 retval = do_merge (mask, \ |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7306 tval.INTX ## _array_value (), \ |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7307 fval.INTX ## _array_value ()); \ |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7308 } |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7309 |
9505
a321a1c227c8
make ifelse an alias or merge
Jaroslav Hajek <highegg@gmail.com>
parents:
9475
diff
changeset
|
7310 DEFUN (merge, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
7311 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
7312 @deftypefn {} {} merge (@var{mask}, @var{tval}, @var{fval})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
7313 @deftypefnx {} {} ifelse (@var{mask}, @var{tval}, @var{fval})\n\ |
11572
7d6d8c1e471f
Grammarcheck Texinfo for files in src directory.
Rik <octave@nomad.inbox5.com>
parents:
11570
diff
changeset
|
7314 Merge elements of @var{true_val} and @var{false_val}, depending on the\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
7315 value of @var{mask}.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
7316 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
7317 If @var{mask} is a logical scalar, the other two arguments can be arbitrary\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
7318 values. Otherwise, @var{mask} must be a logical array, and @var{tval},\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
7319 @var{fval} should be arrays of matching class, or cell arrays. In the\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
7320 scalar mask case, @var{tval} is returned if @var{mask} is true, otherwise\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
7321 @var{fval} is returned.\n\ |
9473
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7322 \n\ |
10846
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10840
diff
changeset
|
7323 In the array mask case, both @var{tval} and @var{fval} must be either\n\ |
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10840
diff
changeset
|
7324 scalars or arrays with dimensions equal to @var{mask}. The result is\n\ |
12642
f96b9b9f141b
doc: Periodic grammarcheck and spellcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
7325 constructed as follows:\n\ |
10840 | 7326 \n\ |
9473
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7327 @example\n\ |
9758
09da0bd91412
Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents:
9736
diff
changeset
|
7328 @group\n\ |
9473
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7329 result(mask) = tval(mask);\n\ |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7330 result(! mask) = fval(! mask);\n\ |
9758
09da0bd91412
Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents:
9736
diff
changeset
|
7331 @end group\n\ |
9473
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7332 @end example\n\ |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7333 \n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
7334 @var{mask} can also be arbitrary numeric type, in which case it is first\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
7335 converted to logical.\n\ |
15028
397f0d80bd47
Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents:
15024
diff
changeset
|
7336 @seealso{logical, diff}\n\ |
9473
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7337 @end deftypefn") |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7338 { |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7339 if (args.length () != 3) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7340 print_usage (); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7341 |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7342 if (! (args(0).is_bool_type () || args(0).is_numeric_type ())) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7343 error ("merge: first argument must be logical or numeric"); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7344 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
7345 octave_value retval; |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
7346 |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7347 octave_value mask_val = args(0); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7348 |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7349 if (mask_val.is_scalar_type ()) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7350 retval = mask_val.is_true () ? args(1) : args(2); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7351 else |
9473
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7352 { |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7353 boolNDArray mask = mask_val.bool_array_value (); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7354 |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7355 octave_value tval = args(1); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7356 octave_value fval = args(2); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7357 |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7358 if (tval.is_double_type () && fval.is_double_type ()) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7359 { |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7360 if (tval.is_complex_type () || fval.is_complex_type ()) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7361 retval = do_merge (mask, |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7362 tval.complex_array_value (), |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7363 fval.complex_array_value ()); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7364 else |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7365 retval = do_merge (mask, |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7366 tval.array_value (), |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7367 fval.array_value ()); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7368 } |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7369 else if (tval.is_single_type () && fval.is_single_type ()) |
9473
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7370 { |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7371 if (tval.is_complex_type () || fval.is_complex_type ()) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7372 retval = do_merge (mask, |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7373 tval.float_complex_array_value (), |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7374 fval.float_complex_array_value ()); |
9473
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7375 else |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7376 retval = do_merge (mask, |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7377 tval.float_array_value (), |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7378 fval.float_array_value ()); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7379 } |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7380 else if (tval.is_string () && fval.is_string ()) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7381 { |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7382 bool sq_string = tval.is_sq_string () || fval.is_sq_string (); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7383 retval = octave_value (do_merge (mask, |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7384 tval.char_array_value (), |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7385 fval.char_array_value ()), |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7386 sq_string ? '\'' : '"'); |
9473
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7387 } |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7388 else if (tval.is_cell () && fval.is_cell ()) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7389 { |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7390 retval = do_merge (mask, |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7391 tval.cell_value (), |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7392 fval.cell_value ()); |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7393 } |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7394 |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7395 MAKE_INT_BRANCH (int8) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7396 MAKE_INT_BRANCH (int16) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7397 MAKE_INT_BRANCH (int32) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7398 MAKE_INT_BRANCH (int64) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7399 MAKE_INT_BRANCH (uint8) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7400 MAKE_INT_BRANCH (uint16) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7401 MAKE_INT_BRANCH (uint32) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7402 MAKE_INT_BRANCH (uint64) |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7403 |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7404 else |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7405 error ("merge: cannot merge %s with %s with array mask", |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7406 tval.class_name ().c_str (), |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7407 fval.class_name ().c_str ()); |
9473
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7408 } |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7409 |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7410 return retval; |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7411 } |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7412 |
9505
a321a1c227c8
make ifelse an alias or merge
Jaroslav Hajek <highegg@gmail.com>
parents:
9475
diff
changeset
|
7413 DEFALIAS (ifelse, merge); |
a321a1c227c8
make ifelse an alias or merge
Jaroslav Hajek <highegg@gmail.com>
parents:
9475
diff
changeset
|
7414 |
9473
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7415 #undef MAKE_INT_BRANCH |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
7416 |
9513
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7417 template <class SparseT> |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7418 static SparseT |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7419 do_sparse_diff (const SparseT& array, octave_idx_type order, |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7420 int dim) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7421 { |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7422 SparseT retval = array; |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7423 if (dim == 1) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7424 { |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7425 octave_idx_type k = retval.columns (); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7426 while (order > 0 && k > 0) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7427 { |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7428 idx_vector col1 (':'), col2 (':'), sl1 (1, k), sl2 (0, k-1); |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
7429 retval = SparseT (retval.index (col1, sl1)) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
7430 - SparseT (retval.index (col2, sl2)); |
9513
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7431 assert (retval.columns () == k-1); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7432 order--; |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7433 k--; |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7434 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7435 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7436 else |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7437 { |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7438 octave_idx_type k = retval.rows (); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7439 while (order > 0 && k > 0) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7440 { |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7441 idx_vector col1 (':'), col2 (':'), sl1 (1, k), sl2 (0, k-1); |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
7442 retval = SparseT (retval.index (sl1, col1)) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
7443 - SparseT (retval.index (sl2, col2)); |
9513
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7444 assert (retval.rows () == k-1); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7445 order--; |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7446 k--; |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7447 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7448 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7449 |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7450 return retval; |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7451 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7452 |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7453 static octave_value |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7454 do_diff (const octave_value& array, octave_idx_type order, |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7455 int dim = -1) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7456 { |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7457 octave_value retval; |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7458 |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7459 const dim_vector& dv = array.dims (); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7460 if (dim == -1) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7461 { |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7462 dim = array.dims ().first_non_singleton (); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7463 |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7464 // Bother Matlab. This behavior is really wicked. |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7465 if (dv(dim) <= order) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7466 { |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7467 if (dv(dim) == 1) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7468 retval = array.resize (dim_vector (0, 0)); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7469 else |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7470 { |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7471 retval = array; |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7472 while (order > 0) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7473 { |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7474 if (dim == dv.length ()) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7475 { |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7476 retval = do_diff (array, order, dim - 1); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7477 order = 0; |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7478 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7479 else if (dv(dim) == 1) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7480 dim++; |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7481 else |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7482 { |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7483 retval = do_diff (array, dv(dim) - 1, dim); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7484 order -= dv(dim) - 1; |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7485 dim++; |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7486 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7487 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7488 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7489 |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7490 return retval; |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7491 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7492 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7493 |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7494 if (array.is_integer_type ()) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7495 { |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7496 if (array.is_int8_type ()) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7497 retval = array.int8_array_value ().diff (order, dim); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7498 else if (array.is_int16_type ()) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7499 retval = array.int16_array_value ().diff (order, dim); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7500 else if (array.is_int32_type ()) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7501 retval = array.int32_array_value ().diff (order, dim); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7502 else if (array.is_int64_type ()) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7503 retval = array.int64_array_value ().diff (order, dim); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7504 else if (array.is_uint8_type ()) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7505 retval = array.uint8_array_value ().diff (order, dim); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7506 else if (array.is_uint16_type ()) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7507 retval = array.uint16_array_value ().diff (order, dim); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7508 else if (array.is_uint32_type ()) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7509 retval = array.uint32_array_value ().diff (order, dim); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7510 else if (array.is_uint64_type ()) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7511 retval = array.uint64_array_value ().diff (order, dim); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7512 else |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7513 panic_impossible (); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7514 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7515 else if (array.is_sparse_type ()) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7516 { |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7517 if (array.is_complex_type ()) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
7518 retval = do_sparse_diff (array.sparse_complex_matrix_value (), |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
7519 order, dim); |
9513
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7520 else |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7521 retval = do_sparse_diff (array.sparse_matrix_value (), order, dim); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7522 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7523 else if (array.is_single_type ()) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7524 { |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7525 if (array.is_complex_type ()) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7526 retval = array.float_complex_array_value ().diff (order, dim); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7527 else |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7528 retval = array.float_array_value ().diff (order, dim); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7529 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7530 else |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7531 { |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7532 if (array.is_complex_type ()) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7533 retval = array.complex_array_value ().diff (order, dim); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7534 else |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7535 retval = array.array_value ().diff (order, dim); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7536 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7537 |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7538 return retval; |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7539 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7540 |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7541 DEFUN (diff, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
7542 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
7543 @deftypefn {} {} diff (@var{x})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
7544 @deftypefnx {} {} diff (@var{x}, @var{k})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
7545 @deftypefnx {} {} diff (@var{x}, @var{k}, @var{dim})\n\ |
20569
c6059134f5d3
data.cc: Add @w{} around @code segments in docstrings to prevent line breaks.
Rik <rik@octave.org>
parents:
20398
diff
changeset
|
7546 If @var{x} is a vector of length @math{n}, @w{@code{diff (@var{x})}} is the\n\ |
9513
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7547 vector of first differences\n\ |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7548 @tex\n\ |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7549 $x_2 - x_1, \\ldots{}, x_n - x_{n-1}$.\n\ |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7550 @end tex\n\ |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7551 @ifnottex\n\ |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7552 @var{x}(2) - @var{x}(1), @dots{}, @var{x}(n) - @var{x}(n-1).\n\ |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7553 @end ifnottex\n\ |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7554 \n\ |
20569
c6059134f5d3
data.cc: Add @w{} around @code segments in docstrings to prevent line breaks.
Rik <rik@octave.org>
parents:
20398
diff
changeset
|
7555 If @var{x} is a matrix, @w{@code{diff (@var{x})}} is the matrix of column\n\ |
9513
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7556 differences along the first non-singleton dimension.\n\ |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7557 \n\ |
20569
c6059134f5d3
data.cc: Add @w{} around @code segments in docstrings to prevent line breaks.
Rik <rik@octave.org>
parents:
20398
diff
changeset
|
7558 The second argument is optional. If supplied,\n\ |
c6059134f5d3
data.cc: Add @w{} around @code segments in docstrings to prevent line breaks.
Rik <rik@octave.org>
parents:
20398
diff
changeset
|
7559 @w{@code{diff (@var{x}, @var{k})}}, where @var{k} is a non-negative integer,\n\ |
c6059134f5d3
data.cc: Add @w{} around @code segments in docstrings to prevent line breaks.
Rik <rik@octave.org>
parents:
20398
diff
changeset
|
7560 returns the @var{k}-th differences. It is possible that @var{k} is larger\n\ |
c6059134f5d3
data.cc: Add @w{} around @code segments in docstrings to prevent line breaks.
Rik <rik@octave.org>
parents:
20398
diff
changeset
|
7561 than the first non-singleton dimension of the matrix. In this case,\n\ |
9513
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7562 @code{diff} continues to take the differences along the next\n\ |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7563 non-singleton dimension.\n\ |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7564 \n\ |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7565 The dimension along which to take the difference can be explicitly\n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
7566 stated with the optional variable @var{dim}. In this case the\n\ |
9513
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7567 @var{k}-th order differences are calculated along this dimension.\n\ |
20569
c6059134f5d3
data.cc: Add @w{} around @code segments in docstrings to prevent line breaks.
Rik <rik@octave.org>
parents:
20398
diff
changeset
|
7568 In the case where @var{k} exceeds @w{@code{size (@var{x}, @var{dim})}}\n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
7569 an empty matrix is returned.\n\ |
15028
397f0d80bd47
Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents:
15024
diff
changeset
|
7570 @seealso{sort, merge}\n\ |
9513
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7571 @end deftypefn") |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7572 { |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7573 int nargin = args.length (); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7574 |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7575 if (nargin < 1 || nargin > 3) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7576 print_usage (); |
20806
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7577 |
20975a6f677a
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
7578 if (! (args(0).is_numeric_type () || args(0).is_bool_type ())) |
10880 | 7579 error ("diff: X must be numeric or logical"); |
9513
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7580 |
20562
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
7581 int dim = -1; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
7582 octave_idx_type order = 1; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
7583 if (nargin > 1) |
9513
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7584 { |
20562
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
7585 if (args(1).is_scalar_type ()) |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
7586 order = args(1).idx_type_value (true, false); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
7587 else if (! args(1).is_zero_by_zero ()) |
20726
25d676f9619c
Preface error() messages with name of function when possible.
Rik <rik@octave.org>
parents:
20720
diff
changeset
|
7588 error ("diff: order K must be a scalar or []"); |
20562
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
7589 if (order < 0) |
20726
25d676f9619c
Preface error() messages with name of function when possible.
Rik <rik@octave.org>
parents:
20720
diff
changeset
|
7590 error ("diff: order K must be non-negative"); |
9513
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7591 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7592 |
20562
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
7593 if (nargin > 2) |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
7594 { |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
7595 dim = args(2).int_value (true, false); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
7596 if (dim < 1 || dim > args(0).ndims ()) |
20726
25d676f9619c
Preface error() messages with name of function when possible.
Rik <rik@octave.org>
parents:
20720
diff
changeset
|
7597 error ("diff: DIM must be a valid dimension"); |
20980
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
7598 |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
7599 dim -= 1; |
20562
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
7600 } |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
7601 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
7602 return do_diff (args(0), order, dim); |
9513
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7603 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7604 |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7605 /* |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7606 %!assert (diff ([1, 2, 3, 4]), [1, 1, 1]) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7607 %!assert (diff ([1, 3, 7, 19], 2), [2, 8]) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7608 %!assert (diff ([1, 2; 5, 4; 8, 7; 9, 6; 3, 1]), [4, 2; 3, 3; 1, -1; -6, -5]) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7609 %!assert (diff ([1, 2; 5, 4; 8, 7; 9, 6; 3, 1], 3), [-1, -5; -5, 0]) |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
7610 %!assert (isempty (diff (1))) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
7611 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
7612 %!error diff () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
7613 %!error diff (1, 2, 3, 4) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
7614 %!error diff ("foo") |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
7615 %!error diff ([1, 2; 3, 4], -1) |
9513
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7616 */ |
10799
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7617 |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7618 template <class T> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
7619 static Array<T> |
10799
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7620 do_repelems (const Array<T>& src, const Array<octave_idx_type>& rep) |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7621 { |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7622 Array<T> retval; |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7623 |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7624 assert (rep.ndims () == 2 && rep.rows () == 2); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7625 |
18100
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17915
diff
changeset
|
7626 octave_idx_type n = rep.columns (); |
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17915
diff
changeset
|
7627 octave_idx_type l = 0; |
10799
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7628 for (octave_idx_type i = 0; i < n; i++) |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7629 { |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7630 octave_idx_type k = rep(1, i); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7631 if (k < 0) |
20893
384ff5aa9437
2015 Code Sprint: Eliminate useless return statements after error ().
Rik <rik@octave.org>
parents:
20884
diff
changeset
|
7632 error ("repelems: second row must contain non-negative numbers"); |
10799
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7633 |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7634 l += k; |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7635 } |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7636 |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7637 retval.clear (1, l); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7638 T *dest = retval.fortran_vec (); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7639 l = 0; |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7640 for (octave_idx_type i = 0; i < n; i++) |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7641 { |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7642 octave_idx_type k = rep(1, i); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7643 std::fill_n (dest, k, src.checkelem (rep(0, i) - 1)); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7644 dest += k; |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7645 } |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7646 |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7647 return retval; |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7648 } |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7649 |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7650 DEFUN (repelems, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
7651 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
7652 @deftypefn {} {} repelems (@var{x}, @var{r})\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
7653 Construct a vector of repeated elements from @var{x}.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
7654 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
7655 @var{r} is a 2x@var{N} integer matrix specifying which elements to repeat and\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
7656 how often to repeat each element. Entries in the first row, @var{r}(1,j),\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
7657 select an element to repeat. The corresponding entry in the second row,\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
7658 @var{r}(2,j), specifies the repeat count. If @var{x} is a matrix then the\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
7659 columns of @var{x} are imagined to be stacked on top of each other for\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
7660 purposes of the selection index. A row vector is always returned.\n\ |
10801
a40e32927b3a
Improve documentation for new repelems function.
Rik <octave@nomad.inbox5.com>
parents:
10799
diff
changeset
|
7661 \n\ |
a40e32927b3a
Improve documentation for new repelems function.
Rik <octave@nomad.inbox5.com>
parents:
10799
diff
changeset
|
7662 Conceptually the result is calculated as follows:\n\ |
10799
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7663 \n\ |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7664 @example\n\ |
10840 | 7665 @group\n\ |
10801
a40e32927b3a
Improve documentation for new repelems function.
Rik <octave@nomad.inbox5.com>
parents:
10799
diff
changeset
|
7666 y = [];\n\ |
a40e32927b3a
Improve documentation for new repelems function.
Rik <octave@nomad.inbox5.com>
parents:
10799
diff
changeset
|
7667 for i = 1:columns (@var{r})\n\ |
a40e32927b3a
Improve documentation for new repelems function.
Rik <octave@nomad.inbox5.com>
parents:
10799
diff
changeset
|
7668 y = [y, @var{x}(@var{r}(1,i)*ones(1, @var{r}(2,i)))];\n\ |
a40e32927b3a
Improve documentation for new repelems function.
Rik <octave@nomad.inbox5.com>
parents:
10799
diff
changeset
|
7669 endfor\n\ |
10840 | 7670 @end group\n\ |
10799
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7671 @end example\n\ |
15028
397f0d80bd47
Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents:
15024
diff
changeset
|
7672 @seealso{repmat, cat}\n\ |
10799
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7673 @end deftypefn") |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7674 { |
20850
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
7675 if (args.length () != 2) |
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
7676 print_usage (); |
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
7677 |
10799
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7678 octave_value retval; |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7679 |
20850
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
7680 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
|
7681 |
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
7682 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
|
7683 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
|
7684 |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
7685 octave_value x = args(0); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
7686 |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
7687 NoAlias< Array<octave_idx_type> > r (rm.dims ()); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
7688 |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
7689 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
|
7690 { |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
7691 octave_idx_type rx = rm(i); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
7692 if (static_cast<double> (rx) != rm(i)) |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
7693 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
|
7694 |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
7695 r(i) = rx; |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
7696 } |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
7697 |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
7698 switch (x.builtin_type ()) |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
7699 { |
10799
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7700 #define BTYP_BRANCH(X, EX) \ |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
7701 case btyp_ ## X: \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
7702 retval = do_repelems (x.EX ## _value (), r); \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
7703 break; |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
7704 |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
7705 BTYP_BRANCH (double, array); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
7706 BTYP_BRANCH (float, float_array); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
7707 BTYP_BRANCH (complex, complex_array); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
7708 BTYP_BRANCH (float_complex, float_complex_array); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
7709 BTYP_BRANCH (bool, bool_array); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
7710 BTYP_BRANCH (char, char_array); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
7711 |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
7712 BTYP_BRANCH (int8, int8_array); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
7713 BTYP_BRANCH (int16, int16_array); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
7714 BTYP_BRANCH (int32, int32_array); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
7715 BTYP_BRANCH (int64, int64_array); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
7716 BTYP_BRANCH (uint8, uint8_array); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
7717 BTYP_BRANCH (uint16, uint16_array); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
7718 BTYP_BRANCH (uint32, uint32_array); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
7719 BTYP_BRANCH (uint64, uint64_array); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
7720 |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
7721 BTYP_BRANCH (cell, cell); |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
7722 //BTYP_BRANCH (struct, map);//FIXME |
10799
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7723 #undef BTYP_BRANCH |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7724 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
7725 default: |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21078
diff
changeset
|
7726 err_wrong_type_arg ("repelems", x); |
10799
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7727 } |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7728 |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7729 return retval; |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7730 } |
15050
abc858bc5165
Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15038
diff
changeset
|
7731 |
15252
fa0118cb67d9
move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents:
15213
diff
changeset
|
7732 DEFUN (base64_encode, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
7733 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
7734 @deftypefn {} {@var{s} =} base64_encode (@var{x})\n\ |
15052
70a1b50bcb45
maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents:
15050
diff
changeset
|
7735 Encode a double matrix or array @var{x} into the base64 format string\n\ |
70a1b50bcb45
maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents:
15050
diff
changeset
|
7736 @var{s}.\n\ |
70a1b50bcb45
maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents:
15050
diff
changeset
|
7737 \n\ |
15050
abc858bc5165
Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15038
diff
changeset
|
7738 @seealso{base64_decode}\n\ |
abc858bc5165
Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15038
diff
changeset
|
7739 @end deftypefn") |
abc858bc5165
Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15038
diff
changeset
|
7740 { |
20819
f428cbe7576f
eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents:
20816
diff
changeset
|
7741 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
|
7742 print_usage (); |
20850
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
7743 |
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
7744 if (! args(0).is_numeric_type ()) |
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
7745 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
|
7746 |
81c2b14c209f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
7747 if (args(0).is_complex_type () || args(0).is_sparse_type ()) |
20850
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
7748 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
|
7749 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
7750 octave_value_list retval; |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
7751 |
20850
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
7752 if (args(0).is_integer_type ()) |
15050
abc858bc5165
Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15038
diff
changeset
|
7753 { |
20562
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
7754 #define MAKE_INT_BRANCH(X) \ |
20850
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
7755 if (args(0).is_ ## X ## _type ()) \ |
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
7756 { \ |
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
7757 const X##NDArray in = args(0). X## _array_value (); \ |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
7758 size_t inlen = in.numel () * sizeof (X## _t) / sizeof (char); \ |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
7759 const char* inc = reinterpret_cast<const char*> (in.data ()); \ |
20850
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
7760 char* out; \ |
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
7761 if (octave_base64_encode (inc, inlen, &out)) \ |
20562
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20542
diff
changeset
|
7762 { \ |
20850
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
7763 retval(0) = octave_value (out); \ |
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
7764 ::free (out); \ |
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
7765 } \ |
15111
5dd599df36de
generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15094
diff
changeset
|
7766 } |
20850
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
7767 |
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
7768 MAKE_INT_BRANCH(int8) |
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
7769 else MAKE_INT_BRANCH(int16) |
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
7770 else MAKE_INT_BRANCH(int32) |
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
7771 else MAKE_INT_BRANCH(int64) |
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
7772 else MAKE_INT_BRANCH(uint8) |
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
7773 else MAKE_INT_BRANCH(uint16) |
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
7774 else MAKE_INT_BRANCH(uint32) |
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
7775 else MAKE_INT_BRANCH(uint64) |
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
7776 #undef MAKE_INT_BRANCH |
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
7777 |
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
7778 else |
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
7779 panic_impossible (); |
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
7780 } |
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
7781 else 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
|
7782 { |
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
7783 const Array<float> in = args(0).float_array_value (); |
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
7784 size_t inlen; |
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
7785 inlen = in.numel () * sizeof (float) / sizeof (char); |
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
7786 const char* inc; |
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
7787 inc = reinterpret_cast<const char*> (in.data ()); |
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
7788 char* out; |
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
7789 if (octave_base64_encode (inc, inlen, &out)) |
15111
5dd599df36de
generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15094
diff
changeset
|
7790 { |
20850
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
7791 retval(0) = octave_value (out); |
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
7792 ::free (out); |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
7793 } |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
7794 } |
20850
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
7795 else // double_type |
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
7796 { |
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
7797 const Array<double> in = args(0).array_value (); |
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
7798 size_t inlen; |
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
7799 inlen = in.numel () * sizeof (double) / sizeof (char); |
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
7800 const char* inc; |
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
7801 inc = reinterpret_cast<const char*> (in.data ()); |
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
7802 char* out; |
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
7803 if (octave_base64_encode (inc, inlen, &out)) |
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
7804 { |
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
7805 retval(0) = octave_value (out); |
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
7806 ::free (out); |
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
7807 } |
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
7808 } |
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
7809 |
15052
70a1b50bcb45
maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents:
15050
diff
changeset
|
7810 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
|
7811 } |
abc858bc5165
Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15038
diff
changeset
|
7812 |
abc858bc5165
Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15038
diff
changeset
|
7813 /* |
15111
5dd599df36de
generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15094
diff
changeset
|
7814 %!assert (base64_encode (single (pi)), "2w9JQA==") |
5dd599df36de
generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15094
diff
changeset
|
7815 %!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
|
7816 %!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
|
7817 %!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
|
7818 %!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
|
7819 %!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
|
7820 |
70a1b50bcb45
maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents:
15050
diff
changeset
|
7821 %!error base64_encode () |
70a1b50bcb45
maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents:
15050
diff
changeset
|
7822 %!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
|
7823 %!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
|
7824 %!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
|
7825 %!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
|
7826 */ |
abc858bc5165
Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15038
diff
changeset
|
7827 |
15252
fa0118cb67d9
move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents:
15213
diff
changeset
|
7828 DEFUN (base64_decode, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
7829 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
7830 @deftypefn {} {@var{x} =} base64_decode (@var{s})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20850
diff
changeset
|
7831 @deftypefnx {} {@var{x} =} base64_decode (@var{s}, @var{dims})\n\ |
15252
fa0118cb67d9
move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents:
15213
diff
changeset
|
7832 Decode the double matrix or array @var{x} from the base64 encoded string\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
7833 @var{s}.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
7834 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
7835 The optional input parameter @var{dims} should be a vector containing the\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19861
diff
changeset
|
7836 dimensions of the decoded array.\n\ |
15050
abc858bc5165
Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15038
diff
changeset
|
7837 @seealso{base64_encode}\n\ |
abc858bc5165
Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15038
diff
changeset
|
7838 @end deftypefn") |
abc858bc5165
Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15038
diff
changeset
|
7839 { |
abc858bc5165
Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15038
diff
changeset
|
7840 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
|
7841 |
15050
abc858bc5165
Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15038
diff
changeset
|
7842 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
|
7843 print_usage (); |
20850
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
7844 |
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
7845 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
|
7846 |
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
7847 Array<double> retval = octave_base64_decode (str); |
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
7848 |
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
7849 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
|
7850 { |
15252
fa0118cb67d9
move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents:
15213
diff
changeset
|
7851 dim_vector dims; |
15052
70a1b50bcb45
maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents:
15050
diff
changeset
|
7852 |
20850
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
7853 const Array<octave_idx_type> size = |
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
7854 args(1).octave_idx_type_vector_value (); |
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
7855 |
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
7856 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
|
7857 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
|
7858 dims(i) = size(i); |
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
7859 |
b36aa3044bca
2015 Code sprint: data.cc: recode instances of print_usage.
Rik <rik@octave.org>
parents:
20819
diff
changeset
|
7860 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
|
7861 } |
15052
70a1b50bcb45
maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents:
15050
diff
changeset
|
7862 |
21127
df7891224709
maint: Use "return ovl (...)" in DEFUN macros.
Rik <rik@octave.org>
parents:
21121
diff
changeset
|
7863 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
|
7864 } |
abc858bc5165
Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15038
diff
changeset
|
7865 |
abc858bc5165
Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15038
diff
changeset
|
7866 /* |
15052
70a1b50bcb45
maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents:
15050
diff
changeset
|
7867 %!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
|
7868 %! |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
7869 %!test |
15052
70a1b50bcb45
maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents:
15050
diff
changeset
|
7870 %! in = randn (10); |
70a1b50bcb45
maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents:
15050
diff
changeset
|
7871 %! 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
|
7872 %! 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
|
7873 %! assert (outv, in(:).'); |
70a1b50bcb45
maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents:
15050
diff
changeset
|
7874 %! assert (outm, in); |
70a1b50bcb45
maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents:
15050
diff
changeset
|
7875 |
70a1b50bcb45
maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents:
15050
diff
changeset
|
7876 %!error base64_decode () |
70a1b50bcb45
maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents:
15050
diff
changeset
|
7877 %!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
|
7878 %!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
|
7879 %!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
|
7880 %!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
|
7881 %!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
|
7882 */ |