Mercurial > hg > octave-nkf
annotate libinterp/corefcn/data.cc @ 20830:b65888ec820e draft default tip gccjit
dmalcom gcc jit import
author | Stefan Mahr <dac922@gmx.de> |
---|---|
date | Fri, 27 Feb 2015 16:59:36 +0100 |
parents | 5fc798a9b32c |
children |
rev | line source |
---|---|
523 | 1 /* |
2 | |
19898
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19794
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" | |
54 #include "gripes.h" | |
6953 | 55 #include "oct-map.h" |
56 #include "oct-obj.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 |
4015 | 85 #define ANY_ALL(FCN) \ |
86 \ | |
4233 | 87 octave_value retval; \ |
4015 | 88 \ |
89 int nargin = args.length (); \ | |
90 \ | |
4021 | 91 if (nargin == 1 || nargin == 2) \ |
4015 | 92 { \ |
4021 | 93 int dim = (nargin == 1 ? -1 : args(1).int_value (true) - 1); \ |
94 \ | |
95 if (! error_state) \ | |
96 { \ | |
4556 | 97 if (dim >= -1) \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
98 retval = args(0).FCN (dim); \ |
4021 | 99 else \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
100 error (#FCN ": invalid dimension argument = %d", dim + 1); \ |
4021 | 101 } \ |
4015 | 102 else \ |
4021 | 103 error (#FCN ": expecting dimension argument to be an integer"); \ |
4015 | 104 } \ |
4021 | 105 else \ |
5823 | 106 print_usage (); \ |
4015 | 107 \ |
108 return retval | |
109 | |
1957 | 110 DEFUN (all, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
111 "-*- texinfo -*-\n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
112 @deftypefn {Built-in Function} {} all (@var{x})\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
113 @deftypefnx {Built-in Function} {} all (@var{x}, @var{dim})\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
114 For a vector argument, return true (logical 1) if all elements of the vector\n\ |
19007
9ac2357f19bc
doc: Replace "non-zero" with "nonzero" to match existing usage.
Rik <rik@octave.org>
parents:
19006
diff
changeset
|
115 are nonzero.\n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
116 \n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
117 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
|
118 zeros with each element indicating whether all of the elements of the\n\ |
19007
9ac2357f19bc
doc: Replace "non-zero" with "nonzero" to match existing usage.
Rik <rik@octave.org>
parents:
19006
diff
changeset
|
119 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
|
120 \n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
121 @example\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
122 @group\n\ |
18834
a142f35f3cb6
doc: Fix unbalanced parentheses in documentation.
Rik <rik@octave.org>
parents:
18833
diff
changeset
|
123 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
|
124 @result{} [ 1, 0 ]\n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
125 @end group\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
126 @end example\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
127 \n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
128 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
|
129 @var{dim}.\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
130 @seealso{any}\n\ |
3369 | 131 @end deftypefn") |
523 | 132 { |
4015 | 133 ANY_ALL (all); |
523 | 134 } |
135 | |
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 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
138 %! 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
|
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 (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]); |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
144 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
145 %!test |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
146 %! 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
|
147 %! x(1,1) = 0; |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
148 %! 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
|
149 %! 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
|
150 %! 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
|
151 %! 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
|
152 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
153 %!error all () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
154 %!error all (1, 2, 3) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
155 */ |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
156 |
1957 | 157 DEFUN (any, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
158 "-*- texinfo -*-\n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
159 @deftypefn {Built-in Function} {} any (@var{x})\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
160 @deftypefnx {Built-in Function} {} any (@var{x}, @var{dim})\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
161 For a vector argument, return true (logical 1) if any element of the vector\n\ |
19007
9ac2357f19bc
doc: Replace "non-zero" with "nonzero" to match existing usage.
Rik <rik@octave.org>
parents:
19006
diff
changeset
|
162 is nonzero.\n\ |
3369 | 163 \n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
164 For a matrix argument, return a row vector of logical ones and\n\ |
3369 | 165 zeros with each element indicating whether any of the elements of the\n\ |
19007
9ac2357f19bc
doc: Replace "non-zero" with "nonzero" to match existing usage.
Rik <rik@octave.org>
parents:
19006
diff
changeset
|
166 corresponding column of the matrix are nonzero. For example:\n\ |
3369 | 167 \n\ |
168 @example\n\ | |
169 @group\n\ | |
170 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
|
171 @result{} [ 1, 1, 0, 0 ]\n\ |
3369 | 172 @end group\n\ |
173 @end example\n\ | |
174 \n\ | |
4015 | 175 If the optional argument @var{dim} is supplied, work along dimension\n\ |
10840 | 176 @var{dim}. For example:\n\ |
3369 | 177 \n\ |
178 @example\n\ | |
4015 | 179 @group\n\ |
180 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
|
181 @result{} [ 1; 1 ]\n\ |
4015 | 182 @end group\n\ |
3369 | 183 @end example\n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
184 @seealso{all}\n\ |
3369 | 185 @end deftypefn") |
523 | 186 { |
4015 | 187 ANY_ALL (any); |
523 | 188 } |
189 | |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
190 /* |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
191 %!test |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
192 %! 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
|
193 %! x(3,3) = 1; |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
194 %! 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
|
195 %! 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
|
196 %! 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
|
197 %! 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
|
198 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
199 %!test |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
200 %! 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
|
201 %! x(3,3) = 1; |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
202 %! 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
|
203 %! 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
|
204 %! 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
|
205 %! 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
|
206 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
207 %!error any () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
208 %!error any (1, 2, 3) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
209 */ |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
210 |
649 | 211 // These mapping functions may also be useful in other places, eh? |
212 | |
1957 | 213 DEFUN (atan2, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
214 "-*- texinfo -*-\n\ |
3428 | 215 @deftypefn {Mapping Function} {} atan2 (@var{y}, @var{x})\n\ |
216 Compute atan (@var{y} / @var{x}) for corresponding elements of @var{y}\n\ | |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
217 and @var{x}.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
218 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
219 @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
|
220 @seealso{tan, tand, tanh, atanh}\n\ |
3439 | 221 @end deftypefn") |
649 | 222 { |
4233 | 223 octave_value retval; |
649 | 224 |
712 | 225 int nargin = args.length (); |
226 | |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
227 if (nargin == 2) |
649 | 228 { |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
229 if (! args(0).is_numeric_type ()) |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
230 gripe_wrong_type_arg ("atan2", args(0)); |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
231 else if (! args(1).is_numeric_type ()) |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
232 gripe_wrong_type_arg ("atan2", args(1)); |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
233 else if (args(0).is_complex_type () || args(1).is_complex_type ()) |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
234 error ("atan2: not defined for complex numbers"); |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
235 else if (args(0).is_single_type () || args(1).is_single_type ()) |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
236 { |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
237 if (args(0).is_scalar_type () && args(1).is_scalar_type ()) |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
238 retval = atan2f (args(0).float_value (), args(1).float_value ()); |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
239 else |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
240 { |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
241 FloatNDArray a0 = args(0).float_array_value (); |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
242 FloatNDArray a1 = args(1).float_array_value (); |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
243 retval = binmap<float> (a0, a1, ::atan2f, "atan2"); |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
244 } |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
245 } |
7494
bd2bd04e68ca
Treat integer types for mod/rem correctly
David Bateman <dbateman@free.fr>
parents:
7433
diff
changeset
|
246 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
247 { |
18978
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
248 if (args(0).is_scalar_type () && args(1).is_scalar_type ()) |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
249 retval = atan2 (args(0).scalar_value (), args(1).scalar_value ()); |
18978
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
250 else if (args(0).is_sparse_type ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
251 { |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
252 SparseMatrix m0 = args(0).sparse_matrix_value (); |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
253 SparseMatrix m1 = args(1).sparse_matrix_value (); |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
254 retval = binmap<double> (m0, m1, ::atan2, "atan2"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
255 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
256 else |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
257 { |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
258 NDArray a0 = args(0).array_value (); |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
259 NDArray a1 = args(1).array_value (); |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
260 retval = binmap<double> (a0, a1, ::atan2, "atan2"); |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
261 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
262 } |
649 | 263 } |
712 | 264 else |
5823 | 265 print_usage (); |
649 | 266 |
267 return retval; | |
268 } | |
269 | |
7506
798b0a00e80c
atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents:
7505
diff
changeset
|
270 /* |
7741 | 271 %!assert (size (atan2 (zeros (0, 2), zeros (0, 2))), [0, 2]) |
272 %!assert (size (atan2 (rand (2, 3, 4), zeros (2, 3, 4))), [2, 3, 4]) | |
273 %!assert (size (atan2 (rand (2, 3, 4), 1)), [2, 3, 4]) | |
274 %!assert (size (atan2 (1, rand (2, 3, 4))), [2, 3, 4]) | |
275 %!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
|
276 |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
277 %!test |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
278 %! rt2 = sqrt (2); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
279 %! rt3 = sqrt (3); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
280 %! 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
|
281 %! 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
|
282 %! 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
|
283 %! 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
|
284 |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
285 %!test |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
286 %! rt2 = sqrt (2); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
287 %! rt3 = sqrt (3); |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
288 %! 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
|
289 %! 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
|
290 %! 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
|
291 %! 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
|
292 |
18978
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
293 ## Test sparse implementations |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
294 %!shared xs |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
295 %! xs = sparse (0:3); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
296 %!test |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
297 %! y = atan2 (1, xs); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
298 %! assert (issparse (y), false); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
299 %! assert (nnz (y), 4); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
300 %! assert (y, atan2 (1, 0:3)); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
301 %!test |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
302 %! y = atan2 (0, xs); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
303 %! assert (issparse (y), false); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
304 %! assert (nnz (y), 0); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
305 %! assert (y, zeros (1,4)); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
306 %!test |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
307 %! y = atan2 (xs, 1); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
308 %! assert (issparse (y)); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
309 %! assert (nnz (y), 3); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
310 %! assert (y, sparse (atan2 (0:3, 1))); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
311 %!test |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
312 %! y = atan2 (xs, 0); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
313 %! assert (issparse (y)); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
314 %! assert (nnz (y), 3); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
315 %! assert (y, sparse (atan2 (0:3, 0))); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
316 %!test |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
317 %! y = atan2 (xs, sparse (ones (1, 4))); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
318 %! assert (issparse (y)); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
319 %! assert (nnz (y), 3); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
320 %! 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:
18964
diff
changeset
|
321 %!test |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
322 %! y = atan2 (xs, sparse (zeros (1,4))); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
323 %! assert (issparse (y)); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
324 %! assert (nnz (y), 3); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
325 %! 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:
18964
diff
changeset
|
326 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
327 %!error atan2 () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
328 %!error atan2 (1, 2, 3) |
7506
798b0a00e80c
atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents:
7505
diff
changeset
|
329 */ |
798b0a00e80c
atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents:
7505
diff
changeset
|
330 |
7815
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
331 |
10538
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
332 static octave_value |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
333 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
|
334 { |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
335 octave_value retval; |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
336 |
18099
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17915
diff
changeset
|
337 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
|
338 octave_value arg1 = y; |
10538
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
339 if (! arg0.is_numeric_type ()) |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
340 gripe_wrong_type_arg ("hypot", arg0); |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
341 else if (! arg1.is_numeric_type ()) |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
342 gripe_wrong_type_arg ("hypot", arg1); |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
343 else |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
344 { |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
345 if (arg0.is_complex_type ()) |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
346 arg0 = arg0.abs (); |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
347 if (arg1.is_complex_type ()) |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
348 arg1 = arg1.abs (); |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
349 |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
350 if (arg0.is_single_type () || arg1.is_single_type ()) |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
351 { |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
352 if (arg0.is_scalar_type () && arg1.is_scalar_type ()) |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
353 retval = hypotf (arg0.float_value (), arg1.float_value ()); |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
354 else |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
355 { |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
356 FloatNDArray a0 = arg0.float_array_value (); |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
357 FloatNDArray a1 = arg1.float_array_value (); |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
358 retval = binmap<float> (a0, a1, ::hypotf, "hypot"); |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
359 } |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
360 } |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
361 else |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
362 { |
18978
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
363 if (arg0.is_scalar_type () && arg1.is_scalar_type ()) |
10538
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
364 retval = hypot (arg0.scalar_value (), arg1.scalar_value ()); |
18978
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
365 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
|
366 { |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
367 SparseMatrix m0 = arg0.sparse_matrix_value (); |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
368 SparseMatrix m1 = arg1.sparse_matrix_value (); |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
369 retval = binmap<double> (m0, m1, ::hypot, "hypot"); |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
370 } |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
371 else |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
372 { |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
373 NDArray a0 = arg0.array_value (); |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
374 NDArray a1 = arg1.array_value (); |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
375 retval = binmap<double> (a0, a1, ::hypot, "hypot"); |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
376 } |
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\ |
10840 | 385 @deftypefn {Built-in Function} {} hypot (@var{x}, @var{y})\n\ |
10711
fbd7843974fa
Periodic grammar check of documentation files to ensure common format.
Rik <octave@nomad.inbox5.com>
parents:
10707
diff
changeset
|
386 @deftypefnx {Built-in Function} {} 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\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
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:
20068
diff
changeset
|
389 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
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:
20068
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\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
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 octave_value retval; | |
406 | |
407 int nargin = args.length (); | |
408 | |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
409 if (nargin == 2) |
7631 | 410 { |
10538
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
411 retval = do_hypot (args(0), args(1)); |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
412 } |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
413 else if (nargin >= 3) |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
414 { |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
415 retval = args(0); |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
416 for (int i = 1; i < nargin; i++) |
10538
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
417 retval = do_hypot (retval, args(i)); |
7631 | 418 } |
419 else | |
420 print_usage (); | |
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])) |
18978
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
433 |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
434 ## Test sparse implementations |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
435 %!shared xs |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
436 %! xs = sparse (0:3); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
437 %!test |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
438 %! y = hypot (1, xs); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
439 %! assert (nnz (y), 4); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
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:
18964
diff
changeset
|
441 %!test |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
442 %! y = hypot (0, xs); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
443 %! assert (nnz (y), 3); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
444 %! assert (y, xs); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
445 %!test |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
446 %! y = hypot (xs, 1); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
447 %! assert (nnz (y), 4); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
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:
18964
diff
changeset
|
449 %!test |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
450 %! y = hypot (xs, 0); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
451 %! assert (nnz (y), 3); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
452 %! assert (y, xs); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
453 %!test |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
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:
18964
diff
changeset
|
455 %! assert (nnz (y), 1); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
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:
18964
diff
changeset
|
457 %!test |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
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:
18964
diff
changeset
|
459 %! assert (nnz (y), 1); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
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:
18964
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\ |
10840 | 480 @deftypefn {Mapping Function} {} log2 (@var{x})\n\ |
9813
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
481 @deftypefnx {Mapping Function} {[@var{f}, @var{e}] =} log2 (@var{x})\n\ |
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\ |
20780
c6059134f5d3
data.cc: Add @w{} around @code segments in docstrings to prevent line breaks.
Rik <rik@octave.org>
parents:
20608
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\ |
20780
c6059134f5d3
data.cc: Add @w{} around @code segments in docstrings to prevent line breaks.
Rik <rik@octave.org>
parents:
20608
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 { |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
502 octave_value_list retval; |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
503 |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
504 if (args.length () == 1) |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
505 { |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
506 if (nargout < 2) |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
507 retval(0) = args(0).log2 (); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
508 else if (args(0).is_single_type ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
509 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
510 if (args(0).is_real_type ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
511 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
512 FloatNDArray f; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
513 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
|
514 // FIXME: should E be an int value? |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
515 FloatMatrix e; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
516 map_2_xlog2 (x, f, e); |
14843
7d4f87c75dbb
data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents:
14635
diff
changeset
|
517 retval(1) = e; |
7d4f87c75dbb
data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents:
14635
diff
changeset
|
518 retval(0) = f; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
519 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
520 else if (args(0).is_complex_type ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
521 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
522 FloatComplexNDArray f; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
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? |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
525 FloatNDArray e; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
526 map_2_xlog2 (x, f, e); |
14843
7d4f87c75dbb
data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents:
14635
diff
changeset
|
527 retval(1) = e; |
7d4f87c75dbb
data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents:
14635
diff
changeset
|
528 retval(0) = f; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
529 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
530 } |
9813
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
531 else if (args(0).is_real_type ()) |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
532 { |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
533 NDArray f; |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
534 NDArray x = args(0).array_value (); |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
535 // FIXME: should E be an int value? |
9813
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
536 Matrix e; |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
537 map_2_xlog2 (x, f, e); |
14843
7d4f87c75dbb
data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents:
14635
diff
changeset
|
538 retval(1) = e; |
7d4f87c75dbb
data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents:
14635
diff
changeset
|
539 retval(0) = f; |
9813
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
540 } |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
541 else if (args(0).is_complex_type ()) |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
542 { |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
543 ComplexNDArray f; |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
544 ComplexNDArray x = args(0).complex_array_value (); |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
545 // FIXME: should E be an int value? |
9813
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
546 NDArray e; |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
547 map_2_xlog2 (x, f, e); |
14843
7d4f87c75dbb
data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents:
14635
diff
changeset
|
548 retval(1) = e; |
7d4f87c75dbb
data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents:
14635
diff
changeset
|
549 retval(0) = f; |
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 else |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
552 gripe_wrong_type_arg ("log2", args(0)); |
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 else |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
555 print_usage (); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
556 |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
557 return retval; |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
558 } |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
559 |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
560 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
561 %!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
|
562 %!assert (log2 (Inf), Inf) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
563 %!assert (isnan (log2 (NaN))) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
564 %!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
|
565 %!assert (log2 (complex (0,Inf)), Inf + log2 (i)) |
9813
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
566 |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
567 %!test |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
568 %! [f, e] = log2 ([0,-1; 2,-4; Inf,-Inf]); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
569 %! 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
|
570 %! assert (e(1:2,:), [0,1;2,3]); |
9813
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
571 |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
572 %!test |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
573 %! [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
|
574 %! 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
|
575 %! assert (e(1:2,:), [0,1; 2,3]); |
19041
9d185537e5d1
* data.cc: New test for log2 (bug #42583).
John W. Eaton <jwe@octave.org>
parents:
19004
diff
changeset
|
576 |
9d185537e5d1
* data.cc: New test for log2 (bug #42583).
John W. Eaton <jwe@octave.org>
parents:
19004
diff
changeset
|
577 # bug #42583 |
9d185537e5d1
* data.cc: New test for log2 (bug #42583).
John W. Eaton <jwe@octave.org>
parents:
19004
diff
changeset
|
578 %!assert (all (log2 (pow2 (-1074:1023)) == -1074:1023)) |
9813
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
579 */ |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
580 |
10436
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
581 DEFUN (rem, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
582 "-*- texinfo -*-\n\ |
19310 | 583 @deftypefn {Mapping Function} {} rem (@var{x}, @var{y})\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
584 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:
20068
diff
changeset
|
585 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
586 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
|
587 \n\ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
588 @example\n\ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
589 x - y .* fix (x ./ y)\n\ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
590 @end example\n\ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
591 \n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
592 An error message is printed if the dimensions of the arguments do not agree,\n\ |
20584
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20442
diff
changeset
|
593 or if either argument is complex.\n\ |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20442
diff
changeset
|
594 \n\ |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20442
diff
changeset
|
595 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:
20442
diff
changeset
|
596 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:
20442
diff
changeset
|
597 @sc{matlab}.\n\ |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20442
diff
changeset
|
598 \n\ |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20442
diff
changeset
|
599 By convention,\n\ |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20442
diff
changeset
|
600 \n\ |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20442
diff
changeset
|
601 @example\n\ |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20442
diff
changeset
|
602 @group\n\ |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20442
diff
changeset
|
603 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:
20442
diff
changeset
|
604 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:
20442
diff
changeset
|
605 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:
20442
diff
changeset
|
606 @end group\n\ |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20442
diff
changeset
|
607 @end example\n\ |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20442
diff
changeset
|
608 \n\ |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20442
diff
changeset
|
609 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:
20442
diff
changeset
|
610 @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:
20442
diff
changeset
|
611 @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:
20442
diff
changeset
|
612 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
|
613 @seealso{mod}\n\ |
4311 | 614 @end deftypefn") |
615 { | |
616 octave_value retval; | |
617 | |
618 int nargin = args.length (); | |
619 | |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
620 if (nargin == 2) |
4311 | 621 { |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
622 if (! args(0).is_numeric_type ()) |
10436
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
623 gripe_wrong_type_arg ("rem", args(0)); |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
624 else if (! args(1).is_numeric_type ()) |
10436
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
625 gripe_wrong_type_arg ("rem", args(1)); |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
626 else if (args(0).is_complex_type () || args(1).is_complex_type ()) |
10436
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
627 error ("rem: not defined for complex numbers"); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
628 else if (args(0).is_integer_type () || args(1).is_integer_type ()) |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
629 { |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
630 builtin_type_t btyp0 = args(0).builtin_type (); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
631 builtin_type_t btyp1 = args(1).builtin_type (); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
632 if (btyp0 == btyp_double || btyp0 == btyp_float) |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
633 btyp0 = btyp1; |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
634 if (btyp1 == btyp_double || btyp1 == btyp_float) |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
635 btyp1 = btyp0; |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
636 |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
637 if (btyp0 == btyp1) |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
638 { |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
639 switch (btyp0) |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
640 { |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
641 #define MAKE_INT_BRANCH(X) \ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
642 case btyp_ ## X: \ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
643 { \ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
644 X##NDArray a0 = args(0).X##_array_value (); \ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
645 X##NDArray a1 = args(1).X##_array_value (); \ |
10682
7b4ffe27bbb4
Specify template arguments explicitely [MSVC].
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10538
diff
changeset
|
646 retval = binmap<octave_##X,octave_##X,octave_##X> (a0, a1, rem, "rem"); \ |
10436
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
647 } \ |
18891
5baada25d5a2
Rewrite docstring of sum() to match prod().
Rik <rik@octave.org>
parents:
18890
diff
changeset
|
648 break; |
10436
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
649 MAKE_INT_BRANCH (int8); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
650 MAKE_INT_BRANCH (int16); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
651 MAKE_INT_BRANCH (int32); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
652 MAKE_INT_BRANCH (int64); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
653 MAKE_INT_BRANCH (uint8); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
654 MAKE_INT_BRANCH (uint16); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
655 MAKE_INT_BRANCH (uint32); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
656 MAKE_INT_BRANCH (uint64); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
657 #undef MAKE_INT_BRANCH |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
658 default: |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
659 panic_impossible (); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
660 } |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
661 } |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
662 else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
663 error ("rem: cannot combine %s and %d", |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
664 args(0).class_name ().c_str (), |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
665 args(1).class_name ().c_str ()); |
10436
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
666 } |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
667 else if (args(0).is_single_type () || args(1).is_single_type ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
668 { |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
669 if (args(0).is_scalar_type () && args(1).is_scalar_type ()) |
11209
94d9d412a2a0
improve Matlab compatibility of rem and mod
John W. Eaton <jwe@octave.org>
parents:
10983
diff
changeset
|
670 retval = xrem (args(0).float_value (), args(1).float_value ()); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
671 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
672 { |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
673 FloatNDArray a0 = args(0).float_array_value (); |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
674 FloatNDArray a1 = args(1).float_array_value (); |
13731
3b52038e6e6c
Help dumb compilers to resolve template parameters.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13294
diff
changeset
|
675 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
|
676 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
677 } |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
678 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
679 { |
18978
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
680 if (args(0).is_scalar_type () && args(1).is_scalar_type ()) |
11209
94d9d412a2a0
improve Matlab compatibility of rem and mod
John W. Eaton <jwe@octave.org>
parents:
10983
diff
changeset
|
681 retval = xrem (args(0).scalar_value (), args(1).scalar_value ()); |
18978
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
682 else if (args(0).is_sparse_type () || args(1).is_sparse_type ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
683 { |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
684 SparseMatrix m0 = args(0).sparse_matrix_value (); |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
685 SparseMatrix m1 = args(1).sparse_matrix_value (); |
13731
3b52038e6e6c
Help dumb compilers to resolve template parameters.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13294
diff
changeset
|
686 retval = binmap<double> (m0, m1, xrem<double>, "rem"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
687 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
688 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
689 { |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
690 NDArray a0 = args(0).array_value (); |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
691 NDArray a1 = args(1).array_value (); |
13731
3b52038e6e6c
Help dumb compilers to resolve template parameters.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13294
diff
changeset
|
692 retval = binmap<double> (a0, a1, xrem<double>, "rem"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
693 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
694 } |
4311 | 695 } |
696 else | |
5823 | 697 print_usage (); |
4311 | 698 |
699 return retval; | |
700 } | |
701 | |
7506
798b0a00e80c
atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents:
7505
diff
changeset
|
702 /* |
19310 | 703 %!assert (size (rem (zeros (0, 2), zeros (0, 2))), [0, 2]) |
704 %!assert (size (rem (rand (2, 3, 4), zeros (2, 3, 4))), [2, 3, 4]) | |
705 %!assert (size (rem (rand (2, 3, 4), 1)), [2, 3, 4]) | |
706 %!assert (size (rem (1, rand (2, 3, 4))), [2, 3, 4]) | |
707 %!assert (size (rem (1, 2)), [1, 1]) | |
18978
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
708 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
709 %!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
|
710 %!assert (rem ([1, 2, 3; -1, -2, -3], 2 * ones (2, 3)),[1, 0, 1; -1, 0, -1]) |
20584
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20442
diff
changeset
|
711 %!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
|
712 %!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
|
713 %!assert (uint8 (rem ([1, 2, 3; -1, -2, -3], 2 * ones (2, 3))),uint8 ([1, 0, 1; -1, 0, -1])) |
20584
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20442
diff
changeset
|
714 %!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
|
715 |
18978
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
716 ## Test sparse implementations |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
717 %!shared xs |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
718 %! xs = sparse (0:3); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
719 %!test |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
720 %! y = rem (11, xs); |
20584
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20442
diff
changeset
|
721 %! assert (isnan (y(1))); |
18978
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
722 %! assert (y, sparse (rem (11, 0:3))); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
723 %!test |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
724 %! y = rem (0, xs); |
20584
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20442
diff
changeset
|
725 %! assert (nnz (y), 1); |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20442
diff
changeset
|
726 %! assert (y, sparse ([NaN 0 0 0])); |
18978
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
727 %!test |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
728 %! y = rem (xs, 2); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
729 %! assert (nnz (y), 2); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
730 %! assert (y, sparse (rem (0:3, 2))); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
731 %!test |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
732 %! y = rem (xs, 1); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
733 %! assert (nnz (y), 0); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
734 %! assert (y, sparse (rem (0:3, 1))); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
735 %!test |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
736 %! 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:
18964
diff
changeset
|
737 %! assert (nnz (y), 3); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
738 %! assert (y, sparse (rem (11, 0:3))); |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
739 %!test |
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
740 %! y = rem (sparse ([0 0 0 0]), xs); |
20584
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20442
diff
changeset
|
741 %! assert (nnz (y), 1); |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20442
diff
changeset
|
742 %! assert (y, sparse ([NaN 0 0 0])); |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20442
diff
changeset
|
743 |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20442
diff
changeset
|
744 ## Bug #45587 |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20442
diff
changeset
|
745 %!assert (signbit (rem (-0, 1))) |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20442
diff
changeset
|
746 %!assert (! signbit (rem (0, 1))) |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20442
diff
changeset
|
747 |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20442
diff
changeset
|
748 ## bug #42627 |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20442
diff
changeset
|
749 %!assert (rem (0.94, 0.01), 0.0) |
18978
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
750 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
751 %!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
|
752 %!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
|
753 %!error rem () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
754 %!error rem (1, 2, 3) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
755 %!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
|
756 %!error rem (i, 1) |
7506
798b0a00e80c
atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents:
7505
diff
changeset
|
757 */ |
798b0a00e80c
atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents:
7505
diff
changeset
|
758 |
10436
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
759 DEFUN (mod, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
760 "-*- texinfo -*-\n\ |
10436
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
761 @deftypefn {Mapping Function} {} mod (@var{x}, @var{y})\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
762 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:
20068
diff
changeset
|
763 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
764 Conceptually this is given by\n\ |
10436
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
765 \n\ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
766 @example\n\ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
767 x - y .* floor (x ./ y)\n\ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
768 @end example\n\ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
769 \n\ |
10846
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10840
diff
changeset
|
770 @noindent\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
771 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:
20068
diff
changeset
|
772 This function handles negative values correctly. That is,\n\ |
20584
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20442
diff
changeset
|
773 @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
|
774 \n\ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
775 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
|
776 either of the arguments is complex.\n\ |
20584
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20442
diff
changeset
|
777 \n\ |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20442
diff
changeset
|
778 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:
20442
diff
changeset
|
779 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:
20442
diff
changeset
|
780 @sc{matlab}.\n\ |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20442
diff
changeset
|
781 \n\ |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20442
diff
changeset
|
782 By convention,\n\ |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20442
diff
changeset
|
783 \n\ |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20442
diff
changeset
|
784 @example\n\ |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20442
diff
changeset
|
785 @group\n\ |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20442
diff
changeset
|
786 mod (@var{x}, 0) = @var{x}\n\ |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20442
diff
changeset
|
787 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:
20442
diff
changeset
|
788 @end group\n\ |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20442
diff
changeset
|
789 @end example\n\ |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20442
diff
changeset
|
790 \n\ |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20442
diff
changeset
|
791 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:
20442
diff
changeset
|
792 @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:
20442
diff
changeset
|
793 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
|
794 @seealso{rem}\n\ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
795 @end deftypefn") |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
796 { |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
797 octave_value retval; |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
798 |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
799 int nargin = args.length (); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
800 |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
801 if (nargin == 2) |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
802 { |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
803 if (! args(0).is_numeric_type ()) |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
804 gripe_wrong_type_arg ("mod", args(0)); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
805 else if (! args(1).is_numeric_type ()) |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
806 gripe_wrong_type_arg ("mod", args(1)); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
807 else if (args(0).is_complex_type () || args(1).is_complex_type ()) |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
808 error ("mod: not defined for complex numbers"); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
809 else if (args(0).is_integer_type () || args(1).is_integer_type ()) |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
810 { |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
811 builtin_type_t btyp0 = args(0).builtin_type (); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
812 builtin_type_t btyp1 = args(1).builtin_type (); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
813 if (btyp0 == btyp_double || btyp0 == btyp_float) |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
814 btyp0 = btyp1; |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
815 if (btyp1 == btyp_double || btyp1 == btyp_float) |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
816 btyp1 = btyp0; |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
817 |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
818 if (btyp0 == btyp1) |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
819 { |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
820 switch (btyp0) |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
821 { |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
822 #define MAKE_INT_BRANCH(X) \ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
823 case btyp_ ## X: \ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
824 { \ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
825 X##NDArray a0 = args(0).X##_array_value (); \ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
826 X##NDArray a1 = args(1).X##_array_value (); \ |
10682
7b4ffe27bbb4
Specify template arguments explicitely [MSVC].
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10538
diff
changeset
|
827 retval = binmap<octave_##X,octave_##X,octave_##X> (a0, a1, mod, "mod"); \ |
10436
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
828 } \ |
18891
5baada25d5a2
Rewrite docstring of sum() to match prod().
Rik <rik@octave.org>
parents:
18890
diff
changeset
|
829 break; |
10436
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
830 MAKE_INT_BRANCH (int8); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
831 MAKE_INT_BRANCH (int16); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
832 MAKE_INT_BRANCH (int32); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
833 MAKE_INT_BRANCH (int64); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
834 MAKE_INT_BRANCH (uint8); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
835 MAKE_INT_BRANCH (uint16); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
836 MAKE_INT_BRANCH (uint32); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
837 MAKE_INT_BRANCH (uint64); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
838 #undef MAKE_INT_BRANCH |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
839 default: |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
840 panic_impossible (); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
841 } |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
842 } |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
843 else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
844 error ("mod: cannot combine %s and %d", |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
845 args(0).class_name ().c_str (), |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
846 args(1).class_name ().c_str ()); |
10436
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
847 } |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
848 else if (args(0).is_single_type () || args(1).is_single_type ()) |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
849 { |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
850 if (args(0).is_scalar_type () && args(1).is_scalar_type ()) |
11209
94d9d412a2a0
improve Matlab compatibility of rem and mod
John W. Eaton <jwe@octave.org>
parents:
10983
diff
changeset
|
851 retval = xmod (args(0).float_value (), args(1).float_value ()); |
10436
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
852 else |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
853 { |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
854 FloatNDArray a0 = args(0).float_array_value (); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
855 FloatNDArray a1 = args(1).float_array_value (); |
13731
3b52038e6e6c
Help dumb compilers to resolve template parameters.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13294
diff
changeset
|
856 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
|
857 } |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
858 } |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
859 else |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
860 { |
18978
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
861 if (args(0).is_scalar_type () && args(1).is_scalar_type ()) |
11209
94d9d412a2a0
improve Matlab compatibility of rem and mod
John W. Eaton <jwe@octave.org>
parents:
10983
diff
changeset
|
862 retval = xmod (args(0).scalar_value (), args(1).scalar_value ()); |
18978
dccbc8bff5cb
Fix binmap for sparse-scalar or scalar-sparse operations (bug #40813).
Rik <rik@octave.org>
parents:
18964
diff
changeset
|
863 else if (args(0).is_sparse_type () || args(1).is_sparse_type ()) |
10436
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
864 { |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
865 SparseMatrix m0 = args(0).sparse_matrix_value (); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
866 SparseMatrix m1 = args(1).sparse_matrix_value (); |
13731
3b52038e6e6c
Help dumb compilers to resolve template parameters.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13294
diff
changeset
|
867 retval = binmap<double> (m0, m1, xmod<double>, "mod"); |
10436
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
868 } |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
869 else |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
870 { |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
871 NDArray a0 = args(0).array_value (); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
872 NDArray a1 = args(1).array_value (); |
13731
3b52038e6e6c
Help dumb compilers to resolve template parameters.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13294
diff
changeset
|
873 retval = binmap<double> (a0, a1, xmod<double>, "mod"); |
10436
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
874 } |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
875 } |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
876 } |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
877 else |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
878 print_usage (); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
879 |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
880 return retval; |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
881 } |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
882 |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
883 /* |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
884 ## empty input test |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
885 %!assert (isempty (mod ([], []))) |
10436
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
886 |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
887 ## 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
|
888 %!assert (mod (5, 3), 2) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
889 %!assert (mod (-5, 3), 1) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
890 %!assert (mod (0, 3), 0) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
891 %!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
|
892 %!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
|
893 %!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
|
894 |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
895 ## x mod 0 tests |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
896 %!assert (mod (5, 0), 5) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
897 %!assert (mod (-5, 0), -5) |
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, 3]), [1, 5, 0]) |
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; 0; 3]), [1; 5; 0]) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
900 %!assert (mod ([-5, 5; 0, 3], [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
|
901 %!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
|
902 |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
903 ## mixed scalar/matrix tests |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
904 %!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
|
905 %!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
|
906 %!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
|
907 %!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
|
908 %!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
|
909 |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
910 ## integer 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), uint8 (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 (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
|
913 %!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
|
914 %!error (mod (uint8 (5), int8 (4))) |
10436
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
915 |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
916 ## mixed integer/real types |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
917 %!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
|
918 %!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
|
919 %!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
|
920 |
903c1a3df301
Add additional tests for mod with non-integer real values.
Rik <octave@nomad.inbox5.com>
parents:
11242
diff
changeset
|
921 ## non-integer real numbers |
903c1a3df301
Add additional tests for mod with non-integer real values.
Rik <octave@nomad.inbox5.com>
parents:
11242
diff
changeset
|
922 %!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
|
923 %!assert (mod (2.1, 0.2), 0.1, eps) |
19059
23681c9ea7ba
better guess if rem or mod could be zero (bug #42627)
Olaf Till <i7tiol@t-online.de>
parents:
19041
diff
changeset
|
924 |
20584
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20442
diff
changeset
|
925 ## Bug #45587 |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20442
diff
changeset
|
926 %!assert (signbit (mod (-0, 0))) |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20442
diff
changeset
|
927 %!assert (! signbit (mod (0, -0))) |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20442
diff
changeset
|
928 |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20442
diff
changeset
|
929 ## Bug #42627 |
0cefba1a1030
Make mod() and rem() Matlab compatible for corner cases (bug #45587).
Rik <rik@octave.org>
parents:
20442
diff
changeset
|
930 %!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
|
931 */ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
932 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
933 // 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
|
934 |
7112 | 935 #define NATIVE_REDUCTION_1(FCN, TYPE, DIM) \ |
936 (arg.is_ ## TYPE ## _type ()) \ | |
937 { \ | |
938 TYPE ## NDArray tmp = arg. TYPE ##_array_value (); \ | |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
939 \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
940 retval = tmp.FCN (DIM); \ |
7112 | 941 } |
942 | |
8780
ea76466605ba
support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents:
8756
diff
changeset
|
943 #define NATIVE_REDUCTION(FCN, BOOL_FCN) \ |
7112 | 944 \ |
945 octave_value retval; \ | |
946 \ | |
947 int nargin = args.length (); \ | |
948 \ | |
949 bool isnative = false; \ | |
7815
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
950 bool isdouble = false; \ |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
951 \ |
7112 | 952 if (nargin > 1 && args(nargin - 1).is_string ()) \ |
953 { \ | |
954 std::string str = args(nargin - 1).string_value (); \ | |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
955 \ |
19948
67f2c76f9f4d
Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents:
19944
diff
changeset
|
956 if (str == "native") \ |
67f2c76f9f4d
Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents:
19944
diff
changeset
|
957 isnative = true; \ |
67f2c76f9f4d
Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents:
19944
diff
changeset
|
958 else if (str == "double") \ |
67f2c76f9f4d
Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents:
19944
diff
changeset
|
959 isdouble = true; \ |
67f2c76f9f4d
Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents:
19944
diff
changeset
|
960 else \ |
67f2c76f9f4d
Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents:
19944
diff
changeset
|
961 error ("sum: unrecognized string argument"); \ |
67f2c76f9f4d
Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents:
19944
diff
changeset
|
962 nargin --; \ |
7112 | 963 } \ |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
964 \ |
7112 | 965 if (nargin == 1 || nargin == 2) \ |
966 { \ | |
967 octave_value arg = args(0); \ | |
968 \ | |
969 int dim = (nargin == 1 ? -1 : args(1).int_value (true) - 1); \ | |
970 \ | |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
971 if (dim >= -1) \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
972 { \ |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
973 if (arg.is_sparse_type ()) \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
974 { \ |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
975 if (arg.is_real_type ()) \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
976 { \ |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
977 SparseMatrix tmp = arg.sparse_matrix_value (); \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
978 \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
979 retval = tmp.FCN (dim); \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
980 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
981 else \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
982 { \ |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
983 SparseComplexMatrix tmp \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
984 = arg.sparse_complex_matrix_value (); \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
985 \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
986 retval = tmp.FCN (dim); \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
987 } \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
988 } \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
989 else \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
990 { \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
991 if (isnative) \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
992 { \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
993 if NATIVE_REDUCTION_1 (FCN, uint8, dim) \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
994 else if NATIVE_REDUCTION_1 (FCN, uint16, dim) \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
995 else if NATIVE_REDUCTION_1 (FCN, uint32, dim) \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
996 else if NATIVE_REDUCTION_1 (FCN, uint64, dim) \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
997 else if NATIVE_REDUCTION_1 (FCN, int8, dim) \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
998 else if NATIVE_REDUCTION_1 (FCN, int16, dim) \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
999 else if NATIVE_REDUCTION_1 (FCN, int32, dim) \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1000 else if NATIVE_REDUCTION_1 (FCN, int64, dim) \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1001 else if (arg.is_bool_type ()) \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1002 { \ |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1003 boolNDArray tmp = arg.bool_array_value (); \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1004 \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1005 retval = boolNDArray (tmp.BOOL_FCN (dim)); \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1006 } \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1007 else if (arg.is_char_matrix ()) \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1008 { \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1009 error (#FCN, ": invalid char type"); \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1010 } \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1011 else if (!isdouble && arg.is_single_type ()) \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1012 { \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1013 if (arg.is_complex_type ()) \ |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7743
diff
changeset
|
1014 { \ |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1015 FloatComplexNDArray tmp = \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1016 arg.float_complex_array_value (); \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1017 \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1018 retval = tmp.FCN (dim); \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1019 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1020 else if (arg.is_real_type ()) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1021 { \ |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1022 FloatNDArray tmp = arg.float_array_value (); \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1023 \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1024 retval = tmp.FCN (dim); \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1025 } \ |
7112 | 1026 } \ |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1027 else if (arg.is_complex_type ()) \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1028 { \ |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1029 ComplexNDArray tmp = arg.complex_array_value (); \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1030 \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1031 retval = tmp.FCN (dim); \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1032 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1033 else if (arg.is_real_type ()) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1034 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1035 NDArray tmp = arg.array_value (); \ |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1036 \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1037 retval = tmp.FCN (dim); \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1038 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1039 else \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1040 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1041 gripe_wrong_type_arg (#FCN, arg); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1042 return retval; \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1043 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1044 } \ |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1045 else if (arg.is_bool_type ()) \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1046 { \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1047 boolNDArray tmp = arg.bool_array_value (); \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1048 \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1049 retval = tmp.FCN (dim); \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1050 } \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1051 else if (!isdouble && arg.is_single_type ()) \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1052 { \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1053 if (arg.is_real_type ()) \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1054 { \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1055 FloatNDArray tmp = arg.float_array_value (); \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1056 \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1057 retval = tmp.FCN (dim); \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1058 } \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1059 else if (arg.is_complex_type ()) \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1060 { \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1061 FloatComplexNDArray tmp = \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1062 arg.float_complex_array_value (); \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1063 \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1064 retval = tmp.FCN (dim); \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1065 } \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1066 } \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1067 else if (arg.is_real_type ()) \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1068 { \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1069 NDArray tmp = arg.array_value (); \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1070 \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1071 retval = tmp.FCN (dim); \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1072 } \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1073 else if (arg.is_complex_type ()) \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1074 { \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1075 ComplexNDArray tmp = arg.complex_array_value (); \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1076 \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1077 retval = tmp.FCN (dim); \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1078 } \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1079 else \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1080 { \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1081 gripe_wrong_type_arg (#FCN, arg); \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1082 return retval; \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1083 } \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1084 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1085 else \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1086 error (#FCN ": invalid dimension argument = %d", dim + 1); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1087 } \ |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1088 \ |
7112 | 1089 } \ |
1090 else \ | |
1091 print_usage (); \ | |
1092 \ | |
1093 return retval | |
1094 | |
3723 | 1095 #define DATA_REDUCTION(FCN) \ |
1096 \ | |
4233 | 1097 octave_value retval; \ |
3723 | 1098 \ |
1099 int nargin = args.length (); \ | |
1100 \ | |
1101 if (nargin == 1 || nargin == 2) \ | |
1102 { \ | |
1103 octave_value arg = args(0); \ | |
1104 \ | |
3864 | 1105 int dim = (nargin == 1 ? -1 : args(1).int_value (true) - 1); \ |
3723 | 1106 \ |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1107 if (dim >= -1) \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1108 { \ |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1109 if (arg.is_real_type ()) \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1110 { \ |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1111 if (arg.is_sparse_type ()) \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1112 { \ |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1113 SparseMatrix tmp = arg.sparse_matrix_value (); \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1114 \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1115 retval = tmp.FCN (dim); \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1116 } \ |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1117 else if (arg.is_single_type ()) \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1118 { \ |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1119 FloatNDArray tmp = arg.float_array_value (); \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1120 \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1121 retval = tmp.FCN (dim); \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1122 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1123 else \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1124 { \ |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1125 NDArray tmp = arg.array_value (); \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1126 \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1127 retval = tmp.FCN (dim); \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1128 } \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1129 } \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1130 else if (arg.is_complex_type ()) \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1131 { \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1132 if (arg.is_sparse_type ()) \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1133 { \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1134 SparseComplexMatrix tmp = arg.sparse_complex_matrix_value (); \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1135 \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1136 retval = tmp.FCN (dim); \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1137 } \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1138 else if (arg.is_single_type ()) \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1139 { \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1140 FloatComplexNDArray tmp \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1141 = arg.float_complex_array_value (); \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1142 \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1143 retval = tmp.FCN (dim); \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1144 } \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1145 else \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1146 { \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1147 ComplexNDArray tmp = arg.complex_array_value (); \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1148 \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1149 retval = tmp.FCN (dim); \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1150 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1151 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1152 else \ |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1153 { \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1154 gripe_wrong_type_arg (#FCN, arg); \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1155 return retval; \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1156 } \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1157 } \ |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1158 else \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1159 error (#FCN ": invalid dimension argument = %d", dim + 1); \ |
3723 | 1160 } \ |
1161 else \ | |
5823 | 1162 print_usage (); \ |
3723 | 1163 \ |
1164 return retval | |
1165 | |
1957 | 1166 DEFUN (cumprod, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1167 "-*- texinfo -*-\n\ |
9163
9cb0c21e97f7
Update section 17.4 (Sums and Products) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9155
diff
changeset
|
1168 @deftypefn {Built-in Function} {} cumprod (@var{x})\n\ |
9cb0c21e97f7
Update section 17.4 (Sums and Products) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9155
diff
changeset
|
1169 @deftypefnx {Built-in Function} {} cumprod (@var{x}, @var{dim})\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
1170 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:
20068
diff
changeset
|
1171 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
1172 If @var{dim} is omitted, it defaults to the first non-singleton dimension.\n\ |
9163
9cb0c21e97f7
Update section 17.4 (Sums and Products) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9155
diff
changeset
|
1173 @seealso{prod, cumsum}\n\ |
3428 | 1174 @end deftypefn") |
523 | 1175 { |
3723 | 1176 DATA_REDUCTION (cumprod); |
523 | 1177 } |
1178 | |
7815
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1179 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1180 %!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
|
1181 %!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
|
1182 %!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
|
1183 %!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
|
1184 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1185 %!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
|
1186 %!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
|
1187 %!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
|
1188 %!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
|
1189 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1190 %!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
|
1191 %!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
|
1192 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1193 %!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
|
1194 %!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
|
1195 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1196 %!error cumprod () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1197 */ |
7815
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1198 |
1957 | 1199 DEFUN (cumsum, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1200 "-*- texinfo -*-\n\ |
9163
9cb0c21e97f7
Update section 17.4 (Sums and Products) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9155
diff
changeset
|
1201 @deftypefn {Built-in Function} {} cumsum (@var{x})\n\ |
9cb0c21e97f7
Update section 17.4 (Sums and Products) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9155
diff
changeset
|
1202 @deftypefnx {Built-in Function} {} cumsum (@var{x}, @var{dim})\n\ |
14361
8de863b7126b
doc: Use Octave preference for double quote in docstrings in all .cc files
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
1203 @deftypefnx {Built-in Function} {} cumsum (@dots{}, \"native\")\n\ |
8de863b7126b
doc: Use Octave preference for double quote in docstrings in all .cc files
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
1204 @deftypefnx {Built-in Function} {} cumsum (@dots{}, \"double\")\n\ |
8de863b7126b
doc: Use Octave preference for double quote in docstrings in all .cc files
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
1205 @deftypefnx {Built-in Function} {} cumsum (@dots{}, \"extra\")\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
1206 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:
20068
diff
changeset
|
1207 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
1208 If @var{dim} is omitted, it defaults to the first non-singleton dimension.\n\ |
8780
ea76466605ba
support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents:
8756
diff
changeset
|
1209 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17268
diff
changeset
|
1210 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
|
1211 @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
|
1212 @seealso{sum, cumprod}\n\ |
3428 | 1213 @end deftypefn") |
523 | 1214 { |
9721
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1215 octave_value retval; |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1216 |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1217 int nargin = args.length (); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1218 |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1219 bool isnative = false; |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1220 bool isdouble = false; |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1221 |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1222 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
|
1223 { |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1224 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
|
1225 |
19948
67f2c76f9f4d
Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents:
19944
diff
changeset
|
1226 if (str == "native") |
67f2c76f9f4d
Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents:
19944
diff
changeset
|
1227 isnative = true; |
67f2c76f9f4d
Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents:
19944
diff
changeset
|
1228 else if (str == "double") |
67f2c76f9f4d
Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents:
19944
diff
changeset
|
1229 isdouble = true; |
67f2c76f9f4d
Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents:
19944
diff
changeset
|
1230 else |
67f2c76f9f4d
Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents:
19944
diff
changeset
|
1231 error ("cumsum: unrecognized string argument"); |
67f2c76f9f4d
Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents:
19944
diff
changeset
|
1232 nargin --; |
9721
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1233 } |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1234 |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1235 if (nargin == 1 || nargin == 2) |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1236 { |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1237 octave_value arg = args(0); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1238 |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1239 int dim = -1; |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1240 if (nargin == 2) |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1241 { |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1242 dim = args(1).int_value () - 1; |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1243 if (dim < 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1244 error ("cumsum: invalid dimension argument = %d", dim + 1); |
9721
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1245 } |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1246 |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1247 switch (arg.builtin_type ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1248 { |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1249 case btyp_double: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1250 if (arg.is_sparse_type ()) |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1251 retval = arg.sparse_matrix_value ().cumsum (dim); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1252 else |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1253 retval = arg.array_value ().cumsum (dim); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1254 break; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1255 case btyp_complex: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1256 if (arg.is_sparse_type ()) |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1257 retval = arg.sparse_complex_matrix_value ().cumsum (dim); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1258 else |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1259 retval = arg.complex_array_value ().cumsum (dim); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1260 break; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1261 case btyp_float: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1262 if (isdouble) |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1263 retval = arg.array_value ().cumsum (dim); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1264 else |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1265 retval = arg.float_array_value ().cumsum (dim); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1266 break; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1267 case btyp_float_complex: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1268 if (isdouble) |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1269 retval = arg.complex_array_value ().cumsum (dim); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1270 else |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1271 retval = arg.float_complex_array_value ().cumsum (dim); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1272 break; |
9721
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1273 |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1274 #define MAKE_INT_BRANCH(X) \ |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1275 case btyp_ ## X: \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1276 if (isnative) \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1277 retval = arg.X ## _array_value ().cumsum (dim); \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1278 else \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1279 retval = arg.array_value ().cumsum (dim); \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1280 break; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1281 MAKE_INT_BRANCH (int8); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1282 MAKE_INT_BRANCH (int16); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1283 MAKE_INT_BRANCH (int32); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1284 MAKE_INT_BRANCH (int64); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1285 MAKE_INT_BRANCH (uint8); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1286 MAKE_INT_BRANCH (uint16); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1287 MAKE_INT_BRANCH (uint32); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1288 MAKE_INT_BRANCH (uint64); |
9721
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1289 #undef MAKE_INT_BRANCH |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1290 |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1291 case btyp_bool: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1292 if (arg.is_sparse_type ()) |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1293 { |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1294 SparseMatrix cs = arg.sparse_matrix_value ().cumsum (dim); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1295 if (isnative) |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1296 retval = cs != 0.0; |
9721
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1297 else |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1298 retval = cs; |
9721
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1299 } |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1300 else |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1301 { |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1302 NDArray cs = arg.bool_array_value ().cumsum (dim); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1303 if (isnative) |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1304 retval = cs != 0.0; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1305 else |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1306 retval = cs; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1307 } |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1308 break; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1309 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1310 default: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1311 gripe_wrong_type_arg ("cumsum", arg); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1312 } |
9721
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1313 } |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1314 else |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1315 print_usage (); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1316 |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1317 return retval; |
523 | 1318 } |
1319 | |
7815
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1320 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1321 %!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
|
1322 %!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
|
1323 %!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
|
1324 %!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
|
1325 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1326 %!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
|
1327 %!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
|
1328 %!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
|
1329 %!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
|
1330 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1331 %!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
|
1332 %!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
|
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, 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
|
1335 %!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
|
1336 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1337 %!error cumsum () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1338 */ |
7815
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1339 |
1957 | 1340 DEFUN (diag, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1341 "-*- texinfo -*-\n\ |
12567
cc8ccdfec424
Remove archaic 3-input argument form of diag function.
Rik <octave@nomad.inbox5.com>
parents:
12546
diff
changeset
|
1342 @deftypefn {Built-in Function} {@var{M} =} diag (@var{v})\n\ |
cc8ccdfec424
Remove archaic 3-input argument form of diag function.
Rik <octave@nomad.inbox5.com>
parents:
12546
diff
changeset
|
1343 @deftypefnx {Built-in Function} {@var{M} =} diag (@var{v}, @var{k})\n\ |
12571
bed932910eb9
Add documentation for 3-input form of diag(). Add new tests.
Rik <octave@nomad.inbox5.com>
parents:
12570
diff
changeset
|
1344 @deftypefnx {Built-in Function} {@var{M} =} diag (@var{v}, @var{m}, @var{n})\n\ |
12567
cc8ccdfec424
Remove archaic 3-input argument form of diag function.
Rik <octave@nomad.inbox5.com>
parents:
12546
diff
changeset
|
1345 @deftypefnx {Built-in Function} {@var{v} =} diag (@var{M})\n\ |
cc8ccdfec424
Remove archaic 3-input argument form of diag function.
Rik <octave@nomad.inbox5.com>
parents:
12546
diff
changeset
|
1346 @deftypefnx {Built-in Function} {@var{v} =} diag (@var{M}, @var{k})\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
1347 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:
20068
diff
changeset
|
1348 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
1349 The second argument is optional. If it is positive, the vector is placed on\n\ |
19230
9e3c35d934ab
doc: Periodic spell check of documentation.
Rik <rik@octave.org>
parents:
19063
diff
changeset
|
1350 the @var{k}-th superdiagonal. If it is negative, it is placed on the\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
1351 @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:
20068
diff
changeset
|
1352 is placed on the main diagonal. For example:\n\ |
3369 | 1353 \n\ |
1354 @example\n\ | |
1355 @group\n\ | |
1356 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
|
1357 @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
|
1358 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
|
1359 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
|
1360 0 0 0 0\n\ |
3369 | 1361 @end group\n\ |
1362 @end example\n\ | |
6772 | 1363 \n\ |
1364 @noindent\n\ | |
12571
bed932910eb9
Add documentation for 3-input form of diag(). Add new tests.
Rik <octave@nomad.inbox5.com>
parents:
12570
diff
changeset
|
1365 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
|
1366 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
|
1367 columns.\n\ |
bed932910eb9
Add documentation for 3-input form of diag(). Add new tests.
Rik <octave@nomad.inbox5.com>
parents:
12570
diff
changeset
|
1368 \n\ |
6772 | 1369 Given a matrix argument, instead of a vector, @code{diag} extracts the\n\ |
6774 | 1370 @var{k}-th diagonal of the matrix.\n\ |
3369 | 1371 @end deftypefn") |
523 | 1372 { |
4233 | 1373 octave_value retval; |
523 | 1374 |
1375 int nargin = args.length (); | |
1376 | |
712 | 1377 if (nargin == 1 && args(0).is_defined ()) |
14843
7d4f87c75dbb
data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents:
14635
diff
changeset
|
1378 retval = args(0).diag (); |
712 | 1379 else if (nargin == 2 && args(0).is_defined () && args(1).is_defined ()) |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7618
diff
changeset
|
1380 { |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7618
diff
changeset
|
1381 octave_idx_type k = args(1).int_value (); |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7618
diff
changeset
|
1382 |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7618
diff
changeset
|
1383 if (error_state) |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11591
diff
changeset
|
1384 error ("diag: invalid argument K"); |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7618
diff
changeset
|
1385 else |
14843
7d4f87c75dbb
data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents:
14635
diff
changeset
|
1386 retval = args(0).diag (k); |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7618
diff
changeset
|
1387 } |
12570
1a93988610a3
Reverse changset cc8ccdfec424. Restore 3-input form of diag().
Rik <octave@nomad.inbox5.com>
parents:
12567
diff
changeset
|
1388 else if (nargin == 3) |
1a93988610a3
Reverse changset cc8ccdfec424. Restore 3-input form of diag().
Rik <octave@nomad.inbox5.com>
parents:
12567
diff
changeset
|
1389 { |
1a93988610a3
Reverse changset cc8ccdfec424. Restore 3-input form of diag().
Rik <octave@nomad.inbox5.com>
parents:
12567
diff
changeset
|
1390 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
|
1391 |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14521
diff
changeset
|
1392 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
|
1393 { |
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
|
1394 octave_idx_type m = args(1).int_value (); |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14521
diff
changeset
|
1395 octave_idx_type n = args(2).int_value (); |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14521
diff
changeset
|
1396 |
12570
1a93988610a3
Reverse changset cc8ccdfec424. Restore 3-input form of diag().
Rik <octave@nomad.inbox5.com>
parents:
12567
diff
changeset
|
1397 if (! error_state) |
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
|
1398 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
|
1399 else |
1a93988610a3
Reverse changset cc8ccdfec424. Restore 3-input form of diag().
Rik <octave@nomad.inbox5.com>
parents:
12567
diff
changeset
|
1400 error ("diag: invalid dimensions"); |
1a93988610a3
Reverse changset cc8ccdfec424. Restore 3-input form of diag().
Rik <octave@nomad.inbox5.com>
parents:
12567
diff
changeset
|
1401 } |
1a93988610a3
Reverse changset cc8ccdfec424. Restore 3-input form of diag().
Rik <octave@nomad.inbox5.com>
parents:
12567
diff
changeset
|
1402 else |
1a93988610a3
Reverse changset cc8ccdfec424. Restore 3-input form of diag().
Rik <octave@nomad.inbox5.com>
parents:
12567
diff
changeset
|
1403 error ("diag: V must be a vector"); |
1a93988610a3
Reverse changset cc8ccdfec424. Restore 3-input form of diag().
Rik <octave@nomad.inbox5.com>
parents:
12567
diff
changeset
|
1404 } |
523 | 1405 else |
5823 | 1406 print_usage (); |
523 | 1407 |
1408 return retval; | |
1409 } | |
1410 | |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1411 /* |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1412 |
14843
7d4f87c75dbb
data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents:
14635
diff
changeset
|
1413 %!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
|
1414 %!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
|
1415 %!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
|
1416 %!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
|
1417 %!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
|
1418 |
7d4f87c75dbb
data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents:
14635
diff
changeset
|
1419 %!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
|
1420 %!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
|
1421 %!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
|
1422 %!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
|
1423 %!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
|
1424 |
7d4f87c75dbb
data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents:
14635
diff
changeset
|
1425 %!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
|
1426 %!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
|
1427 %!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
|
1428 %!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
|
1429 %!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
|
1430 |
7d4f87c75dbb
data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents:
14635
diff
changeset
|
1431 %!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
|
1432 %!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
|
1433 %!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
|
1434 |
7d4f87c75dbb
data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents:
14635
diff
changeset
|
1435 %!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
|
1436 %!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
|
1437 %!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
|
1438 %!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
|
1439 %!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
|
1440 |
7d4f87c75dbb
data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents:
14635
diff
changeset
|
1441 %!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
|
1442 %!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
|
1443 %!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
|
1444 |
15428
fd5c0159b588
Fix diag handling of diagvectors (bug #37411)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14567
diff
changeset
|
1445 ## bug #37411 |
fd5c0159b588
Fix diag handling of diagvectors (bug #37411)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14567
diff
changeset
|
1446 %!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
|
1447 %!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
|
1448 %!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
|
1449 |
14490
3959f3f81e33
Initialise memory in non-square diag call (bug #35946)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14171
diff
changeset
|
1450 ## 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
|
1451 %!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
|
1452 %!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
|
1453 %!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
|
1454 %!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
|
1455 |
18145
a86d608c413c
Return empty matrix rather than issuing error when requested diagonal is out of range.
Marco Caliari <marco.caliari@univr.it>
parents:
18111
diff
changeset
|
1456 ## 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:
18111
diff
changeset
|
1457 %!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:
18111
diff
changeset
|
1458 %!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:
18111
diff
changeset
|
1459 %!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:
18111
diff
changeset
|
1460 |
12571
bed932910eb9
Add documentation for 3-input form of diag(). Add new tests.
Rik <octave@nomad.inbox5.com>
parents:
12570
diff
changeset
|
1461 %% Test input validation |
14491
5bd9e47e9277
maint: periodic merge of stable to default
Jordi Gutiérrez Hermoso <jordigh@octave.org>
diff
changeset
|
1462 %!error <Invalid call to diag> diag () |
5bd9e47e9277
maint: periodic merge of stable to default
Jordi Gutiérrez Hermoso <jordigh@octave.org>
diff
changeset
|
1463 %!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
|
1464 %!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
|
1465 %!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
|
1466 |
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
|
1467 %!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
|
1468 %!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
|
1469 %!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
|
1470 %!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
|
1471 %!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
|
1472 %!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
|
1473 %!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
|
1474 %!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
|
1475 */ |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1476 |
1957 | 1477 DEFUN (prod, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1478 "-*- texinfo -*-\n\ |
9163
9cb0c21e97f7
Update section 17.4 (Sums and Products) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9155
diff
changeset
|
1479 @deftypefn {Built-in Function} {} prod (@var{x})\n\ |
9cb0c21e97f7
Update section 17.4 (Sums and Products) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9155
diff
changeset
|
1480 @deftypefnx {Built-in Function} {} prod (@var{x}, @var{dim})\n\ |
18890
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18834
diff
changeset
|
1481 @deftypefnx {Built-in Function} {} prod (@dots{}, \"native\")\n\ |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18834
diff
changeset
|
1482 @deftypefnx {Built-in Function} {} prod (@dots{}, \"double\")\n\ |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18834
diff
changeset
|
1483 Product of elements along dimension @var{dim}.\n\ |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18834
diff
changeset
|
1484 \n\ |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18834
diff
changeset
|
1485 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:
18834
diff
changeset
|
1486 \n\ |
19007
9ac2357f19bc
doc: Replace "non-zero" with "nonzero" to match existing usage.
Rik <rik@octave.org>
parents:
19006
diff
changeset
|
1487 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:
19006
diff
changeset
|
1488 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:
19006
diff
changeset
|
1489 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:
19006
diff
changeset
|
1490 than the default double type.\n\ |
18890
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18834
diff
changeset
|
1491 \n\ |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18834
diff
changeset
|
1492 For example:\n\ |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18834
diff
changeset
|
1493 \n\ |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18834
diff
changeset
|
1494 @example\n\ |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18834
diff
changeset
|
1495 @group\n\ |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18834
diff
changeset
|
1496 prod ([true, true])\n\ |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18834
diff
changeset
|
1497 @result{} 1\n\ |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18834
diff
changeset
|
1498 prod ([true, true], \"native\")\n\ |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18834
diff
changeset
|
1499 @result{} true\n\ |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18834
diff
changeset
|
1500 @end group\n\ |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18834
diff
changeset
|
1501 @end example\n\ |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18834
diff
changeset
|
1502 \n\ |
19007
9ac2357f19bc
doc: Replace "non-zero" with "nonzero" to match existing usage.
Rik <rik@octave.org>
parents:
19006
diff
changeset
|
1503 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:
19006
diff
changeset
|
1504 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
|
1505 @seealso{cumprod, sum}\n\ |
3428 | 1506 @end deftypefn") |
523 | 1507 { |
18890
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18834
diff
changeset
|
1508 octave_value retval; |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18834
diff
changeset
|
1509 |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18834
diff
changeset
|
1510 int nargin = args.length (); |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18834
diff
changeset
|
1511 |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18834
diff
changeset
|
1512 bool isnative = false; |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18834
diff
changeset
|
1513 bool isdouble = false; |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18834
diff
changeset
|
1514 |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18834
diff
changeset
|
1515 if (nargin > 1 && args(nargin - 1).is_string ()) |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18834
diff
changeset
|
1516 { |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18834
diff
changeset
|
1517 std::string str = args(nargin - 1).string_value (); |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18834
diff
changeset
|
1518 |
19948
67f2c76f9f4d
Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents:
19944
diff
changeset
|
1519 if (str == "native") |
67f2c76f9f4d
Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents:
19944
diff
changeset
|
1520 isnative = true; |
67f2c76f9f4d
Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents:
19944
diff
changeset
|
1521 else if (str == "double") |
67f2c76f9f4d
Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents:
19944
diff
changeset
|
1522 isdouble = true; |
67f2c76f9f4d
Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents:
19944
diff
changeset
|
1523 else |
67f2c76f9f4d
Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents:
19944
diff
changeset
|
1524 error ("prod: unrecognized type argument '%s'", str.c_str ()); |
67f2c76f9f4d
Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents:
19944
diff
changeset
|
1525 nargin --; |
18890
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18834
diff
changeset
|
1526 } |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18834
diff
changeset
|
1527 |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18834
diff
changeset
|
1528 if (nargin == 1 || nargin == 2) |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18834
diff
changeset
|
1529 { |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18834
diff
changeset
|
1530 octave_value arg = args(0); |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18834
diff
changeset
|
1531 |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18834
diff
changeset
|
1532 int dim = -1; |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18834
diff
changeset
|
1533 if (nargin == 2) |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18834
diff
changeset
|
1534 { |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18834
diff
changeset
|
1535 dim = args(1).int_value () - 1; |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18834
diff
changeset
|
1536 if (dim < 0) |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18834
diff
changeset
|
1537 error ("prod: invalid dimension DIM = %d", dim + 1); |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18834
diff
changeset
|
1538 } |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18834
diff
changeset
|
1539 |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1540 switch (arg.builtin_type ()) |
18890
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18834
diff
changeset
|
1541 { |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1542 case btyp_double: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1543 if (arg.is_sparse_type ()) |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1544 retval = arg.sparse_matrix_value ().prod (dim); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1545 else |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1546 retval = arg.array_value ().prod (dim); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1547 break; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1548 case btyp_complex: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1549 if (arg.is_sparse_type ()) |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1550 retval = arg.sparse_complex_matrix_value ().prod (dim); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1551 else |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1552 retval = arg.complex_array_value ().prod (dim); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1553 break; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1554 case btyp_float: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1555 if (isdouble) |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1556 retval = arg.float_array_value ().dprod (dim); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1557 else |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1558 retval = arg.float_array_value ().prod (dim); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1559 break; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1560 case btyp_float_complex: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1561 if (isdouble) |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1562 retval = arg.float_complex_array_value ().dprod (dim); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1563 else |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1564 retval = arg.float_complex_array_value ().prod (dim); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1565 break; |
18890
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18834
diff
changeset
|
1566 |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18834
diff
changeset
|
1567 #define MAKE_INT_BRANCH(X) \ |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1568 case btyp_ ## X: \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1569 if (isnative) \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1570 retval = arg.X ## _array_value ().prod (dim); \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1571 else \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1572 retval = arg.array_value ().prod (dim); \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1573 break; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1574 MAKE_INT_BRANCH (int8); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1575 MAKE_INT_BRANCH (int16); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1576 MAKE_INT_BRANCH (int32); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1577 MAKE_INT_BRANCH (int64); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1578 MAKE_INT_BRANCH (uint8); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1579 MAKE_INT_BRANCH (uint16); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1580 MAKE_INT_BRANCH (uint32); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1581 MAKE_INT_BRANCH (uint64); |
18890
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18834
diff
changeset
|
1582 #undef MAKE_INT_BRANCH |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18834
diff
changeset
|
1583 |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1584 // GAGME: Accursed Matlab compatibility... |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1585 case btyp_char: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1586 retval = arg.array_value (true).prod (dim); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1587 break; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1588 case btyp_bool: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1589 if (arg.is_sparse_type ()) |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1590 { |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1591 if (isnative) |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1592 retval = arg.sparse_bool_matrix_value ().all (dim); |
18890
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18834
diff
changeset
|
1593 else |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1594 retval = arg.sparse_matrix_value ().prod (dim); |
18890
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18834
diff
changeset
|
1595 } |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1596 else if (isnative) |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1597 retval = arg.bool_array_value ().all (dim); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1598 else |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1599 retval = NDArray (arg.bool_array_value ().all (dim)); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1600 break; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1601 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1602 default: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1603 gripe_wrong_type_arg ("prod", arg); |
18890
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18834
diff
changeset
|
1604 } |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18834
diff
changeset
|
1605 } |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18834
diff
changeset
|
1606 else |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18834
diff
changeset
|
1607 print_usage (); |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18834
diff
changeset
|
1608 |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18834
diff
changeset
|
1609 return retval; |
523 | 1610 } |
1611 | |
7815
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1612 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1613 %!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
|
1614 %!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
|
1615 %!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
|
1616 %!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
|
1617 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1618 %!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
|
1619 %!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
|
1620 %!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
|
1621 %!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
|
1622 |
18890
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18834
diff
changeset
|
1623 %% Test sparse |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18834
diff
changeset
|
1624 %!assert (prod (sparse ([1, 2, 3])), sparse (6)) |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18834
diff
changeset
|
1625 %!assert (prod (sparse ([-1; -2; -3])), sparse (-6)) |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18834
diff
changeset
|
1626 ## Commented out until bug #42290 is fixed |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18834
diff
changeset
|
1627 #%!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:
18834
diff
changeset
|
1628 #%!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:
18834
diff
changeset
|
1629 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1630 %!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
|
1631 %!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
|
1632 %!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
|
1633 %!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
|
1634 %!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
|
1635 %!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
|
1636 %!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
|
1637 %!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
|
1638 %!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
|
1639 %!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
|
1640 %!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
|
1641 %!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
|
1642 %!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
|
1643 %!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
|
1644 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1645 %!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
|
1646 %!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
|
1647 %!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
|
1648 %!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
|
1649 %!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
|
1650 %!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
|
1651 %!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
|
1652 %!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
|
1653 %!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
|
1654 %!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
|
1655 %!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
|
1656 %!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
|
1657 %!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
|
1658 %!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
|
1659 |
18890
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18834
diff
changeset
|
1660 %% Test "double" type argument |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18834
diff
changeset
|
1661 %!assert (prod (single ([1, 2, 3]), "double"), 6) |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18834
diff
changeset
|
1662 %!assert (prod (single ([-1; -2; -3]), "double"), -6) |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18834
diff
changeset
|
1663 %!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:
18834
diff
changeset
|
1664 %!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:
18834
diff
changeset
|
1665 |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18834
diff
changeset
|
1666 %% Test "native" type argument |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18834
diff
changeset
|
1667 %!assert (prod (uint8 ([1, 2, 3]), "native"), uint8 (6)) |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18834
diff
changeset
|
1668 %!assert (prod (uint8 ([-1; -2; -3]), "native"), uint8 (0)) |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18834
diff
changeset
|
1669 %!assert (prod (int8 ([1, 2, 3]), "native"), int8 (6)) |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18834
diff
changeset
|
1670 %!assert (prod (int8 ([-1; -2; -3]), "native"), int8 (-6)) |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18834
diff
changeset
|
1671 %!assert (prod ([true false; true true], "native"), [true false]) |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18834
diff
changeset
|
1672 %!assert (prod ([true false; true true], 2, "native"), [false; true]) |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18834
diff
changeset
|
1673 |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18834
diff
changeset
|
1674 %% Test input validation |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1675 %!error prod () |
18890
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18834
diff
changeset
|
1676 %!error prod (1,2,3) |
8cc66f091584
Add "native" option to prod() (bug #40349).
Rik <rik@octave.org>
parents:
18834
diff
changeset
|
1677 %!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
|
1678 */ |
7815
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1679 |
10758
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1680 static bool |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1681 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
|
1682 { |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1683 int n_args = args.length (); |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1684 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
|
1685 if (args(i).numel () != 1) |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1686 return false; |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1687 |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1688 return true; |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1689 } |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1690 |
10533
f094ac9bc93e
reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents:
10498
diff
changeset
|
1691 template <class TYPE, class T> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
1692 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
|
1693 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
|
1694 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
|
1695 int dim) |
f094ac9bc93e
reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents:
10498
diff
changeset
|
1696 { |
f094ac9bc93e
reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents:
10498
diff
changeset
|
1697 int n_args = args.length (); |
10758
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1698 if (! (equal_types<T, char>::value |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1699 || equal_types<T, octave_value>::value) |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1700 && 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
|
1701 { |
10758
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1702 // Optimize all scalars case. |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1703 dim_vector dv (1, 1); |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1704 if (dim == -1 || dim == -2) |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1705 dim = -dim - 1; |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1706 else if (dim >= 2) |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1707 dv.resize (dim+1, 1); |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1708 dv(dim) = n_args; |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1709 |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1710 result.clear (dv); |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1711 |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1712 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
|
1713 { |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1714 octave_quit (); |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1715 |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1716 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
|
1717 } |
10533
f094ac9bc93e
reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents:
10498
diff
changeset
|
1718 } |
10758
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1719 else |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1720 { |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1721 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
|
1722 |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1723 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
|
1724 { |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1725 octave_quit (); |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1726 |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1727 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
|
1728 } |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1729 |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1730 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
|
1731 } |
10533
f094ac9bc93e
reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents:
10498
diff
changeset
|
1732 } |
f094ac9bc93e
reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents:
10498
diff
changeset
|
1733 |
f094ac9bc93e
reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents:
10498
diff
changeset
|
1734 template <class TYPE, class T> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
1735 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
|
1736 single_type_concat (Sparse<T>& result, |
10498
8615b55b5caf
fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents:
10436
diff
changeset
|
1737 const octave_value_list& args, |
8615b55b5caf
fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents:
10436
diff
changeset
|
1738 int dim) |
8615b55b5caf
fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents:
10436
diff
changeset
|
1739 { |
10533
f094ac9bc93e
reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents:
10498
diff
changeset
|
1740 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
|
1741 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
|
1742 |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1743 for (int j = 0; j < n_args; j++) |
10498
8615b55b5caf
fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents:
10436
diff
changeset
|
1744 { |
8615b55b5caf
fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents:
10436
diff
changeset
|
1745 octave_quit (); |
8615b55b5caf
fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents:
10436
diff
changeset
|
1746 |
10716
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1747 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
|
1748 } |
10533
f094ac9bc93e
reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents:
10498
diff
changeset
|
1749 |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1750 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
|
1751 } |
8615b55b5caf
fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents:
10436
diff
changeset
|
1752 |
10533
f094ac9bc93e
reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents:
10498
diff
changeset
|
1753 // Dispatcher. |
10498
8615b55b5caf
fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents:
10436
diff
changeset
|
1754 template<class TYPE> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
1755 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
|
1756 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
|
1757 { |
10533
f094ac9bc93e
reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents:
10498
diff
changeset
|
1758 TYPE result; |
f094ac9bc93e
reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents:
10498
diff
changeset
|
1759 |
f094ac9bc93e
reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents:
10498
diff
changeset
|
1760 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
|
1761 |
8615b55b5caf
fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents:
10436
diff
changeset
|
1762 return result; |
8615b55b5caf
fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents:
10436
diff
changeset
|
1763 } |
8615b55b5caf
fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents:
10436
diff
changeset
|
1764 |
10758
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1765 template<class MAP> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
1766 static void |
10758
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1767 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
|
1768 const octave_value_list& args, |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1769 int dim) |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1770 { |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1771 int n_args = args.length (); |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1772 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
|
1773 |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1774 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
|
1775 { |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1776 octave_quit (); |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1777 |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1778 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
|
1779 } |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1780 |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1781 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
|
1782 } |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1783 |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1784 static octave_map |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1785 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
|
1786 int dim) |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1787 { |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1788 octave_map result; |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1789 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
|
1790 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
|
1791 else |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1792 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
|
1793 |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1794 return result; |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1795 } |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1796 |
4824 | 1797 static octave_value |
13294
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1798 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
|
1799 { |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1800 octave_value retval; |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1801 |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1802 // 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
|
1803 // 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
|
1804 // type. |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1805 |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1806 std::string cname = ov.class_name (); |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1807 |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1808 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
|
1809 |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1810 if (fcn.is_defined ()) |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1811 { |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1812 octave_value_list result |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1813 = fcn.do_multi_index_op (1, octave_value_list (1, ov)); |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1814 |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1815 if (! error_state && result.length () > 0) |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1816 retval = result(0); |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1817 else |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1818 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
|
1819 cname.c_str ()); |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1820 } |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1821 else |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1822 { |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1823 // 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
|
1824 // dispatch type. |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1825 |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1826 fcn = symbol_table::find_method (dtype, dtype); |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1827 |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1828 if (fcn.is_defined ()) |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1829 { |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1830 octave_value_list result |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1831 = fcn.do_multi_index_op (1, octave_value_list (1, ov)); |
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 if (! error_state && result.length () > 0) |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1834 retval = result(0); |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1835 else |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1836 error ("%s constructor failed for %s argument", dtype.c_str (), |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1837 cname.c_str ()); |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1838 } |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1839 else |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1840 error ("no constructor for %s!", dtype.c_str ()); |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1841 } |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1842 |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1843 return retval; |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1844 } |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1845 |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1846 octave_value |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1847 do_class_concat (const octave_value_list& ovl, std::string cattype, int dim) |
4806 | 1848 { |
1849 octave_value retval; | |
1850 | |
13294
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1851 // Get dominant type for list |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1852 |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1853 std::string dtype = get_dispatch_type (ovl); |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1854 |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1855 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
|
1856 |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1857 if (fcn.is_defined ()) |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1858 { |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1859 // Have method for dominant type, so call it and let it handle |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1860 // conversions. |
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 octave_value_list tmp2 = fcn.do_multi_index_op (1, ovl); |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1863 |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1864 if (tmp2.length () > 0) |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1865 retval = tmp2(0); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1866 else |
13294
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1867 { |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1868 error ("%s/%s method did not return a value", |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1869 dtype.c_str (), cattype.c_str ()); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1870 goto done; |
13294
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 } |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1873 else |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1874 { |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1875 // 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
|
1876 // 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
|
1877 // default operation for octave_class values. |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1878 |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1879 octave_idx_type j = 0; |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1880 octave_idx_type len = ovl.length (); |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1881 octave_value_list tmp (len, octave_value ()); |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1882 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
|
1883 { |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1884 octave_value elt = ovl(k); |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1885 |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1886 std::string t1_type = elt.class_name (); |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1887 |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1888 if (t1_type == dtype) |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1889 tmp(j++) = elt; |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1890 else if (elt.is_object () || ! elt.is_empty ()) |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
1891 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
|
1892 } |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1893 |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1894 tmp.resize (j); |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1895 |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1896 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
|
1897 |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1898 std::string cname = tmp(0).class_name (); |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1899 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
|
1900 |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1901 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
|
1902 } |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1903 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1904 done: |
13294
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1905 return retval; |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1906 } |
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 static octave_value |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1909 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
|
1910 { |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1911 octave_value retval; |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1912 |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1913 // We may need to convert elements of the list to cells, so make a |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1914 // copy. This should be efficient, it is done mostly by incrementing |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1915 // reference counts. |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1916 octave_value_list args = xargs; |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1917 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
1918 int n_args = args.length (); |
4806 | 1919 |
10716
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1920 if (n_args == 0) |
5714 | 1921 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
|
1922 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
|
1923 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
|
1924 else if (n_args > 1) |
4824 | 1925 { |
13294
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1926 std::string result_type; |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1927 |
19596
2304ddfd736f
Restore warning Octave:num-to-str missing since 3.2.4 (bug #43814).
Rik <rik@octave.org>
parents:
19059
diff
changeset
|
1928 bool all_strings_p = true; |
13294
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1929 bool all_sq_strings_p = true; |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1930 bool all_dq_strings_p = true; |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1931 bool all_real_p = true; |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1932 bool all_cmplx_p = true; |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1933 bool any_sparse_p = false; |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1934 bool any_cell_p = false; |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1935 bool any_class_p = false; |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1936 |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1937 bool first_elem_is_struct = false; |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1938 |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1939 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
|
1940 { |
13294
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1941 if (i == 0) |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1942 { |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1943 result_type = args(i).class_name (); |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1944 |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1945 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
|
1946 } |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1947 else |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1948 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
|
1949 |
19596
2304ddfd736f
Restore warning Octave:num-to-str missing since 3.2.4 (bug #43814).
Rik <rik@octave.org>
parents:
19059
diff
changeset
|
1950 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:
19059
diff
changeset
|
1951 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
|
1952 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
|
1953 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
|
1954 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
|
1955 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
|
1956 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
|
1957 all_real_p = false; |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1958 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
|
1959 || args(i).is_real_type ())) |
13294
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1960 all_cmplx_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
|
1961 if (!any_sparse_p && args(i).is_sparse_type ()) |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1962 any_sparse_p = true; |
13294
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1963 if (!any_cell_p && args(i).is_cell ()) |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1964 any_cell_p = true; |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1965 if (!any_class_p && args(i).is_object ()) |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1966 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
|
1967 } |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1968 |
13294
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1969 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
|
1970 { |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1971 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
|
1972 { |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1973 if (! args(i).is_cell ()) |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1974 args(i) = Cell (args(i)); |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1975 } |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1976 } |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1977 |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1978 if (any_class_p) |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1979 { |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1980 retval = do_class_concat (args, fname, dim); |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1981 } |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1982 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
|
1983 { |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1984 if (any_sparse_p) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
1985 { |
10716
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1986 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
|
1987 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
|
1988 else |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1989 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
|
1990 } |
10716
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1991 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1992 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1993 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
|
1994 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
|
1995 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
|
1996 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
|
1997 } |
10716
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1998 } |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1999 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
|
2000 { |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2001 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
|
2002 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
|
2003 else |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2004 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
|
2005 } |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2006 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
|
2007 { |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2008 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
|
2009 |
19596
2304ddfd736f
Restore warning Octave:num-to-str missing since 3.2.4 (bug #43814).
Rik <rik@octave.org>
parents:
19059
diff
changeset
|
2010 if (! all_strings_p) |
2304ddfd736f
Restore warning Octave:num-to-str missing since 3.2.4 (bug #43814).
Rik <rik@octave.org>
parents:
19059
diff
changeset
|
2011 gripe_implicit_conversion ("Octave:num-to-str", |
2304ddfd736f
Restore warning Octave:num-to-str missing since 3.2.4 (bug #43814).
Rik <rik@octave.org>
parents:
19059
diff
changeset
|
2012 "numeric", result_type); |
2304ddfd736f
Restore warning Octave:num-to-str missing since 3.2.4 (bug #43814).
Rik <rik@octave.org>
parents:
19059
diff
changeset
|
2013 else |
2304ddfd736f
Restore warning Octave:num-to-str missing since 3.2.4 (bug #43814).
Rik <rik@octave.org>
parents:
19059
diff
changeset
|
2014 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:
19059
diff
changeset
|
2015 |
2304ddfd736f
Restore warning Octave:num-to-str missing since 3.2.4 (bug #43814).
Rik <rik@octave.org>
parents:
19059
diff
changeset
|
2016 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
|
2017 |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2018 retval = 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
|
2019 } |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2020 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
|
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 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
|
2023 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
|
2024 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
|
2025 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
|
2026 } |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2027 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
|
2028 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
|
2029 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
|
2030 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
|
2031 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
|
2032 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
|
2033 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
|
2034 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
|
2035 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
|
2036 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
|
2037 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
|
2038 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
|
2039 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
|
2040 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
|
2041 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
|
2042 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
|
2043 else if (result_type == "cell") |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
2044 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
|
2045 else if (result_type == "struct") |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
2046 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
|
2047 else |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2048 { |
20428
b2100e1659ac
maint: Use cuddled parentheses when indexing dimension_vectors.
Rik <rik@octave.org>
parents:
20393
diff
changeset
|
2049 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
|
2050 |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2051 // Default concatenation. |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2052 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
|
2053 = &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
|
2054 |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2055 if (dim == -1 || dim == -2) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2056 { |
10716
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2057 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
|
2058 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
|
2059 } |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2060 |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2061 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
|
2062 { |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2063 if (! (dv.*concat_rule) (args(i).dims (), dim)) |
10533
f094ac9bc93e
reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents:
10498
diff
changeset
|
2064 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
2065 // Dimensions do not match. |
10716
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2066 error ("cat: dimension mismatch"); |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2067 return retval; |
10533
f094ac9bc93e
reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents:
10498
diff
changeset
|
2068 } |
10716
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2069 } |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2070 |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2071 // 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
|
2072 // 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
|
2073 // 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
|
2074 // 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
|
2075 // 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
|
2076 // 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
|
2077 // 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
|
2078 // |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2079 // 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
|
2080 // 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
|
2081 // (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
|
2082 // 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
|
2083 // 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
|
2084 |
18111
b560bac0fca2
maint: Don't use space between 'args' and '(' when doing indexing.
Rik <rik@octave.org>
parents:
18099
diff
changeset
|
2085 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
|
2086 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
|
2087 |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2088 int dv_len = dv.length (); |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
2089 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
|
2090 |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2091 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
|
2092 { |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2093 // 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
|
2094 // 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
|
2095 // the right type. |
18111
b560bac0fca2
maint: Don't use space between 'args' and '(' when doing indexing.
Rik <rik@octave.org>
parents:
18099
diff
changeset
|
2096 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
|
2097 |
18111
b560bac0fca2
maint: Don't use space between 'args' and '(' when doing indexing.
Rik <rik@octave.org>
parents:
18099
diff
changeset
|
2098 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
|
2099 |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2100 if (dim >= dv_len) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2101 { |
10716
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2102 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
|
2103 error ("%s: indexing error", fname.c_str ()); |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2104 break; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2105 } |
10716
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2106 else |
20428
b2100e1659ac
maint: Use cuddled parentheses when indexing dimension_vectors.
Rik <rik@octave.org>
parents:
20393
diff
changeset
|
2107 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
|
2108 } |
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 retval = tmp; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2110 } |
4806 | 2111 } |
2112 else | |
5823 | 2113 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
|
2114 |
4806 | 2115 return retval; |
2116 } | |
2117 | |
2118 DEFUN (horzcat, args, , | |
4824 | 2119 "-*- texinfo -*-\n\ |
4806 | 2120 @deftypefn {Built-in Function} {} 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
|
2121 Return the horizontal concatenation of N-D array objects, @var{array1},\n\ |
4806 | 2122 @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
|
2123 \n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
2124 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
|
2125 new matrices. For example:\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
2126 \n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
2127 @example\n\ |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
2128 @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
|
2129 @end example\n\ |
5642 | 2130 @seealso{cat, vertcat}\n\ |
2131 @end deftypefn") | |
4806 | 2132 { |
10716
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2133 return do_cat (args, -2, "horzcat"); |
4806 | 2134 } |
2135 | |
13294
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
2136 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2137 ## 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
|
2138 %!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
|
2139 %!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
|
2140 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2141 %!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
|
2142 %!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
|
2143 %!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
|
2144 %!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
|
2145 %!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
|
2146 %!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
|
2147 %!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
|
2148 %!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
|
2149 %!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
|
2150 %!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
|
2151 %!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
|
2152 %!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
|
2153 %!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
|
2154 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2155 %!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
|
2156 %!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
|
2157 %!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
|
2158 %!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
|
2159 %!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
|
2160 %!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
|
2161 %!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
|
2162 %!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
|
2163 %!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
|
2164 %!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
|
2165 %!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
|
2166 %!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
|
2167 %!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
|
2168 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2169 %!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
|
2170 %!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
|
2171 %!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
|
2172 %!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
|
2173 %!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
|
2174 %!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
|
2175 %!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
|
2176 %!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
|
2177 %!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
|
2178 %!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
|
2179 %!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
|
2180 %!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
|
2181 %!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
|
2182 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2183 %!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
|
2184 %!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
|
2185 %!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
|
2186 %!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
|
2187 %!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
|
2188 %!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
|
2189 %!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
|
2190 %!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
|
2191 %!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
|
2192 %!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
|
2193 %!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
|
2194 %!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
|
2195 %!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
|
2196 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2197 %!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
|
2198 %!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
|
2199 %!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
|
2200 %!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
|
2201 %!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
|
2202 %!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
|
2203 %!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
|
2204 %!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
|
2205 %!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
|
2206 %!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
|
2207 %!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
|
2208 %!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
|
2209 %!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
|
2210 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2211 %!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
|
2212 %!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
|
2213 %!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
|
2214 %!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
|
2215 %!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
|
2216 %!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
|
2217 %!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
|
2218 %!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
|
2219 %!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
|
2220 %!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
|
2221 %!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
|
2222 %!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
|
2223 %!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
|
2224 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2225 %!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
|
2226 %!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
|
2227 %!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
|
2228 %!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
|
2229 %!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
|
2230 %!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
|
2231 %!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
|
2232 %!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
|
2233 %!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
|
2234 %!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
|
2235 %!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
|
2236 %!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
|
2237 %!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
|
2238 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2239 %!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
|
2240 %!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
|
2241 %!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
|
2242 %!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
|
2243 %!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
|
2244 %!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
|
2245 %!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
|
2246 %!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
|
2247 %!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
|
2248 %!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
|
2249 %!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
|
2250 %!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
|
2251 %!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
|
2252 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2253 %!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
|
2254 %!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
|
2255 %!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
|
2256 %!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
|
2257 %!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
|
2258 %!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
|
2259 %!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
|
2260 %!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
|
2261 %!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
|
2262 %!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
|
2263 %!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
|
2264 %!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
|
2265 %!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
|
2266 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2267 %!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
|
2268 %!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
|
2269 %!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
|
2270 %!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
|
2271 %!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
|
2272 %!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
|
2273 %!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
|
2274 %!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
|
2275 %!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
|
2276 %!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
|
2277 %!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
|
2278 %!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
|
2279 %!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
|
2280 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2281 %!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
|
2282 %!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
|
2283 %!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
|
2284 %!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
|
2285 %!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
|
2286 %!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
|
2287 %!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
|
2288 %!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
|
2289 %!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
|
2290 %!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
|
2291 %!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
|
2292 %!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
|
2293 %!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
|
2294 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2295 %!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
|
2296 %!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
|
2297 %!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
|
2298 %!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
|
2299 %!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
|
2300 %!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
|
2301 %!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
|
2302 %!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
|
2303 %!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
|
2304 %!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
|
2305 %!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
|
2306 %!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
|
2307 %!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
|
2308 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2309 %!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
|
2310 %!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
|
2311 %!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
|
2312 %!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
|
2313 %!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
|
2314 %!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
|
2315 %!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
|
2316 %!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
|
2317 %!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
|
2318 %!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
|
2319 %!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
|
2320 %!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
|
2321 %!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
|
2322 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2323 %!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
|
2324 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2325 %!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
|
2326 */ |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
2327 |
4806 | 2328 DEFUN (vertcat, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2329 "-*- texinfo -*-\n\ |
4806 | 2330 @deftypefn {Built-in Function} {} 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
|
2331 Return the vertical concatenation of N-D array objects, @var{array1},\n\ |
4806 | 2332 @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
|
2333 \n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
2334 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
|
2335 new matrices. For example:\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
2336 \n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
2337 @example\n\ |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
2338 @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
|
2339 @end example\n\ |
5642 | 2340 @seealso{cat, horzcat}\n\ |
2341 @end deftypefn") | |
4806 | 2342 { |
10716
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2343 return do_cat (args, -1, "vertcat"); |
4806 | 2344 } |
2345 | |
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 %!test |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2348 %! c = {"foo"; "bar"; "bazoloa"}; |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2349 %! 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
|
2350 */ |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
2351 |
4758 | 2352 DEFUN (cat, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2353 "-*- texinfo -*-\n\ |
4758 | 2354 @deftypefn {Built-in Function} {} 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
|
2355 Return the concatenation of N-D array objects, @var{array1},\n\ |
4806 | 2356 @var{array2}, @dots{}, @var{arrayN} along dimension @var{dim}.\n\ |
4758 | 2357 \n\ |
2358 @example\n\ | |
2359 @group\n\ | |
2360 A = ones (2, 2);\n\ | |
2361 B = zeros (2, 2);\n\ | |
2362 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
|
2363 @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
|
2364 1 1 0 0\n\ |
4758 | 2365 @end group\n\ |
2366 @end example\n\ | |
2367 \n\ | |
2368 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
|
2369 second dimension in the following way:\n\ |
4758 | 2370 \n\ |
2371 @example\n\ | |
2372 @group\n\ | |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
2373 [A, B]\n\ |
4758 | 2374 @end group\n\ |
2375 @end example\n\ | |
2376 \n\ | |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
2377 @var{dim} can be larger than the dimensions of the N-D array objects\n\ |
4758 | 2378 and the result will thus have @var{dim} dimensions as the\n\ |
2379 following example shows:\n\ | |
10840 | 2380 \n\ |
4758 | 2381 @example\n\ |
2382 @group\n\ | |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
2383 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
|
2384 @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
|
2385 \n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
2386 1 1\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
2387 1 1\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
2388 \n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
2389 ans(:,:,1,2) =\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
2390 \n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
2391 0 0\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
2392 0 0\n\ |
4758 | 2393 @end group\n\ |
2394 @end example\n\ | |
5642 | 2395 @seealso{horzcat, vertcat}\n\ |
2396 @end deftypefn") | |
4758 | 2397 { |
10716
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2398 octave_value retval; |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2399 |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2400 if (args.length () > 0) |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2401 { |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2402 int dim = args(0).int_value () - 1; |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2403 |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2404 if (! error_state) |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2405 { |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2406 if (dim >= 0) |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2407 retval = do_cat (args.slice (1, args.length () - 1), dim, "cat"); |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2408 else |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11591
diff
changeset
|
2409 error ("cat: DIM must be a valid dimension"); |
10716
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2410 } |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2411 else |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11591
diff
changeset
|
2412 error ("cat: DIM must be an integer"); |
10716
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2413 } |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2414 else |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2415 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
|
2416 |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2417 return retval; |
4758 | 2418 } |
2419 | |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
2420 /* |
14085
4e8f23ccadce
test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents:
14022
diff
changeset
|
2421 %!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
|
2422 %! 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
|
2423 %! |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2424 %! 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
|
2425 %! 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
|
2426 %! 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
|
2427 %! 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
|
2428 %! 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
|
2429 %! 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
|
2430 %! 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
|
2431 %! 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
|
2432 %! |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2433 %! 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
|
2434 %! 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
|
2435 %! 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
|
2436 %! 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
|
2437 %! 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
|
2438 %! 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
|
2439 %! 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
|
2440 %! 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
|
2441 %! |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2442 %! if (nargin == 3 || cmplx) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2443 %! 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
|
2444 %! 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
|
2445 %! 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
|
2446 %! 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
|
2447 %! 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
|
2448 %! 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
|
2449 %! 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
|
2450 %! 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
|
2451 %! |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2452 %! 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
|
2453 %! 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
|
2454 %! 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
|
2455 %! 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
|
2456 %! 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
|
2457 %! 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
|
2458 %! 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
|
2459 %! 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
|
2460 %! |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2461 %! 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
|
2462 %! 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
|
2463 %! 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
|
2464 %! 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
|
2465 %! 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
|
2466 %! 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
|
2467 %! 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
|
2468 %! 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
|
2469 %! |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2470 %! 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
|
2471 %! 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
|
2472 %! 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
|
2473 %! 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
|
2474 %! 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
|
2475 %! 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
|
2476 %! 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
|
2477 %! 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
|
2478 %! |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2479 %! 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
|
2480 %! 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
|
2481 %! 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
|
2482 %! 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
|
2483 %! 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
|
2484 %! 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
|
2485 %! 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
|
2486 %! 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
|
2487 %! |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2488 %! 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
|
2489 %! 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
|
2490 %! 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
|
2491 %! 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
|
2492 %! 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
|
2493 %! 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
|
2494 %! 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
|
2495 %! 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
|
2496 %! endif |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2497 %! ret = true; |
14085
4e8f23ccadce
test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents:
14022
diff
changeset
|
2498 %!endfunction |
4e8f23ccadce
test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents:
14022
diff
changeset
|
2499 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2500 %!assert (__testcat ("double", "double", "double")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2501 %!assert (__testcat ("single", "double", "single")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2502 %!assert (__testcat ("double", "single", "single")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2503 %!assert (__testcat ("single", "single", "single")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2504 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2505 %!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
|
2506 %!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
|
2507 %!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
|
2508 %!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
|
2509 %!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
|
2510 %!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
|
2511 %!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
|
2512 %!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
|
2513 %!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
|
2514 %!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
|
2515 %!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
|
2516 %!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
|
2517 %!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
|
2518 %!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
|
2519 %!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
|
2520 %!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
|
2521 %!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
|
2522 %!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
|
2523 %!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
|
2524 %!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
|
2525 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2526 %!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
|
2527 %!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
|
2528 %!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
|
2529 %!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
|
2530 %!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
|
2531 %!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
|
2532 %!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
|
2533 %!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
|
2534 %!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
|
2535 %!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
|
2536 %!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
|
2537 %!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
|
2538 %!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
|
2539 %!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
|
2540 %!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
|
2541 %!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
|
2542 %!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
|
2543 %!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
|
2544 %!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
|
2545 %!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
|
2546 |
4e8f23ccadce
test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents:
14022
diff
changeset
|
2547 %!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
|
2548 %!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
|
2549 %!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
|
2550 %!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
|
2551 |
4e8f23ccadce
test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents:
14022
diff
changeset
|
2552 %!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
|
2553 %!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
|
2554 %!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
|
2555 |
18833
6113e0c6920b
maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents:
18831
diff
changeset
|
2556 %!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:
18831
diff
changeset
|
2557 %!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
|
2558 |
14085
4e8f23ccadce
test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents:
14022
diff
changeset
|
2559 %!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
|
2560 %!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
|
2561 */ |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
2562 |
4593 | 2563 static octave_value |
6959 | 2564 do_permute (const octave_value_list& args, bool inv) |
4593 | 2565 { |
2566 octave_value retval; | |
2567 | |
5148 | 2568 if (args.length () == 2 && args(1).length () >= args(1).ndims ()) |
4593 | 2569 { |
2570 Array<int> vec = args(1).int_vector_value (); | |
2571 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2572 // FIXME: maybe we should create an idx_vector object |
5148 | 2573 // here and pass that to permute? |
2574 | |
20442
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20428
diff
changeset
|
2575 int n = vec.numel (); |
5148 | 2576 |
2577 for (int i = 0; i < n; i++) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2578 vec(i)--; |
5148 | 2579 |
4593 | 2580 octave_value ret = args(0).permute (vec, inv); |
2581 | |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
2582 retval = ret; |
4593 | 2583 } |
2584 else | |
5823 | 2585 print_usage (); |
4593 | 2586 |
2587 return retval; | |
2588 } | |
2589 | |
2590 DEFUN (permute, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2591 "-*- texinfo -*-\n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
2592 @deftypefn {Built-in Function} {} permute (@var{A}, @var{perm})\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
2593 Return the generalized transpose for an N-D array object @var{A}.\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
2594 \n\ |
4593 | 2595 The permutation vector @var{perm} must contain the elements\n\ |
20780
c6059134f5d3
data.cc: Add @w{} around @code segments in docstrings to prevent line breaks.
Rik <rik@octave.org>
parents:
20608
diff
changeset
|
2596 @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:
20608
diff
changeset
|
2597 once). The @var{N}th dimension of @var{A} gets remapped to dimension\n\ |
19344
0f9c5a15c8fa
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
19310
diff
changeset
|
2598 @code{@var{PERM}(@var{N})}. For example:\n\ |
19265
ec1e295402fa
doc: explain permute's PERM variable and give examples
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
19230
diff
changeset
|
2599 \n\ |
ec1e295402fa
doc: explain permute's PERM variable and give examples
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
19230
diff
changeset
|
2600 @example\n\ |
ec1e295402fa
doc: explain permute's PERM variable and give examples
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
19230
diff
changeset
|
2601 @group\n\ |
ec1e295402fa
doc: explain permute's PERM variable and give examples
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
19230
diff
changeset
|
2602 @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:
19230
diff
changeset
|
2603 size (@var{x})\n\ |
ec1e295402fa
doc: explain permute's PERM variable and give examples
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
19230
diff
changeset
|
2604 @result{} 2 3 5 7\n\ |
ec1e295402fa
doc: explain permute's PERM variable and give examples
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
19230
diff
changeset
|
2605 \n\ |
ec1e295402fa
doc: explain permute's PERM variable and give examples
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
19230
diff
changeset
|
2606 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:
19230
diff
changeset
|
2607 @result{} 3 2 5 7\n\ |
ec1e295402fa
doc: explain permute's PERM variable and give examples
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
19230
diff
changeset
|
2608 \n\ |
ec1e295402fa
doc: explain permute's PERM variable and give examples
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
19230
diff
changeset
|
2609 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:
19230
diff
changeset
|
2610 @result{} 2 5 7 3\n\ |
ec1e295402fa
doc: explain permute's PERM variable and give examples
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
19230
diff
changeset
|
2611 \n\ |
ec1e295402fa
doc: explain permute's PERM variable and give examples
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
19230
diff
changeset
|
2612 ## The identity permutation\n\ |
ec1e295402fa
doc: explain permute's PERM variable and give examples
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
19230
diff
changeset
|
2613 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:
19230
diff
changeset
|
2614 @result{} 2 3 5 7\n\ |
ec1e295402fa
doc: explain permute's PERM variable and give examples
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
19230
diff
changeset
|
2615 @end group\n\ |
ec1e295402fa
doc: explain permute's PERM variable and give examples
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
19230
diff
changeset
|
2616 @end example\n\ |
5642 | 2617 @seealso{ipermute}\n\ |
2618 @end deftypefn") | |
4593 | 2619 { |
6959 | 2620 return do_permute (args, false); |
4593 | 2621 } |
2622 | |
2623 DEFUN (ipermute, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2624 "-*- texinfo -*-\n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
2625 @deftypefn {Built-in Function} {} ipermute (@var{A}, @var{iperm})\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
2626 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:
20068
diff
changeset
|
2627 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
2628 The expression\n\ |
4593 | 2629 \n\ |
2630 @example\n\ | |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
2631 ipermute (permute (A, perm), perm)\n\ |
4593 | 2632 @end example\n\ |
10840 | 2633 \n\ |
10846
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10840
diff
changeset
|
2634 @noindent\n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
2635 returns the original array @var{A}.\n\ |
5642 | 2636 @seealso{permute}\n\ |
2637 @end deftypefn") | |
4593 | 2638 { |
6959 | 2639 return do_permute (args, true); |
4593 | 2640 } |
2641 | |
3195 | 2642 DEFUN (length, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2643 "-*- texinfo -*-\n\ |
3373 | 2644 @deftypefn {Built-in Function} {} 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
|
2645 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
|
2646 \n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17268
diff
changeset
|
2647 The length is 0 for empty objects, 1 for scalars, and the number of elements\n\ |
20608
fc23fbe05f3a
doc: Clarify behavior of length() function (bug #45611).
Rik <rik@octave.org>
parents:
20393
diff
changeset
|
2648 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:
20393
diff
changeset
|
2649 of elements along the largest dimension\n\ |
fc23fbe05f3a
doc: Clarify behavior of length() function (bug #45611).
Rik <rik@octave.org>
parents:
20393
diff
changeset
|
2650 (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
|
2651 @seealso{numel, size}\n\ |
3373 | 2652 @end deftypefn") |
3195 | 2653 { |
2654 octave_value retval; | |
2655 | |
2656 if (args.length () == 1) | |
9706
71160b139b07
simplify length,ndims,size and size_equal
Jaroslav Hajek <highegg@gmail.com>
parents:
9705
diff
changeset
|
2657 retval = args(0).length (); |
3195 | 2658 else |
5823 | 2659 print_usage (); |
3195 | 2660 |
2661 return retval; | |
2662 } | |
2663 | |
4554 | 2664 DEFUN (ndims, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2665 "-*- texinfo -*-\n\ |
4554 | 2666 @deftypefn {Built-in Function} {} ndims (@var{a})\n\ |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
2667 Return the number of dimensions of @var{a}.\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
2668 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
2669 For any array, the result will always be greater than or equal to 2.\n\ |
4554 | 2670 Trailing singleton dimensions are not counted.\n\ |
10840 | 2671 \n\ |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
2672 @example\n\ |
10711
fbd7843974fa
Periodic grammar check of documentation files to ensure common format.
Rik <octave@nomad.inbox5.com>
parents:
10707
diff
changeset
|
2673 @group\n\ |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
2674 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
|
2675 @result{} 3\n\ |
10711
fbd7843974fa
Periodic grammar check of documentation files to ensure common format.
Rik <octave@nomad.inbox5.com>
parents:
10707
diff
changeset
|
2676 @end group\n\ |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
2677 @end example\n\ |
15028
397f0d80bd47
Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents:
15024
diff
changeset
|
2678 @seealso{size}\n\ |
4554 | 2679 @end deftypefn") |
2680 { | |
2681 octave_value retval; | |
2682 | |
2683 if (args.length () == 1) | |
9706
71160b139b07
simplify length,ndims,size and size_equal
Jaroslav Hajek <highegg@gmail.com>
parents:
9705
diff
changeset
|
2684 retval = args(0).ndims (); |
4554 | 2685 else |
5823 | 2686 print_usage (); |
4554 | 2687 |
2688 return retval; | |
2689 } | |
2690 | |
4559 | 2691 DEFUN (numel, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2692 "-*- texinfo -*-\n\ |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
2693 @deftypefn {Built-in Function} {} numel (@var{a})\n\ |
9705
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
2694 @deftypefnx {Built-in Function} {} numel (@var{a}, @var{idx1}, @var{idx2}, @dots{})\n\ |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
2695 Return the number of elements in the object @var{a}.\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
2696 \n\ |
9705
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
2697 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
|
2698 return the number of elements that would result from the indexing\n\ |
10840 | 2699 \n\ |
9705
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
2700 @example\n\ |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
2701 @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
|
2702 @end example\n\ |
10840 | 2703 \n\ |
20783
db3286201347
doc: Add explanation of ':' optional input to numel().
Rik <rik@octave.org>
parents:
20780
diff
changeset
|
2704 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
|
2705 \n\ |
67a5acac8e1b
Clarify what indices can be for numel
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12681
diff
changeset
|
2706 @example\n\ |
13929
9cae456085c2
Grammarcheck of documentation before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
2707 @group\n\ |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
2708 @var{a} = 1;\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
2709 @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
|
2710 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
|
2711 @end group\n\ |
12924
67a5acac8e1b
Clarify what indices can be for numel
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12681
diff
changeset
|
2712 @end example\n\ |
67a5acac8e1b
Clarify what indices can be for numel
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12681
diff
changeset
|
2713 \n\ |
13929
9cae456085c2
Grammarcheck of documentation before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
2714 @noindent\n\ |
12924
67a5acac8e1b
Clarify what indices can be for numel
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12681
diff
changeset
|
2715 will return 6, as this is the number of ways to index with @var{b}.\n\ |
20783
db3286201347
doc: Add explanation of ':' optional input to numel().
Rik <rik@octave.org>
parents:
20780
diff
changeset
|
2716 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:
20780
diff
changeset
|
2717 operator. For example,\n\ |
db3286201347
doc: Add explanation of ':' optional input to numel().
Rik <rik@octave.org>
parents:
20780
diff
changeset
|
2718 \n\ |
db3286201347
doc: Add explanation of ':' optional input to numel().
Rik <rik@octave.org>
parents:
20780
diff
changeset
|
2719 @example\n\ |
db3286201347
doc: Add explanation of ':' optional input to numel().
Rik <rik@octave.org>
parents:
20780
diff
changeset
|
2720 @group\n\ |
db3286201347
doc: Add explanation of ':' optional input to numel().
Rik <rik@octave.org>
parents:
20780
diff
changeset
|
2721 @var{a} = ones (5, 3);\n\ |
db3286201347
doc: Add explanation of ':' optional input to numel().
Rik <rik@octave.org>
parents:
20780
diff
changeset
|
2722 numel (@var{a}, 2, \":\")\n\ |
db3286201347
doc: Add explanation of ':' optional input to numel().
Rik <rik@octave.org>
parents:
20780
diff
changeset
|
2723 @end group\n\ |
db3286201347
doc: Add explanation of ':' optional input to numel().
Rik <rik@octave.org>
parents:
20780
diff
changeset
|
2724 @end example\n\ |
db3286201347
doc: Add explanation of ':' optional input to numel().
Rik <rik@octave.org>
parents:
20780
diff
changeset
|
2725 \n\ |
db3286201347
doc: Add explanation of ':' optional input to numel().
Rik <rik@octave.org>
parents:
20780
diff
changeset
|
2726 @noindent\n\ |
db3286201347
doc: Add explanation of ':' optional input to numel().
Rik <rik@octave.org>
parents:
20780
diff
changeset
|
2727 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
|
2728 \n\ |
9705
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
2729 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
|
2730 indexing, i.e., @code{object@{@dots{}@}} or @code{object(@dots{}).field}.\n\ |
5724 | 2731 @seealso{size}\n\ |
4559 | 2732 @end deftypefn") |
2733 { | |
2734 octave_value retval; | |
9329
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9319
diff
changeset
|
2735 octave_idx_type nargin = args.length (); |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9319
diff
changeset
|
2736 |
9705
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
2737 if (nargin == 1) |
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
2738 retval = args(0).numel (); |
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
2739 else if (nargin > 1) |
4559 | 2740 { |
9705
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
2741 // 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
|
2742 // an overloaded call, not to builtin! |
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
2743 retval = dims_to_numel (args(0).dims (), args.slice (1, nargin-1)); |
4559 | 2744 } |
2745 else | |
5823 | 2746 print_usage (); |
4559 | 2747 |
2748 return retval; | |
2749 } | |
2750 | |
1957 | 2751 DEFUN (size, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2752 "-*- texinfo -*-\n\ |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
2753 @deftypefn {Built-in Function} {} size (@var{a})\n\ |
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
2754 @deftypefnx {Built-in Function} {} size (@var{a}, @var{dim})\n\ |
12546
39ca02387a32
Improve docstrings for a number of functions.
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
2755 Return the number of rows and columns of @var{a}.\n\ |
3373 | 2756 \n\ |
2757 With one input argument and one output argument, the result is returned\n\ | |
4741 | 2758 in a row vector. If there are multiple output arguments, the number of\n\ |
2759 rows is assigned to the first, and the number of columns to the second,\n\ | |
10840 | 2760 etc. For example:\n\ |
3373 | 2761 \n\ |
2762 @example\n\ | |
2763 @group\n\ | |
2764 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
|
2765 @result{} [ 3, 2 ]\n\ |
1031 | 2766 \n\ |
3373 | 2767 [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
|
2768 @result{} nr = 3\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
2769 @result{} nc = 2\n\ |
3373 | 2770 @end group\n\ |
2771 @end example\n\ | |
2772 \n\ | |
4741 | 2773 If given a second argument, @code{size} will return the size of the\n\ |
10840 | 2774 corresponding dimension. For example,\n\ |
1031 | 2775 \n\ |
3373 | 2776 @example\n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
9041
diff
changeset
|
2777 @group\n\ |
3373 | 2778 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
|
2779 @result{} 2\n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
9041
diff
changeset
|
2780 @end group\n\ |
3373 | 2781 @end example\n\ |
2782 \n\ | |
2783 @noindent\n\ | |
2784 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
|
2785 @seealso{numel, ndims, length, rows, columns}\n\ |
3373 | 2786 @end deftypefn") |
523 | 2787 { |
2086 | 2788 octave_value_list retval; |
523 | 2789 |
2790 int nargin = args.length (); | |
2791 | |
4513 | 2792 if (nargin == 1) |
523 | 2793 { |
9706
71160b139b07
simplify length,ndims,size and size_equal
Jaroslav Hajek <highegg@gmail.com>
parents:
9705
diff
changeset
|
2794 const dim_vector dimensions = args(0).dims (); |
4513 | 2795 |
2796 if (nargout > 1) | |
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 const dim_vector rdims = dimensions.redim (nargout); |
71160b139b07
simplify length,ndims,size and size_equal
Jaroslav Hajek <highegg@gmail.com>
parents:
9705
diff
changeset
|
2799 retval.resize (nargout); |
71160b139b07
simplify length,ndims,size and size_equal
Jaroslav Hajek <highegg@gmail.com>
parents:
9705
diff
changeset
|
2800 for (int i = 0; i < nargout; i++) |
71160b139b07
simplify length,ndims,size and size_equal
Jaroslav Hajek <highegg@gmail.com>
parents:
9705
diff
changeset
|
2801 retval(i) = rdims(i); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2802 } |
4513 | 2803 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2804 { |
9706
71160b139b07
simplify length,ndims,size and size_equal
Jaroslav Hajek <highegg@gmail.com>
parents:
9705
diff
changeset
|
2805 int ndims = dimensions.length (); |
71160b139b07
simplify length,ndims,size and size_equal
Jaroslav Hajek <highegg@gmail.com>
parents:
9705
diff
changeset
|
2806 |
71160b139b07
simplify length,ndims,size and size_equal
Jaroslav Hajek <highegg@gmail.com>
parents:
9705
diff
changeset
|
2807 NoAlias<Matrix> m (1, ndims); |
71160b139b07
simplify length,ndims,size and size_equal
Jaroslav Hajek <highegg@gmail.com>
parents:
9705
diff
changeset
|
2808 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2809 for (int i = 0; i < ndims; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2810 m(i) = dimensions(i); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2811 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2812 retval(0) = m; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2813 } |
1031 | 2814 } |
2815 else if (nargin == 2 && nargout < 2) | |
2816 { | |
5275 | 2817 octave_idx_type nd = args(1).int_value (true); |
1031 | 2818 |
2819 if (error_state) | |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11591
diff
changeset
|
2820 error ("size: DIM must be a scalar"); |
712 | 2821 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2822 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2823 const dim_vector dv = args(0).dims (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2824 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2825 if (nd > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2826 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2827 if (nd <= dv.length ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2828 retval(0) = dv(nd-1); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
2829 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2830 retval(0) = 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2831 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2832 else |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11591
diff
changeset
|
2833 error ("size: requested dimension DIM (= %d) out of range", nd); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2834 } |
523 | 2835 } |
712 | 2836 else |
5823 | 2837 print_usage (); |
523 | 2838 |
2839 return retval; | |
2840 } | |
2841 | |
6156 | 2842 DEFUN (size_equal, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2843 "-*- texinfo -*-\n\ |
6561 | 2844 @deftypefn {Built-in Function} {} size_equal (@var{a}, @var{b}, @dots{})\n\ |
2845 Return true if the dimensions of all arguments agree.\n\ | |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
2846 \n\ |
6156 | 2847 Trailing singleton dimensions are ignored.\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
2848 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
|
2849 @seealso{size, numel, ndims}\n\ |
6156 | 2850 @end deftypefn") |
2851 { | |
2852 octave_value retval; | |
2853 | |
6561 | 2854 int nargin = args.length (); |
2855 | |
10002
e93c9bfff8b8
allow size_equal with 0 arguments
Jaroslav Hajek <highegg@gmail.com>
parents:
9866
diff
changeset
|
2856 retval = true; |
e93c9bfff8b8
allow size_equal with 0 arguments
Jaroslav Hajek <highegg@gmail.com>
parents:
9866
diff
changeset
|
2857 |
8947
1e4b3149365a
allow size_equal called with 1 arg
Jaroslav Hajek <highegg@gmail.com>
parents:
8934
diff
changeset
|
2858 if (nargin >= 1) |
6156 | 2859 { |
2860 dim_vector a_dims = args(0).dims (); | |
6561 | 2861 |
2862 for (int i = 1; i < nargin; ++i) | |
2863 { | |
2864 dim_vector b_dims = args(i).dims (); | |
2865 | |
2866 if (a_dims != b_dims) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2867 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2868 retval = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2869 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2870 } |
6561 | 2871 } |
6156 | 2872 } |
2873 | |
2874 return retval; | |
2875 } | |
2876 | |
5602 | 2877 DEFUN (nnz, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2878 "-*- texinfo -*-\n\ |
19004
53af80da6781
doc: Update documentation of sparse functions including seealso links.
Rik <rik@octave.org>
parents:
18978
diff
changeset
|
2879 @deftypefn {Built-in Function} {@var{n} =} nnz (@var{a})\n\ |
19007
9ac2357f19bc
doc: Replace "non-zero" with "nonzero" to match existing usage.
Rik <rik@octave.org>
parents:
19006
diff
changeset
|
2880 Return the number of nonzero elements in @var{a}.\n\ |
19004
53af80da6781
doc: Update documentation of sparse functions including seealso links.
Rik <rik@octave.org>
parents:
18978
diff
changeset
|
2881 @seealso{nzmax, nonzeros, find}\n\ |
5602 | 2882 @end deftypefn") |
2883 { | |
2884 octave_value retval; | |
2885 | |
2886 if (args.length () == 1) | |
2887 retval = args(0).nnz (); | |
2888 else | |
5823 | 2889 print_usage (); |
5602 | 2890 |
2891 return retval; | |
2892 } | |
2893 | |
5604 | 2894 DEFUN (nzmax, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2895 "-*- texinfo -*-\n\ |
19004
53af80da6781
doc: Update documentation of sparse functions including seealso links.
Rik <rik@octave.org>
parents:
18978
diff
changeset
|
2896 @deftypefn {Built-in Function} {@var{n} =} nzmax (@var{SM})\n\ |
5604 | 2897 Return the amount of storage allocated to the sparse matrix @var{SM}.\n\ |
19004
53af80da6781
doc: Update documentation of sparse functions including seealso links.
Rik <rik@octave.org>
parents:
18978
diff
changeset
|
2898 \n\ |
7001 | 2899 Note that Octave tends to crop unused memory at the first opportunity\n\ |
19004
53af80da6781
doc: Update documentation of sparse functions including seealso links.
Rik <rik@octave.org>
parents:
18978
diff
changeset
|
2900 for sparse objects. Thus, in general the value of @code{nzmax} will be the\n\ |
20393
4e7f12a763cd
doc: Remove typo of same word twice in a row.
Rik <rik@octave.org>
parents:
20382
diff
changeset
|
2901 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
|
2902 @seealso{nnz, spalloc, sparse}\n\ |
5604 | 2903 @end deftypefn") |
2904 { | |
2905 octave_value retval; | |
2906 | |
14843
7d4f87c75dbb
data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents:
14635
diff
changeset
|
2907 if (args.length () == 1) |
5604 | 2908 retval = args(0).nzmax (); |
2909 else | |
5823 | 2910 print_usage (); |
5604 | 2911 |
2912 return retval; | |
2913 } | |
2914 | |
5677 | 2915 DEFUN (rows, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2916 "-*- texinfo -*-\n\ |
5677 | 2917 @deftypefn {Built-in Function} {} rows (@var{a})\n\ |
2918 Return the number of rows of @var{a}.\n\ | |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
2919 @seealso{columns, size, length, numel, isscalar, isvector, ismatrix}\n\ |
5677 | 2920 @end deftypefn") |
2921 { | |
2922 octave_value retval; | |
2923 | |
2924 if (args.length () == 1) | |
2925 retval = args(0).rows (); | |
2926 else | |
5823 | 2927 print_usage (); |
5677 | 2928 |
2929 return retval; | |
2930 } | |
2931 | |
2932 DEFUN (columns, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2933 "-*- texinfo -*-\n\ |
5677 | 2934 @deftypefn {Built-in Function} {} columns (@var{a})\n\ |
2935 Return the number of columns of @var{a}.\n\ | |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
2936 @seealso{rows, size, length, numel, isscalar, isvector, ismatrix}\n\ |
5677 | 2937 @end deftypefn") |
2938 { | |
2939 octave_value retval; | |
2940 | |
2941 if (args.length () == 1) | |
2942 retval = args(0).columns (); | |
2943 else | |
5823 | 2944 print_usage (); |
5677 | 2945 |
2946 return retval; | |
2947 } | |
2948 | |
1957 | 2949 DEFUN (sum, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2950 "-*- texinfo -*-\n\ |
9163
9cb0c21e97f7
Update section 17.4 (Sums and Products) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9155
diff
changeset
|
2951 @deftypefn {Built-in Function} {} sum (@var{x})\n\ |
9cb0c21e97f7
Update section 17.4 (Sums and Products) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9155
diff
changeset
|
2952 @deftypefnx {Built-in Function} {} sum (@var{x}, @var{dim})\n\ |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
2953 @deftypefnx {Built-in Function} {} sum (@dots{}, \"native\")\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
2954 @deftypefnx {Built-in Function} {} sum (@dots{}, \"double\")\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
2955 @deftypefnx {Built-in Function} {} sum (@dots{}, \"extra\")\n\ |
18891
5baada25d5a2
Rewrite docstring of sum() to match prod().
Rik <rik@octave.org>
parents:
18890
diff
changeset
|
2956 Sum of elements along dimension @var{dim}.\n\ |
5baada25d5a2
Rewrite docstring of sum() to match prod().
Rik <rik@octave.org>
parents:
18890
diff
changeset
|
2957 \n\ |
5baada25d5a2
Rewrite docstring of sum() to match prod().
Rik <rik@octave.org>
parents:
18890
diff
changeset
|
2958 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:
18890
diff
changeset
|
2959 \n\ |
19007
9ac2357f19bc
doc: Replace "non-zero" with "nonzero" to match existing usage.
Rik <rik@octave.org>
parents:
19006
diff
changeset
|
2960 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:
19006
diff
changeset
|
2961 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:
19006
diff
changeset
|
2962 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:
19006
diff
changeset
|
2963 than the default double type.\n\ |
18891
5baada25d5a2
Rewrite docstring of sum() to match prod().
Rik <rik@octave.org>
parents:
18890
diff
changeset
|
2964 \n\ |
5baada25d5a2
Rewrite docstring of sum() to match prod().
Rik <rik@octave.org>
parents:
18890
diff
changeset
|
2965 For example:\n\ |
7112 | 2966 \n\ |
2967 @example\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
9041
diff
changeset
|
2968 @group\n\ |
7112 | 2969 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
|
2970 @result{} 2\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
2971 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
|
2972 @result{} true\n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
9041
diff
changeset
|
2973 @end group\n\ |
7112 | 2974 @end example\n\ |
10840 | 2975 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17268
diff
changeset
|
2976 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
|
2977 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
|
2978 \n\ |
19007
9ac2357f19bc
doc: Replace "non-zero" with "nonzero" to match existing usage.
Rik <rik@octave.org>
parents:
19006
diff
changeset
|
2979 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:
19006
diff
changeset
|
2980 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
|
2981 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
|
2982 @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
|
2983 @seealso{cumsum, sumsq, prod}\n\ |
3428 | 2984 @end deftypefn") |
523 | 2985 { |
9721
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2986 octave_value retval; |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2987 |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2988 int nargin = args.length (); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2989 |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2990 bool isnative = false; |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2991 bool isdouble = false; |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2992 bool isextra = false; |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2993 |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2994 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
|
2995 { |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2996 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
|
2997 |
19948
67f2c76f9f4d
Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents:
19944
diff
changeset
|
2998 if (str == "native") |
67f2c76f9f4d
Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents:
19944
diff
changeset
|
2999 isnative = true; |
67f2c76f9f4d
Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents:
19944
diff
changeset
|
3000 else if (str == "double") |
67f2c76f9f4d
Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents:
19944
diff
changeset
|
3001 isdouble = true; |
67f2c76f9f4d
Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents:
19944
diff
changeset
|
3002 else if (str == "extra") |
67f2c76f9f4d
Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents:
19944
diff
changeset
|
3003 isextra = true; |
67f2c76f9f4d
Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents:
19944
diff
changeset
|
3004 else |
67f2c76f9f4d
Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents:
19944
diff
changeset
|
3005 error ("sum: unrecognized type argument '%s'", str.c_str ()); |
67f2c76f9f4d
Remove unnecessary checking of error_state after is_string validation.
Rik <rik@octave.org>
parents:
19944
diff
changeset
|
3006 nargin --; |
9721
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
3007 } |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
3008 |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
3009 if (nargin == 1 || nargin == 2) |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
3010 { |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
3011 octave_value arg = args(0); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
3012 |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
3013 int dim = -1; |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
3014 if (nargin == 2) |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
3015 { |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
3016 dim = args(1).int_value () - 1; |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
3017 if (dim < 0) |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11591
diff
changeset
|
3018 error ("sum: invalid dimension DIM = %d", dim + 1); |
9721
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
3019 } |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
3020 |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3021 switch (arg.builtin_type ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3022 { |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3023 case btyp_double: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3024 if (arg.is_sparse_type ()) |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3025 { |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3026 if (isextra) |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3027 warning ("sum: 'extra' not yet implemented for sparse matrices"); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3028 retval = arg.sparse_matrix_value ().sum (dim); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3029 } |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3030 else if (isextra) |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3031 retval = arg.array_value ().xsum (dim); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3032 else |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3033 retval = arg.array_value ().sum (dim); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3034 break; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3035 case btyp_complex: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3036 if (arg.is_sparse_type ()) |
9721
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
3037 { |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3038 if (isextra) |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3039 warning ("sum: 'extra' not yet implemented for sparse matrices"); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3040 retval = arg.sparse_complex_matrix_value ().sum (dim); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3041 } |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3042 else if (isextra) |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3043 retval = arg.complex_array_value ().xsum (dim); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3044 else |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3045 retval = arg.complex_array_value ().sum (dim); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3046 break; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3047 case btyp_float: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3048 if (isdouble || isextra) |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3049 retval = arg.float_array_value ().dsum (dim); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3050 else |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3051 retval = arg.float_array_value ().sum (dim); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3052 break; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3053 case btyp_float_complex: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3054 if (isdouble || isextra) |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3055 retval = arg.float_complex_array_value ().dsum (dim); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3056 else |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3057 retval = arg.float_complex_array_value ().sum (dim); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3058 break; |
9721
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
3059 |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
3060 #define MAKE_INT_BRANCH(X) \ |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3061 case btyp_ ## X: \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3062 if (isnative) \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3063 retval = arg.X ## _array_value ().sum (dim); \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3064 else \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3065 retval = arg.X ## _array_value ().dsum (dim); \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3066 break; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3067 MAKE_INT_BRANCH (int8); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3068 MAKE_INT_BRANCH (int16); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3069 MAKE_INT_BRANCH (int32); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3070 MAKE_INT_BRANCH (int64); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3071 MAKE_INT_BRANCH (uint8); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3072 MAKE_INT_BRANCH (uint16); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3073 MAKE_INT_BRANCH (uint32); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3074 MAKE_INT_BRANCH (uint64); |
9721
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
3075 #undef MAKE_INT_BRANCH |
19794
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19793
diff
changeset
|
3076 |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3077 // GAGME: Accursed Matlab compatibility... |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3078 case btyp_char: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3079 if (isextra) |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3080 retval = arg.array_value (true).xsum (dim); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3081 else |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3082 retval = arg.array_value (true).sum (dim); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3083 break; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3084 case btyp_bool: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3085 if (arg.is_sparse_type ()) |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3086 { |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3087 if (isnative) |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3088 retval = arg.sparse_bool_matrix_value ().any (dim); |
15621
e9d842dcfc91
*data.cc (Fsum): allow string arguments for Matlab compatibility
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15509
diff
changeset
|
3089 else |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3090 retval = arg.sparse_bool_matrix_value ().sum (dim); |
9721
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
3091 } |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3092 else if (isnative) |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3093 retval = arg.bool_array_value ().any (dim); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3094 else |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3095 retval = arg.bool_array_value ().sum (dim); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3096 break; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3097 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3098 default: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3099 gripe_wrong_type_arg ("sum", arg); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3100 } |
9721
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
3101 } |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
3102 else |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
3103 print_usage (); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
3104 |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
3105 return retval; |
523 | 3106 } |
3107 | |
7112 | 3108 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3109 %!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
|
3110 %!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
|
3111 %!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
|
3112 %!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
|
3113 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3114 %!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
|
3115 %!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
|
3116 %!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
|
3117 %!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
|
3118 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3119 %!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
|
3120 %!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
|
3121 %!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
|
3122 %!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
|
3123 %!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
|
3124 %!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
|
3125 %!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
|
3126 %!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
|
3127 %!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
|
3128 %!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
|
3129 %!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
|
3130 %!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
|
3131 %!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
|
3132 %!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
|
3133 %!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
|
3134 %!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
|
3135 %!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
|
3136 %!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
|
3137 %!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
|
3138 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3139 %!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
|
3140 %!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
|
3141 %!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
|
3142 %!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
|
3143 %!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
|
3144 %!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
|
3145 %!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
|
3146 %!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
|
3147 %!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
|
3148 %!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
|
3149 %!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
|
3150 %!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
|
3151 %!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
|
3152 %!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
|
3153 %!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
|
3154 %!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
|
3155 %!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
|
3156 %!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
|
3157 %!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
|
3158 |
18891
5baada25d5a2
Rewrite docstring of sum() to match prod().
Rik <rik@octave.org>
parents:
18890
diff
changeset
|
3159 ## Test "native" |
5baada25d5a2
Rewrite docstring of sum() to match prod().
Rik <rik@octave.org>
parents:
18890
diff
changeset
|
3160 %!assert (sum ([true,true]), 2) |
5baada25d5a2
Rewrite docstring of sum() to match prod().
Rik <rik@octave.org>
parents:
18890
diff
changeset
|
3161 %!assert (sum ([true,true], "native"), true) |
5baada25d5a2
Rewrite docstring of sum() to match prod().
Rik <rik@octave.org>
parents:
18890
diff
changeset
|
3162 %!assert (sum (int8 ([127,10,-20])), 117) |
5baada25d5a2
Rewrite docstring of sum() to match prod().
Rik <rik@octave.org>
parents:
18890
diff
changeset
|
3163 %!assert (sum (int8 ([127,10,-20]), "native"), int8 (107)) |
5baada25d5a2
Rewrite docstring of sum() to match prod().
Rik <rik@octave.org>
parents:
18890
diff
changeset
|
3164 |
15623
d928ad126b66
maint: add a new test for Fsum corresponding to cset e9d842dcfc91
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15621
diff
changeset
|
3165 ;-) |
d928ad126b66
maint: add a new test for Fsum corresponding to cset e9d842dcfc91
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15621
diff
changeset
|
3166 %!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
|
3167 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3168 %!error sum () |
18891
5baada25d5a2
Rewrite docstring of sum() to match prod().
Rik <rik@octave.org>
parents:
18890
diff
changeset
|
3169 %!error sum (1,2,3) |
5baada25d5a2
Rewrite docstring of sum() to match prod().
Rik <rik@octave.org>
parents:
18890
diff
changeset
|
3170 %!error <unrecognized type argument 'foobar'> sum (1, "foobar") |
7112 | 3171 */ |
3172 | |
1957 | 3173 DEFUN (sumsq, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3174 "-*- texinfo -*-\n\ |
9163
9cb0c21e97f7
Update section 17.4 (Sums and Products) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9155
diff
changeset
|
3175 @deftypefn {Built-in Function} {} sumsq (@var{x})\n\ |
9cb0c21e97f7
Update section 17.4 (Sums and Products) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9155
diff
changeset
|
3176 @deftypefnx {Built-in Function} {} sumsq (@var{x}, @var{dim})\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
3177 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:
20068
diff
changeset
|
3178 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
3179 If @var{dim} is omitted, it defaults to the first non-singleton dimension.\n\ |
5061 | 3180 \n\ |
3181 This function is conceptually equivalent to computing\n\ | |
10840 | 3182 \n\ |
3723 | 3183 @example\n\ |
3184 sum (x .* conj (x), dim)\n\ | |
3185 @end example\n\ | |
10840 | 3186 \n\ |
10846
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10840
diff
changeset
|
3187 @noindent\n\ |
9163
9cb0c21e97f7
Update section 17.4 (Sums and Products) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9155
diff
changeset
|
3188 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
|
3189 @seealso{sum, prod}\n\ |
3428 | 3190 @end deftypefn") |
523 | 3191 { |
3723 | 3192 DATA_REDUCTION (sumsq); |
523 | 3193 } |
3194 | |
7815
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
3195 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3196 %!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
|
3197 %!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
|
3198 %!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
|
3199 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3200 %!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
|
3201 %!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
|
3202 %!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
|
3203 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3204 %!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
|
3205 %!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
|
3206 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3207 %!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
|
3208 %!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
|
3209 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3210 %!error sumsq () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3211 */ |
7815
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
3212 |
6688 | 3213 DEFUN (islogical, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3214 "-*- texinfo -*-\n\ |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11422
diff
changeset
|
3215 @deftypefn {Built-in Function} {} islogical (@var{x})\n\ |
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11422
diff
changeset
|
3216 @deftypefnx {Built-in Function} {} isbool (@var{x})\n\ |
6688 | 3217 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
|
3218 @seealso{isfloat, isinteger, ischar, isnumeric, isa}\n\ |
3439 | 3219 @end deftypefn") |
3209 | 3220 { |
3221 octave_value retval; | |
3222 | |
3223 if (args.length () == 1) | |
3258 | 3224 retval = args(0).is_bool_type (); |
3209 | 3225 else |
5823 | 3226 print_usage (); |
3209 | 3227 |
3228 return retval; | |
3229 } | |
3230 | |
6688 | 3231 DEFALIAS (isbool, islogical); |
3209 | 3232 |
7815
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
3233 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3234 %!assert (islogical (true), true) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3235 %!assert (islogical (false), true) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3236 %!assert (islogical ([true, false]), true) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3237 %!assert (islogical (1), false) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3238 %!assert (islogical (1i), false) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3239 %!assert (islogical ([1,1]), false) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3240 %!assert (islogical (single (1)), false) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3241 %!assert (islogical (single (1i)), false) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3242 %!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
|
3243 %!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
|
3244 %!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
|
3245 */ |
7815
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
3246 |
6223 | 3247 DEFUN (isinteger, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3248 "-*- texinfo -*-\n\ |
6230 | 3249 @deftypefn {Built-in Function} {} isinteger (@var{x})\n\ |
6223 | 3250 Return true if @var{x} is an integer object (int8, uint8, int16, etc.).\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
3251 \n\ |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11422
diff
changeset
|
3252 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
|
3253 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
|
3254 @seealso{isfloat, ischar, islogical, isnumeric, isa}\n\ |
6223 | 3255 @end deftypefn") |
3256 { | |
3257 octave_value retval; | |
3258 | |
3259 if (args.length () == 1) | |
3260 retval = args(0).is_integer_type (); | |
3261 else | |
3262 print_usage (); | |
3263 | |
3264 return retval; | |
3265 } | |
3266 | |
4028 | 3267 DEFUN (iscomplex, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3268 "-*- texinfo -*-\n\ |
4028 | 3269 @deftypefn {Built-in Function} {} iscomplex (@var{x})\n\ |
3428 | 3270 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
|
3271 @seealso{isreal, isnumeric, islogical, ischar, isfloat, isa}\n\ |
3428 | 3272 @end deftypefn") |
3186 | 3273 { |
3274 octave_value retval; | |
3275 | |
3276 if (args.length () == 1) | |
3258 | 3277 retval = args(0).is_complex_type (); |
3186 | 3278 else |
5823 | 3279 print_usage (); |
3186 | 3280 |
3281 return retval; | |
3282 } | |
3283 | |
7576 | 3284 DEFUN (isfloat, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3285 "-*- texinfo -*-\n\ |
7576 | 3286 @deftypefn {Built-in Function} {} isfloat (@var{x})\n\ |
3287 Return true if @var{x} is a floating-point numeric object.\n\ | |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
3288 \n\ |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11422
diff
changeset
|
3289 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
|
3290 @seealso{isinteger, ischar, islogical, isnumeric, isa}\n\ |
7576 | 3291 @end deftypefn") |
3292 { | |
3293 octave_value retval; | |
3294 | |
3295 if (args.length () == 1) | |
3296 retval = args(0).is_float_type (); | |
3297 else | |
3298 print_usage (); | |
3299 | |
3300 return retval; | |
3301 } | |
3302 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3303 // FIXME: perhaps this should be implemented with an |
5476 | 3304 // octave_value member function? |
3305 | |
3306 DEFUN (complex, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3307 "-*- texinfo -*-\n\ |
9309
fb8b8589dd46
Expand documentation for 'complex' function
Rik <rdrider0-list@yahoo.com>
parents:
9308
diff
changeset
|
3308 @deftypefn {Built-in Function} {} complex (@var{x})\n\ |
5476 | 3309 @deftypefnx {Built-in Function} {} complex (@var{re}, @var{im})\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
3310 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:
20068
diff
changeset
|
3311 \n\ |
20780
c6059134f5d3
data.cc: Add @w{} around @code segments in docstrings to prevent line breaks.
Rik <rik@octave.org>
parents:
20608
diff
changeset
|
3312 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:
20608
diff
changeset
|
3313 @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:
20608
diff
changeset
|
3314 \n\ |
c6059134f5d3
data.cc: Add @w{} around @code segments in docstrings to prevent line breaks.
Rik <rik@octave.org>
parents:
20608
diff
changeset
|
3315 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:
20608
diff
changeset
|
3316 @w{@code{@var{re} + @var{im}}}.\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
3317 @code{complex} can often be more convenient than expressions such as\n\ |
20780
c6059134f5d3
data.cc: Add @w{} around @code segments in docstrings to prevent line breaks.
Rik <rik@octave.org>
parents:
20608
diff
changeset
|
3318 @w{@code{a + i*b}}.\n\ |
9309
fb8b8589dd46
Expand documentation for 'complex' function
Rik <rdrider0-list@yahoo.com>
parents:
9308
diff
changeset
|
3319 For example:\n\ |
fb8b8589dd46
Expand documentation for 'complex' function
Rik <rdrider0-list@yahoo.com>
parents:
9308
diff
changeset
|
3320 \n\ |
fb8b8589dd46
Expand documentation for 'complex' function
Rik <rdrider0-list@yahoo.com>
parents:
9308
diff
changeset
|
3321 @example\n\ |
9758
09da0bd91412
Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents:
9736
diff
changeset
|
3322 @group\n\ |
9309
fb8b8589dd46
Expand documentation for 'complex' function
Rik <rdrider0-list@yahoo.com>
parents:
9308
diff
changeset
|
3323 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
|
3324 @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
|
3325 @end group\n\ |
9309
fb8b8589dd46
Expand documentation for 'complex' function
Rik <rdrider0-list@yahoo.com>
parents:
9308
diff
changeset
|
3326 @end example\n\ |
15028
397f0d80bd47
Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents:
15024
diff
changeset
|
3327 @seealso{real, imag, iscomplex, abs, arg}\n\ |
5476 | 3328 @end deftypefn") |
3329 { | |
3330 octave_value retval; | |
3331 | |
3332 int nargin = args.length (); | |
3333 | |
3334 if (nargin == 1) | |
3335 { | |
3336 octave_value arg = args(0); | |
3337 | |
3338 if (arg.is_complex_type ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3339 retval = arg; |
5476 | 3340 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3341 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3342 if (arg.is_sparse_type ()) |
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 SparseComplexMatrix val = arg.sparse_complex_matrix_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3345 |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3346 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
|
3347 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3348 else if (arg.is_single_type ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3349 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3350 if (arg.numel () == 1) |
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 FloatComplex val = arg.float_complex_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3353 |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3354 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
|
3355 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3356 else |
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 FloatComplexNDArray val = arg.float_complex_array_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3359 |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3360 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
|
3361 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3362 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3363 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3364 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3365 if (arg.numel () == 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3366 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3367 Complex val = arg.complex_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3368 |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3369 retval = octave_value (new octave_complex (val)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3370 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3371 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3372 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3373 ComplexNDArray val = arg.complex_array_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3374 |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3375 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
|
3376 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3377 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3378 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3379 if (error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3380 error ("complex: invalid conversion"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3381 } |
5476 | 3382 } |
3383 else if (nargin == 2) | |
3384 { | |
3385 octave_value re = args(0); | |
3386 octave_value im = args(1); | |
3387 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7743
diff
changeset
|
3388 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
|
3389 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3390 const SparseMatrix re_val = re.sparse_matrix_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3391 const SparseMatrix im_val = im.sparse_matrix_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3392 |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3393 if (re.numel () == 1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3394 { |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3395 SparseComplexMatrix result; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3396 if (re_val.nnz () == 0) |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3397 result = Complex (0, 1) * SparseComplexMatrix (im_val); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3398 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3399 { |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3400 octave_idx_type nr = im_val.rows (); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3401 octave_idx_type nc = im_val.cols (); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3402 result = SparseComplexMatrix (nr, nc, re_val(0)); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3403 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3404 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
|
3405 { |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3406 octave_idx_type off = j * nr; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3407 for (octave_idx_type i = im_val.cidx (j); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3408 i < im_val.cidx (j + 1); i++) |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3409 result.data (im_val.ridx (i) + off) += |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3410 Complex (0, im_val.data (i)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3411 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3412 } |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3413 retval = octave_value (new octave_sparse_complex_matrix (result)); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3414 } |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3415 else if (im.numel () == 1) |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3416 { |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3417 SparseComplexMatrix result; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3418 if (im_val.nnz () == 0) |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3419 result = SparseComplexMatrix (re_val); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3420 else |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3421 { |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3422 octave_idx_type nr = re_val.rows (); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3423 octave_idx_type nc = re_val.cols (); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3424 result = SparseComplexMatrix (nr, nc, |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3425 Complex (0, im_val(0))); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3426 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3427 for (octave_idx_type j = 0; j < nc; j++) |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3428 { |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3429 octave_idx_type off = j * nr; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3430 for (octave_idx_type i = re_val.cidx (j); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3431 i < re_val.cidx (j + 1); i++) |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3432 result.data (re_val.ridx (i) + off) += |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3433 re_val.data (i); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3434 } |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3435 } |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3436 retval = octave_value (new octave_sparse_complex_matrix (result)); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3437 } |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3438 else |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3439 { |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3440 if (re_val.dims () == im_val.dims ()) |
10315
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 SparseComplexMatrix result; |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3443 result = SparseComplexMatrix (re_val) |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3444 + Complex (0, 1) * SparseComplexMatrix (im_val); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3445 retval = octave_value ( |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3446 new octave_sparse_complex_matrix (result)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3447 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3448 else |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3449 error ("complex: dimension mismatch"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3450 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3451 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7743
diff
changeset
|
3452 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
|
3453 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3454 if (re.numel () == 1) |
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 float re_val = re.float_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.double_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3461 |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3462 retval = octave_value (new octave_float_complex |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3463 (FloatComplex (re_val, im_val))); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3464 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3465 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3466 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3467 const FloatNDArray im_val = im.float_array_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3468 |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3469 FloatComplexNDArray result (im_val.dims (), |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3470 FloatComplex ()); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3471 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3472 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:
20749
diff
changeset
|
3473 result.xelem (i) = FloatComplex (re_val, im_val(i)); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3474 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3475 retval = octave_value (new octave_float_complex_matrix |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3476 (result)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3477 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3478 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3479 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3480 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3481 const FloatNDArray re_val = re.float_array_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3482 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3483 if (im.numel () == 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3484 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3485 float im_val = im.float_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3486 |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3487 FloatComplexNDArray result (re_val.dims (), |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3488 FloatComplex ()); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3489 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3490 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:
20749
diff
changeset
|
3491 result.xelem (i) = FloatComplex (re_val(i), im_val); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3492 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3493 retval = octave_value (new octave_float_complex_matrix |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3494 (result)); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3495 } |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3496 else |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3497 { |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3498 const FloatNDArray im_val = im.float_array_value (); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3499 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3500 if (re_val.dims () == im_val.dims ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3501 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3502 FloatComplexNDArray result (re_val.dims (), |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3503 FloatComplex ()); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3504 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3505 for (octave_idx_type i = 0; i < re_val.numel (); i++) |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3506 result.xelem (i) = FloatComplex (re_val(i), |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3507 im_val(i)); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3508 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3509 retval = octave_value (new octave_float_complex_matrix |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3510 (result)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3511 } |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3512 else |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3513 error ("complex: dimension mismatch"); |
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 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3516 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7743
diff
changeset
|
3517 else if (re.numel () == 1) |
10315
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 re_val = re.double_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3520 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3521 if (im.numel () == 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3522 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3523 double im_val = im.double_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3524 |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3525 retval = octave_value (new octave_complex |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3526 (Complex (re_val, im_val))); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3527 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3528 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 |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3532 ComplexNDArray result (im_val.dims (), Complex ()); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3533 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3534 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:
20749
diff
changeset
|
3535 result.xelem (i) = Complex (re_val, im_val(i)); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3536 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3537 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
|
3538 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3539 } |
5476 | 3540 else |
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 const NDArray re_val = re.array_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3543 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3544 if (im.numel () == 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3545 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3546 double im_val = im.double_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3547 |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3548 ComplexNDArray result (re_val.dims (), Complex ()); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3549 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3550 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:
20749
diff
changeset
|
3551 result.xelem (i) = Complex (re_val(i), im_val); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3552 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3553 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
|
3554 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3555 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3556 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3557 const NDArray im_val = im.array_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3558 |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3559 if (re_val.dims () == im_val.dims ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3560 { |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3561 ComplexNDArray result (re_val.dims (), Complex ()); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3562 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3563 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:
20749
diff
changeset
|
3564 result.xelem (i) = Complex (re_val(i), im_val(i)); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3565 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3566 retval = octave_value ( |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3567 new octave_complex_matrix (result)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3568 } |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3569 else |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3570 error ("complex: dimension mismatch"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3571 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3572 } |
5476 | 3573 |
3574 if (error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3575 error ("complex: invalid conversion"); |
5476 | 3576 } |
3577 else | |
5823 | 3578 print_usage (); |
5476 | 3579 |
3580 return retval; | |
3581 } | |
3582 | |
3258 | 3583 DEFUN (isreal, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3584 "-*- texinfo -*-\n\ |
3428 | 3585 @deftypefn {Built-in Function} {} isreal (@var{x})\n\ |
10291
fc879f361bda
make isreal matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10290
diff
changeset
|
3586 Return true if @var{x} is a non-complex matrix or scalar.\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
3587 \n\ |
10711
fbd7843974fa
Periodic grammar check of documentation files to ensure common format.
Rik <octave@nomad.inbox5.com>
parents:
10707
diff
changeset
|
3588 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
|
3589 matrices.\n\ |
15028
397f0d80bd47
Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents:
15024
diff
changeset
|
3590 @seealso{iscomplex, isnumeric, isa}\n\ |
3428 | 3591 @end deftypefn") |
3258 | 3592 { |
3593 octave_value retval; | |
3594 | |
3595 if (args.length () == 1) | |
3596 retval = args(0).is_real_type (); | |
3597 else | |
5823 | 3598 print_usage (); |
3258 | 3599 |
3600 return retval; | |
3601 } | |
3602 | |
3202 | 3603 DEFUN (isempty, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3604 "-*- texinfo -*-\n\ |
3373 | 3605 @deftypefn {Built-in Function} {} isempty (@var{a})\n\ |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11422
diff
changeset
|
3606 Return true if @var{a} is an empty matrix (any one of its dimensions is\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
3607 zero).\n\ |
15028
397f0d80bd47
Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents:
15024
diff
changeset
|
3608 @seealso{isnull, isa}\n\ |
3373 | 3609 @end deftypefn") |
3202 | 3610 { |
4233 | 3611 octave_value retval = false; |
3202 | 3612 |
3613 if (args.length () == 1) | |
4559 | 3614 retval = args(0).is_empty (); |
3202 | 3615 else |
5823 | 3616 print_usage (); |
3202 | 3617 |
3618 return retval; | |
3619 } | |
3620 | |
16779
8fce0ed4894a
Specialize is_empty and numel methods for sparse matrices (debian bug #706376)
David Bateman <dbateman@free.fr>
parents:
16077
diff
changeset
|
3621 /* |
8fce0ed4894a
Specialize is_empty and numel methods for sparse matrices (debian bug #706376)
David Bateman <dbateman@free.fr>
parents:
16077
diff
changeset
|
3622 %% 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
|
3623 %!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
|
3624 */ |
8fce0ed4894a
Specialize is_empty and numel methods for sparse matrices (debian bug #706376)
David Bateman <dbateman@free.fr>
parents:
16077
diff
changeset
|
3625 |
3206 | 3626 DEFUN (isnumeric, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3627 "-*- texinfo -*-\n\ |
3428 | 3628 @deftypefn {Built-in Function} {} isnumeric (@var{x})\n\ |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11422
diff
changeset
|
3629 Return true if @var{x} is a numeric object, i.e., an integer, real, or\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
3630 complex array.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
3631 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
3632 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
|
3633 @seealso{isinteger, isfloat, isreal, iscomplex, islogical, ischar, iscell, isstruct, isa}\n\ |
3428 | 3634 @end deftypefn") |
3206 | 3635 { |
3636 octave_value retval; | |
3637 | |
3638 if (args.length () == 1) | |
3258 | 3639 retval = args(0).is_numeric_type (); |
3206 | 3640 else |
5823 | 3641 print_usage (); |
3206 | 3642 |
3643 return retval; | |
3644 } | |
3645 | |
11435
20f53b3a558f
Add tests for sparse forms of logical matrices to islogical, isnumeric.
Rik <octave@nomad.inbox5.com>
parents:
11431
diff
changeset
|
3646 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3647 %!assert (isnumeric (1), true) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3648 %!assert (isnumeric (1i), true) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3649 %!assert (isnumeric ([1,1]), true) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3650 %!assert (isnumeric (single (1)), true) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3651 %!assert (isnumeric (single (1i)), true) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3652 %!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
|
3653 %!assert (isnumeric (int8 (1)), true) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3654 %!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
|
3655 %!assert (isnumeric ("Hello World"), false) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3656 %!assert (isnumeric (true), false) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3657 %!assert (isnumeric (false), false) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3658 %!assert (isnumeric ([true, false]), false) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3659 %!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
|
3660 */ |
20f53b3a558f
Add tests for sparse forms of logical matrices to islogical, isnumeric.
Rik <octave@nomad.inbox5.com>
parents:
11431
diff
changeset
|
3661 |
19008
bc52657a7d29
Convert isscalar from an m-file to a built-in function (bug #42422).
Jason Alan Palmer <jalanpalmer@gmail.com>
parents:
19007
diff
changeset
|
3662 DEFUN (isscalar, args, , |
20068
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
20000
diff
changeset
|
3663 "-*- texinfo -*-\n\ |
19008
bc52657a7d29
Convert isscalar from an m-file to a built-in function (bug #42422).
Jason Alan Palmer <jalanpalmer@gmail.com>
parents:
19007
diff
changeset
|
3664 @deftypefn {Built-in Function} {} isscalar (@var{x})\n\ |
bc52657a7d29
Convert isscalar from an m-file to a built-in function (bug #42422).
Jason Alan Palmer <jalanpalmer@gmail.com>
parents:
19007
diff
changeset
|
3665 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:
19007
diff
changeset
|
3666 @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:
19007
diff
changeset
|
3667 @end deftypefn") |
bc52657a7d29
Convert isscalar from an m-file to a built-in function (bug #42422).
Jason Alan Palmer <jalanpalmer@gmail.com>
parents:
19007
diff
changeset
|
3668 { |
bc52657a7d29
Convert isscalar from an m-file to a built-in function (bug #42422).
Jason Alan Palmer <jalanpalmer@gmail.com>
parents:
19007
diff
changeset
|
3669 octave_value retval; |
bc52657a7d29
Convert isscalar from an m-file to a built-in function (bug #42422).
Jason Alan Palmer <jalanpalmer@gmail.com>
parents:
19007
diff
changeset
|
3670 |
bc52657a7d29
Convert isscalar from an m-file to a built-in function (bug #42422).
Jason Alan Palmer <jalanpalmer@gmail.com>
parents:
19007
diff
changeset
|
3671 if (args.length () == 1) |
bc52657a7d29
Convert isscalar from an m-file to a built-in function (bug #42422).
Jason Alan Palmer <jalanpalmer@gmail.com>
parents:
19007
diff
changeset
|
3672 retval = args(0).numel () == 1; |
bc52657a7d29
Convert isscalar from an m-file to a built-in function (bug #42422).
Jason Alan Palmer <jalanpalmer@gmail.com>
parents:
19007
diff
changeset
|
3673 else |
bc52657a7d29
Convert isscalar from an m-file to a built-in function (bug #42422).
Jason Alan Palmer <jalanpalmer@gmail.com>
parents:
19007
diff
changeset
|
3674 print_usage (); |
bc52657a7d29
Convert isscalar from an m-file to a built-in function (bug #42422).
Jason Alan Palmer <jalanpalmer@gmail.com>
parents:
19007
diff
changeset
|
3675 |
bc52657a7d29
Convert isscalar from an m-file to a built-in function (bug #42422).
Jason Alan Palmer <jalanpalmer@gmail.com>
parents:
19007
diff
changeset
|
3676 return retval; |
bc52657a7d29
Convert isscalar from an m-file to a built-in function (bug #42422).
Jason Alan Palmer <jalanpalmer@gmail.com>
parents:
19007
diff
changeset
|
3677 } |
bc52657a7d29
Convert isscalar from an m-file to a built-in function (bug #42422).
Jason Alan Palmer <jalanpalmer@gmail.com>
parents:
19007
diff
changeset
|
3678 |
bc52657a7d29
Convert isscalar from an m-file to a built-in function (bug #42422).
Jason Alan Palmer <jalanpalmer@gmail.com>
parents:
19007
diff
changeset
|
3679 /* |
bc52657a7d29
Convert isscalar from an m-file to a built-in function (bug #42422).
Jason Alan Palmer <jalanpalmer@gmail.com>
parents:
19007
diff
changeset
|
3680 %!assert (isscalar (1)) |
bc52657a7d29
Convert isscalar from an m-file to a built-in function (bug #42422).
Jason Alan Palmer <jalanpalmer@gmail.com>
parents:
19007
diff
changeset
|
3681 %!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:
19007
diff
changeset
|
3682 %!assert (isscalar ([]), false) |
bc52657a7d29
Convert isscalar from an m-file to a built-in function (bug #42422).
Jason Alan Palmer <jalanpalmer@gmail.com>
parents:
19007
diff
changeset
|
3683 %!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:
19007
diff
changeset
|
3684 |
bc52657a7d29
Convert isscalar from an m-file to a built-in function (bug #42422).
Jason Alan Palmer <jalanpalmer@gmail.com>
parents:
19007
diff
changeset
|
3685 %!assert (isscalar ("t")) |
bc52657a7d29
Convert isscalar from an m-file to a built-in function (bug #42422).
Jason Alan Palmer <jalanpalmer@gmail.com>
parents:
19007
diff
changeset
|
3686 %!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:
19007
diff
changeset
|
3687 %!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:
19007
diff
changeset
|
3688 |
bc52657a7d29
Convert isscalar from an m-file to a built-in function (bug #42422).
Jason Alan Palmer <jalanpalmer@gmail.com>
parents:
19007
diff
changeset
|
3689 %!test |
bc52657a7d29
Convert isscalar from an m-file to a built-in function (bug #42422).
Jason Alan Palmer <jalanpalmer@gmail.com>
parents:
19007
diff
changeset
|
3690 %! s.a = 1; |
bc52657a7d29
Convert isscalar from an m-file to a built-in function (bug #42422).
Jason Alan Palmer <jalanpalmer@gmail.com>
parents:
19007
diff
changeset
|
3691 %! assert (isscalar (s)); |
bc52657a7d29
Convert isscalar from an m-file to a built-in function (bug #42422).
Jason Alan Palmer <jalanpalmer@gmail.com>
parents:
19007
diff
changeset
|
3692 |
bc52657a7d29
Convert isscalar from an m-file to a built-in function (bug #42422).
Jason Alan Palmer <jalanpalmer@gmail.com>
parents:
19007
diff
changeset
|
3693 %% Test input validation |
bc52657a7d29
Convert isscalar from an m-file to a built-in function (bug #42422).
Jason Alan Palmer <jalanpalmer@gmail.com>
parents:
19007
diff
changeset
|
3694 %!error isscalar () |
bc52657a7d29
Convert isscalar from an m-file to a built-in function (bug #42422).
Jason Alan Palmer <jalanpalmer@gmail.com>
parents:
19007
diff
changeset
|
3695 %!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:
19007
diff
changeset
|
3696 */ |
bc52657a7d29
Convert isscalar from an m-file to a built-in function (bug #42422).
Jason Alan Palmer <jalanpalmer@gmail.com>
parents:
19007
diff
changeset
|
3697 |
19009
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3698 DEFUN (isvector, args, , |
20068
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
20000
diff
changeset
|
3699 "-*- texinfo -*-\n\ |
19009
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3700 @deftypefn {Function File} {} isvector (@var{x})\n\ |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3701 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:
19008
diff
changeset
|
3702 \n\ |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3703 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:
19008
diff
changeset
|
3704 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:
19008
diff
changeset
|
3705 @seealso{isscalar, ismatrix, size, rows, columns, length}\n\ |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3706 @end deftypefn") |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3707 { |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3708 octave_value retval; |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3709 |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3710 if (args.length () == 1) |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3711 { |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3712 dim_vector sz = args(0).dims (); |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3713 retval = sz.length () == 2 && (sz(0) == 1 || sz(1) == 1); |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3714 } |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3715 else |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3716 print_usage (); |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3717 |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3718 return retval; |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3719 } |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3720 |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3721 /* |
19901
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19898
diff
changeset
|
3722 %!assert (isvector (1), true) |
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19898
diff
changeset
|
3723 %!assert (isvector ([1; 2; 3]), true) |
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19898
diff
changeset
|
3724 %!assert (isvector ([1, 2, 3]), true) |
19009
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3725 %!assert (isvector ([]), false) |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3726 %!assert (isvector ([1, 2; 3, 4]), false) |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3727 |
19901
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19898
diff
changeset
|
3728 %!assert (isvector ("t"), true) |
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19898
diff
changeset
|
3729 %!assert (isvector ("test"), true) |
19009
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3730 %!assert (isvector (["test"; "ing"]), false) |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3731 |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3732 %!test |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3733 %! s.a = 1; |
19901
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19898
diff
changeset
|
3734 %! assert (isvector (s), true); |
19009
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3735 |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3736 %% Test input validation |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3737 %!error isvector () |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3738 %!error isvector ([1, 2], 2) |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3739 */ |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3740 |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3741 DEFUN (isrow, args, , |
20068
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
20000
diff
changeset
|
3742 "-*- texinfo -*-\n\ |
19009
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3743 @deftypefn {Function File} {} isrow (@var{x})\n\ |
20000
ca7599ae464d
doc: Grammarcheck documentation ahead of 4.0 release.
Rik <rik@octave.org>
parents:
19954
diff
changeset
|
3744 Return true if @var{x} is a row vector 1xN with non-negative N.\n\ |
19009
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3745 @seealso{iscolumn, isscalar, isvector, ismatrix}\n\ |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3746 @end deftypefn") |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3747 { |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3748 octave_value retval; |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3749 |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3750 if (args.length () == 1) |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3751 { |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3752 dim_vector sz = args(0).dims (); |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3753 retval = sz.length () == 2 && sz(0) == 1; |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3754 } |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3755 else |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3756 print_usage (); |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3757 |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3758 return retval; |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3759 } |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3760 |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3761 /* |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3762 %!assert (isrow ([1, 2, 3])) |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3763 %!assert (isrow ([1; 2; 3]), false) |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3764 %!assert (isrow (1)) |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3765 %!assert (isrow ([]), false) |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3766 %!assert (isrow ([1, 2; 3, 4]), false) |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3767 |
19901
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19898
diff
changeset
|
3768 %!assert (isrow (ones (1, 0)), true) |
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19898
diff
changeset
|
3769 %!assert (isrow (ones (1, 1)), true) |
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19898
diff
changeset
|
3770 %!assert (isrow (ones (1, 2)), true) |
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19898
diff
changeset
|
3771 %!assert (isrow (ones (1, 1, 1)), true) |
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19898
diff
changeset
|
3772 %!assert (isrow (ones (1, 1, 1, 1)), true) |
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19898
diff
changeset
|
3773 |
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19898
diff
changeset
|
3774 %!assert (isrow (ones (0, 0)), false) |
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19898
diff
changeset
|
3775 %!assert (isrow (ones (1, 1, 0)), false) |
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19898
diff
changeset
|
3776 |
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19898
diff
changeset
|
3777 |
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19898
diff
changeset
|
3778 %!assert (isrow ("t"), true) |
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19898
diff
changeset
|
3779 %!assert (isrow ("test"), true) |
19009
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3780 %!assert (isrow (["test"; "ing"]), false) |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3781 |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3782 %!test |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3783 %! s.a = 1; |
19901
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19898
diff
changeset
|
3784 %! assert (isrow (s), true); |
19009
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3785 |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3786 %% Test input validation |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3787 %!error isrow () |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3788 %!error isrow ([1, 2], 2) |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3789 */ |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3790 |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3791 DEFUN (iscolumn, args, , |
20068
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
20000
diff
changeset
|
3792 "-*- texinfo -*-\n\ |
19009
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3793 @deftypefn {Function File} {} iscolumn (@var{x})\n\ |
20000
ca7599ae464d
doc: Grammarcheck documentation ahead of 4.0 release.
Rik <rik@octave.org>
parents:
19954
diff
changeset
|
3794 Return true if @var{x} is a column vector Nx1 with non-negative N.\n\ |
19009
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3795 @seealso{isrow, isscalar, isvector, ismatrix}\n\ |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3796 @end deftypefn") |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3797 { |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3798 octave_value retval; |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3799 |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3800 if (args.length () == 1) |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3801 { |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3802 dim_vector sz = args(0).dims (); |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3803 retval = sz.length () == 2 && sz(1) == 1; |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3804 } |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3805 else |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3806 print_usage (); |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3807 |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3808 return retval; |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3809 } |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3810 |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3811 /* |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3812 %!assert (iscolumn ([1, 2, 3]), false) |
19901
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19898
diff
changeset
|
3813 %!assert (iscolumn ([1; 2; 3]), true) |
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19898
diff
changeset
|
3814 %!assert (iscolumn (1), true) |
19009
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3815 %!assert (iscolumn ([]), false) |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3816 %!assert (iscolumn ([1, 2; 3, 4]), false) |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3817 |
19901
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19898
diff
changeset
|
3818 %!assert (iscolumn ("t"), true) |
19009
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3819 %!assert (iscolumn ("test"), false) |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3820 %!assert (iscolumn (["test"; "ing"]), false) |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3821 |
19901
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19898
diff
changeset
|
3822 %!assert (iscolumn (ones (0, 1)), true) |
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19898
diff
changeset
|
3823 %!assert (iscolumn (ones (1, 1)), true) |
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19898
diff
changeset
|
3824 %!assert (iscolumn (ones (2, 1)), true) |
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19898
diff
changeset
|
3825 %!assert (iscolumn (ones (1, 1, 1)), true) |
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19898
diff
changeset
|
3826 %!assert (iscolumn (ones (1, 1, 1, 1)), true) |
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19898
diff
changeset
|
3827 |
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19898
diff
changeset
|
3828 %!assert (iscolumn (ones (0, 0)), false) |
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19898
diff
changeset
|
3829 %!assert (iscolumn (ones (0, 1, 0)), false) |
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19898
diff
changeset
|
3830 |
19009
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3831 %!test |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3832 %! s.a = 1; |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3833 %! assert (iscolumn (s)); |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3834 |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3835 %% Test input validation |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3836 %!error iscolumn () |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3837 %!error iscolumn ([1, 2], 2) |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3838 */ |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3839 |
4028 | 3840 DEFUN (ismatrix, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3841 "-*- texinfo -*-\n\ |
4028 | 3842 @deftypefn {Built-in Function} {} ismatrix (@var{a})\n\ |
20000
ca7599ae464d
doc: Grammarcheck documentation ahead of 4.0 release.
Rik <rik@octave.org>
parents:
19954
diff
changeset
|
3843 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
|
3844 @seealso{isscalar, isvector, iscell, isstruct, issparse, isa}\n\ |
3333 | 3845 @end deftypefn") |
3202 | 3846 { |
4233 | 3847 octave_value retval = false; |
3202 | 3848 |
3849 if (args.length () == 1) | |
3850 { | |
19901
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19898
diff
changeset
|
3851 dim_vector sz = args(0).dims (); |
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19898
diff
changeset
|
3852 retval = (sz.length () == 2) && (sz(0) >= 0) && (sz(1) >= 0); |
3202 | 3853 } |
3854 else | |
5823 | 3855 print_usage (); |
3202 | 3856 |
3857 return retval; | |
3858 } | |
3859 | |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3860 /* |
19901
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19898
diff
changeset
|
3861 %!assert (ismatrix ([]), true) |
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19898
diff
changeset
|
3862 %!assert (ismatrix (1), true) |
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19898
diff
changeset
|
3863 %!assert (ismatrix ([1, 2, 3]), true) |
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19898
diff
changeset
|
3864 %!assert (ismatrix ([1, 2; 3, 4]), true) |
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19898
diff
changeset
|
3865 |
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19898
diff
changeset
|
3866 %!assert (ismatrix (zeros (0)), true) |
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19898
diff
changeset
|
3867 %!assert (ismatrix (zeros (0, 0)), true) |
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19898
diff
changeset
|
3868 %!assert (ismatrix (zeros (0, 0, 0)), false) |
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19898
diff
changeset
|
3869 %!assert (ismatrix (zeros (3, 2, 4)), false) |
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19898
diff
changeset
|
3870 |
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19898
diff
changeset
|
3871 %!assert (ismatrix (single ([])), true) |
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19898
diff
changeset
|
3872 %!assert (ismatrix (single (1)), true) |
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19898
diff
changeset
|
3873 %!assert (ismatrix (single ([1, 2, 3])), true) |
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19898
diff
changeset
|
3874 %!assert (ismatrix (single ([1, 2; 3, 4])), true) |
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19898
diff
changeset
|
3875 |
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19898
diff
changeset
|
3876 %!assert (ismatrix ("t"), true) |
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19898
diff
changeset
|
3877 %!assert (ismatrix ("test"), true) |
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19898
diff
changeset
|
3878 %!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
|
3879 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3880 %!test |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3881 %! s.a = 1; |
19901
00e31f316a3a
Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
19898
diff
changeset
|
3882 %! assert (ismatrix (s), true); |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3883 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3884 %!error ismatrix () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3885 %!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
|
3886 */ |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3887 |
19009
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3888 DEFUN (issquare, args, , |
20068
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
20000
diff
changeset
|
3889 "-*- texinfo -*-\n\ |
19009
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3890 @deftypefn {Function File} {} issquare (@var{x})\n\ |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3891 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:
19008
diff
changeset
|
3892 @seealso{isscalar, isvector, ismatrix, size}\n\ |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3893 @end deftypefn") |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3894 { |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3895 octave_value retval; |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3896 |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3897 if (args.length () == 1) |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3898 { |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3899 dim_vector sz = args(0).dims (); |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3900 retval = sz.length () == 2 && sz(0) == sz(1); |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3901 } |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3902 else |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3903 print_usage (); |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3904 |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3905 return retval; |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3906 } |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3907 |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3908 /* |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3909 %!assert (issquare ([])) |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3910 %!assert (issquare (1)) |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3911 %!assert (! issquare ([1, 2])) |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3912 %!assert (issquare ([1, 2; 3, 4])) |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3913 %!assert (! issquare ([1, 2; 3, 4; 5, 6])) |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3914 %!assert (! issquare (ones (3,3,3))) |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3915 %!assert (issquare ("t")) |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3916 %!assert (! issquare ("test")) |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3917 %!assert (issquare (["test"; "ing"; "1"; "2"])) |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3918 %!test |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3919 %! s.a = 1; |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3920 %! assert (issquare (s)); |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3921 %!assert (issquare ({1, 2; 3, 4})) |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3922 %!assert (sparse (([1, 2; 3, 4]))) |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3923 |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3924 %% Test input validation |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3925 %!error issquare () |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3926 %!error issquare ([1, 2; 3, 4], 2) |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3927 */ |
4f0e4f20a33f
Promote isvector, isrow, iscolumn, issquare to C++ versions (bug #42454).
Rik <rik@octave.org>
parents:
19008
diff
changeset
|
3928 |
3354 | 3929 static octave_value |
5747 | 3930 fill_matrix (const octave_value_list& args, int val, const char *fcn) |
523 | 3931 { |
3354 | 3932 octave_value retval; |
523 | 3933 |
3934 int nargin = args.length (); | |
3935 | |
4946 | 3936 oct_data_conv::data_type dt = oct_data_conv::dt_double; |
4481 | 3937 |
4946 | 3938 dim_vector dims (1, 1); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
3939 |
4481 | 3940 if (nargin > 0 && args(nargin-1).is_string ()) |
3941 { | |
4946 | 3942 std::string nm = args(nargin-1).string_value (); |
4481 | 3943 nargin--; |
3944 | |
4946 | 3945 dt = oct_data_conv::string_to_data_type (nm); |
4481 | 3946 } |
3947 | |
523 | 3948 switch (nargin) |
3949 { | |
712 | 3950 case 0: |
3951 break; | |
777 | 3952 |
610 | 3953 case 1: |
4481 | 3954 get_dimensions (args(0), fcn, dims); |
610 | 3955 break; |
777 | 3956 |
4563 | 3957 default: |
3958 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3959 dims.resize (nargin); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3960 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3961 for (int i = 0; i < nargin; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3962 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3963 dims(i) = args(i).is_empty () ? 0 : args(i).idx_type_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3964 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3965 if (error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3966 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3967 error ("%s: expecting scalar integer arguments", fcn); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3968 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3969 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3970 } |
4563 | 3971 } |
3972 break; | |
4481 | 3973 } |
3974 | |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3975 dims.chop_trailing_singletons (); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3976 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3977 check_dimensions (dims, fcn); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3978 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3979 // FIXME: perhaps this should be made extensible by |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3980 // 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:
20749
diff
changeset
|
3981 // the new value. |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3982 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3983 // Note that automatic narrowing will handle conversion from |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3984 // NDArray to scalar. |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3985 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3986 switch (dt) |
4481 | 3987 { |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3988 case oct_data_conv::dt_int8: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3989 retval = int8NDArray (dims, val); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3990 break; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3991 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3992 case oct_data_conv::dt_uint8: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3993 retval = uint8NDArray (dims, val); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3994 break; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3995 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3996 case oct_data_conv::dt_int16: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3997 retval = int16NDArray (dims, val); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3998 break; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
3999 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4000 case oct_data_conv::dt_uint16: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4001 retval = uint16NDArray (dims, val); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4002 break; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4003 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4004 case oct_data_conv::dt_int32: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4005 retval = int32NDArray (dims, val); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4006 break; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4007 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4008 case oct_data_conv::dt_uint32: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4009 retval = uint32NDArray (dims, val); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4010 break; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4011 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4012 case oct_data_conv::dt_int64: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4013 retval = int64NDArray (dims, val); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4014 break; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4015 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4016 case oct_data_conv::dt_uint64: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4017 retval = uint64NDArray (dims, val); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4018 break; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4019 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4020 case oct_data_conv::dt_single: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4021 retval = FloatNDArray (dims, val); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4022 break; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4023 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4024 case oct_data_conv::dt_double: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4025 { |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4026 if (val == 1 && dims.length () == 2 && dims(0) == 1) |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4027 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:
20749
diff
changeset
|
4028 else |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4029 retval = NDArray (dims, val); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4030 } |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4031 break; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4032 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4033 case oct_data_conv::dt_logical: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4034 retval = boolNDArray (dims, val); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4035 break; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4036 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4037 default: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4038 error ("%s: invalid class name", fcn); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4039 break; |
523 | 4040 } |
4041 | |
4042 return retval; | |
4043 } | |
4044 | |
5747 | 4045 static octave_value |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
4046 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
|
4047 const char *fcn) |
7795
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4048 { |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4049 octave_value retval; |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4050 |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4051 int nargin = args.length (); |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4052 |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4053 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
|
4054 |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4055 dim_vector dims (1, 1); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
4056 |
7795
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4057 if (nargin > 0 && args(nargin-1).is_string ()) |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4058 { |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4059 std::string nm = args(nargin-1).string_value (); |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4060 nargin--; |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4061 |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4062 dt = oct_data_conv::string_to_data_type (nm); |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4063 } |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4064 |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4065 switch (nargin) |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4066 { |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4067 case 0: |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4068 break; |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4069 |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4070 case 1: |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4071 get_dimensions (args(0), fcn, dims); |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4072 break; |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4073 |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4074 default: |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4075 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4076 dims.resize (nargin); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4077 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4078 for (int i = 0; i < nargin; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4079 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4080 dims(i) = args(i).is_empty () ? 0 : args(i).idx_type_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4081 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4082 if (error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4083 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4084 error ("%s: expecting scalar integer arguments", fcn); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4085 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4086 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4087 } |
7795
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4088 } |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4089 break; |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4090 } |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4091 |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4092 dims.chop_trailing_singletons (); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4093 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4094 check_dimensions (dims, fcn); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4095 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4096 // Note that automatic narrowing will handle conversion from |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4097 // NDArray to scalar. |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4098 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4099 switch (dt) |
7795
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4100 { |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4101 case oct_data_conv::dt_single: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4102 retval = FloatNDArray (dims, fval); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4103 break; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4104 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4105 case oct_data_conv::dt_double: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4106 retval = NDArray (dims, val); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4107 break; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4108 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4109 default: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4110 error ("%s: invalid class name", fcn); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4111 break; |
7795
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4112 } |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4113 |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4114 return retval; |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4115 } |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4116 |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4117 static octave_value |
5747 | 4118 fill_matrix (const octave_value_list& args, double val, const char *fcn) |
4119 { | |
4120 octave_value retval; | |
4121 | |
4122 int nargin = args.length (); | |
4123 | |
4124 oct_data_conv::data_type dt = oct_data_conv::dt_double; | |
4125 | |
4126 dim_vector dims (1, 1); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
4127 |
5747 | 4128 if (nargin > 0 && args(nargin-1).is_string ()) |
4129 { | |
4130 std::string nm = args(nargin-1).string_value (); | |
4131 nargin--; | |
4132 | |
4133 dt = oct_data_conv::string_to_data_type (nm); | |
4134 } | |
4135 | |
4136 switch (nargin) | |
4137 { | |
4138 case 0: | |
4139 break; | |
4140 | |
4141 case 1: | |
4142 get_dimensions (args(0), fcn, dims); | |
4143 break; | |
4144 | |
4145 default: | |
4146 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4147 dims.resize (nargin); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4148 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4149 for (int i = 0; i < nargin; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4150 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4151 dims(i) = args(i).is_empty () ? 0 : args(i).idx_type_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4152 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4153 if (error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4154 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4155 error ("%s: expecting scalar integer arguments", fcn); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4156 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4157 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4158 } |
5747 | 4159 } |
4160 break; | |
4161 } | |
4162 | |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4163 dims.chop_trailing_singletons (); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4164 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4165 check_dimensions (dims, fcn); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4166 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4167 // Note that automatic narrowing will handle conversion from |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4168 // NDArray to scalar. |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4169 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4170 switch (dt) |
5747 | 4171 { |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4172 case oct_data_conv::dt_single: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4173 retval = FloatNDArray (dims, static_cast<float> (val)); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4174 break; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4175 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4176 case oct_data_conv::dt_double: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4177 retval = NDArray (dims, val); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4178 break; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4179 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4180 default: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4181 error ("%s: invalid class name", fcn); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4182 break; |
5747 | 4183 } |
4184 | |
4185 return retval; | |
4186 } | |
4187 | |
4188 static octave_value | |
4189 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
|
4190 const char *fcn) |
5747 | 4191 { |
4192 octave_value retval; | |
4193 | |
4194 int nargin = args.length (); | |
4195 | |
4196 oct_data_conv::data_type dt = oct_data_conv::dt_double; | |
4197 | |
4198 dim_vector dims (1, 1); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
4199 |
5747 | 4200 if (nargin > 0 && args(nargin-1).is_string ()) |
4201 { | |
4202 std::string nm = args(nargin-1).string_value (); | |
4203 nargin--; | |
4204 | |
4205 dt = oct_data_conv::string_to_data_type (nm); | |
4206 } | |
4207 | |
4208 switch (nargin) | |
4209 { | |
4210 case 0: | |
4211 break; | |
4212 | |
4213 case 1: | |
4214 get_dimensions (args(0), fcn, dims); | |
4215 break; | |
4216 | |
4217 default: | |
4218 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4219 dims.resize (nargin); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4220 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4221 for (int i = 0; i < nargin; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4222 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4223 dims(i) = args(i).is_empty () ? 0 : args(i).idx_type_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4224 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4225 if (error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4226 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4227 error ("%s: expecting scalar integer arguments", fcn); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4228 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4229 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4230 } |
5747 | 4231 } |
4232 break; | |
4233 } | |
4234 | |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4235 dims.chop_trailing_singletons (); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4236 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4237 check_dimensions (dims, fcn); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4238 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4239 // Note that automatic narrowing will handle conversion from |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4240 // NDArray to scalar. |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4241 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4242 switch (dt) |
5747 | 4243 { |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4244 case oct_data_conv::dt_single: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4245 retval = FloatComplexNDArray (dims, |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4246 static_cast<FloatComplex> (val)); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4247 break; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4248 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4249 case oct_data_conv::dt_double: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4250 retval = ComplexNDArray (dims, val); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4251 break; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4252 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4253 default: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4254 error ("%s: invalid class name", fcn); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4255 break; |
5747 | 4256 } |
4257 | |
4258 return retval; | |
4259 } | |
4260 | |
4261 static octave_value | |
4262 fill_matrix (const octave_value_list& args, bool val, const char *fcn) | |
4263 { | |
4264 octave_value retval; | |
4265 | |
4266 int nargin = args.length (); | |
4267 | |
4268 dim_vector dims (1, 1); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
4269 |
5747 | 4270 switch (nargin) |
4271 { | |
4272 case 0: | |
4273 break; | |
4274 | |
4275 case 1: | |
4276 get_dimensions (args(0), fcn, dims); | |
4277 break; | |
4278 | |
4279 default: | |
4280 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4281 dims.resize (nargin); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4282 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4283 for (int i = 0; i < nargin; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4284 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4285 dims(i) = args(i).is_empty () ? 0 : args(i).idx_type_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4286 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4287 if (error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4288 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4289 error ("%s: expecting scalar integer arguments", fcn); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4290 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4291 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4292 } |
5747 | 4293 } |
4294 break; | |
4295 } | |
4296 | |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4297 dims.chop_trailing_singletons (); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4298 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4299 check_dimensions (dims, fcn); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4300 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4301 // Note that automatic narrowing will handle conversion from |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4302 // NDArray to scalar. |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4303 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4304 retval = boolNDArray (dims, val); |
5747 | 4305 |
4306 return retval; | |
4307 } | |
4308 | |
3354 | 4309 DEFUN (ones, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
4310 "-*- texinfo -*-\n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
4311 @deftypefn {Built-in Function} {} ones (@var{n})\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
4312 @deftypefnx {Built-in Function} {} ones (@var{m}, @var{n})\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
4313 @deftypefnx {Built-in Function} {} ones (@var{m}, @var{n}, @var{k}, @dots{})\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
4314 @deftypefnx {Built-in Function} {} ones ([@var{m} @var{n} @dots{}])\n\ |
4948 | 4315 @deftypefnx {Built-in Function} {} ones (@dots{}, @var{class})\n\ |
4481 | 4316 Return a matrix or N-dimensional array whose elements are all 1.\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
4317 \n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
4318 If invoked with a single scalar integer argument @var{n}, return a square\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
4319 @nospell{NxN} matrix.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
4320 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
4321 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:
20068
diff
changeset
|
4322 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:
20068
diff
changeset
|
4323 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
4324 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:
20068
diff
changeset
|
4325 such as\n\ |
3369 | 4326 \n\ |
4327 @example\n\ | |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
4328 val_matrix = val * ones (m, n)\n\ |
3369 | 4329 @end example\n\ |
4945 | 4330 \n\ |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
4331 The optional argument @var{class} specifies the class of the return array\n\ |
10840 | 4332 and defaults to double. For example:\n\ |
4945 | 4333 \n\ |
4334 @example\n\ | |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
4335 val = ones (m,n, \"uint8\")\n\ |
4945 | 4336 @end example\n\ |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
4337 @seealso{zeros}\n\ |
3369 | 4338 @end deftypefn") |
523 | 4339 { |
5747 | 4340 return fill_matrix (args, 1, "ones"); |
523 | 4341 } |
4342 | |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4343 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4344 %!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
|
4345 %!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
|
4346 %!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
|
4347 %!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
|
4348 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4349 %!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
|
4350 %!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
|
4351 %!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
|
4352 %!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
|
4353 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4354 %!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
|
4355 %!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
|
4356 %!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
|
4357 %!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
|
4358 */ |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4359 |
3354 | 4360 DEFUN (zeros, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
4361 "-*- texinfo -*-\n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
4362 @deftypefn {Built-in Function} {} zeros (@var{n})\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
4363 @deftypefnx {Built-in Function} {} zeros (@var{m}, @var{n})\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
4364 @deftypefnx {Built-in Function} {} zeros (@var{m}, @var{n}, @var{k}, @dots{})\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
4365 @deftypefnx {Built-in Function} {} zeros ([@var{m} @var{n} @dots{}])\n\ |
4948 | 4366 @deftypefnx {Built-in Function} {} zeros (@dots{}, @var{class})\n\ |
4481 | 4367 Return a matrix or N-dimensional array whose elements are all 0.\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
4368 \n\ |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
4369 If invoked with a single scalar integer argument, return a square\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
4370 @nospell{NxN} matrix.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
4371 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
4372 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:
20068
diff
changeset
|
4373 values, return an array with the given dimensions.\n\ |
4945 | 4374 \n\ |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
4375 The optional argument @var{class} specifies the class of the return array\n\ |
10840 | 4376 and defaults to double. For example:\n\ |
4945 | 4377 \n\ |
4378 @example\n\ | |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
4379 val = zeros (m,n, \"uint8\")\n\ |
4945 | 4380 @end example\n\ |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
4381 @seealso{ones}\n\ |
3369 | 4382 @end deftypefn") |
523 | 4383 { |
5747 | 4384 return fill_matrix (args, 0, "zeros"); |
4385 } | |
4386 | |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4387 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4388 %!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
|
4389 %!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
|
4390 %!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
|
4391 %!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
|
4392 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4393 %!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
|
4394 %!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
|
4395 %!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
|
4396 %!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
|
4397 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4398 %!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
|
4399 %!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
|
4400 %!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
|
4401 %!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
|
4402 */ |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4403 |
5747 | 4404 DEFUN (Inf, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
4405 "-*- texinfo -*-\n\ |
14171
2ced2f59f523
doc: miscellaneous documentation improvements
Rik <octave@nomad.inbox5.com>
parents:
14169
diff
changeset
|
4406 @c List other form of function in documentation index\n\ |
2ced2f59f523
doc: miscellaneous documentation improvements
Rik <octave@nomad.inbox5.com>
parents:
14169
diff
changeset
|
4407 @findex inf\n\ |
2ced2f59f523
doc: miscellaneous documentation improvements
Rik <octave@nomad.inbox5.com>
parents:
14169
diff
changeset
|
4408 \n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4409 @deftypefn {Built-in Function} {} Inf\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4410 @deftypefnx {Built-in Function} {} Inf (@var{n})\n\ |
5747 | 4411 @deftypefnx {Built-in Function} {} Inf (@var{n}, @var{m})\n\ |
4412 @deftypefnx {Built-in Function} {} Inf (@var{n}, @var{m}, @var{k}, @dots{})\n\ | |
4413 @deftypefnx {Built-in Function} {} 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
|
4414 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
|
4415 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
|
4416 \n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4417 Infinity is produced when results are too large to be represented using the\n\ |
20393
4e7f12a763cd
doc: Remove typo of same word twice in a row.
Rik <rik@octave.org>
parents:
20382
diff
changeset
|
4418 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:
20382
diff
changeset
|
4419 infinity are division by zero and overflow.\n\ |
10840 | 4420 \n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4421 @example\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4422 @group\n\ |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
4423 [ 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
|
4424 @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
|
4425 @end group\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4426 @end example\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4427 \n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4428 When called with no arguments, return a scalar with the value @samp{Inf}.\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
4429 \n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4430 When called with a single argument, return a square matrix with the dimension\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
4431 specified.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
4432 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
4433 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:
20068
diff
changeset
|
4434 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:
20068
diff
changeset
|
4435 additional matrix dimensions.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
4436 \n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4437 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
|
4438 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
|
4439 @seealso{isinf, NaN}\n\ |
5747 | 4440 @end deftypefn") |
4441 { | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
4442 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
|
4443 lo_ieee_float_inf_value (), "Inf"); |
5747 | 4444 } |
4445 | |
4446 DEFALIAS (inf, Inf); | |
4447 | |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4448 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4449 %!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
|
4450 %!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
|
4451 %!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
|
4452 %!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
|
4453 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4454 %!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
|
4455 %!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
|
4456 %!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
|
4457 %!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
|
4458 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4459 %!error (inf (3, "int8")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4460 %!error (inf (2, 3, "int8")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4461 %!error (inf (3, 2, "int8")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4462 %!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
|
4463 */ |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4464 |
5747 | 4465 DEFUN (NaN, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
4466 "-*- texinfo -*-\n\ |
14171
2ced2f59f523
doc: miscellaneous documentation improvements
Rik <octave@nomad.inbox5.com>
parents:
14169
diff
changeset
|
4467 @c List other form of function in documentation index\n\ |
2ced2f59f523
doc: miscellaneous documentation improvements
Rik <octave@nomad.inbox5.com>
parents:
14169
diff
changeset
|
4468 @findex nan\n\ |
2ced2f59f523
doc: miscellaneous documentation improvements
Rik <octave@nomad.inbox5.com>
parents:
14169
diff
changeset
|
4469 \n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4470 @deftypefn {Built-in Function} {} NaN\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4471 @deftypefnx {Built-in Function} {} NaN (@var{n})\n\ |
5747 | 4472 @deftypefnx {Built-in Function} {} NaN (@var{n}, @var{m})\n\ |
4473 @deftypefnx {Built-in Function} {} NaN (@var{n}, @var{m}, @var{k}, @dots{})\n\ | |
4474 @deftypefnx {Built-in Function} {} 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
|
4475 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
|
4476 to the IEEE symbol NaN (Not a Number).\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
4477 \n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4478 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
|
4479 result. Common operations which produce a NaN are arithmetic with infinity\n\ |
5747 | 4480 @tex\n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4481 ($\\infty - \\infty$), zero divided by zero ($0/0$),\n\ |
5747 | 4482 @end tex\n\ |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
8487
diff
changeset
|
4483 @ifnottex\n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4484 (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
|
4485 @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
|
4486 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
|
4487 \n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4488 Note that NaN always compares not equal to NaN (NaN != NaN). This behavior\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
4489 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:
20068
diff
changeset
|
4490 NaN values, use the @code{isnan} function.\n\ |
5747 | 4491 \n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4492 When called with no arguments, return a scalar with the value @samp{NaN}.\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
4493 \n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4494 When called with a single argument, return a square matrix with the dimension\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
4495 specified.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
4496 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
4497 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:
20068
diff
changeset
|
4498 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:
20068
diff
changeset
|
4499 additional matrix dimensions.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
4500 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
4501 \n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4502 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
|
4503 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
|
4504 @seealso{isnan, Inf}\n\ |
5747 | 4505 @end deftypefn") |
4506 { | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
4507 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
|
4508 lo_ieee_float_nan_value (), "NaN"); |
5747 | 4509 } |
4510 | |
4511 DEFALIAS (nan, NaN); | |
4512 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
4513 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4514 %!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
|
4515 %!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
|
4516 %!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
|
4517 %!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
|
4518 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4519 %!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
|
4520 %!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
|
4521 %!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
|
4522 %!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
|
4523 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4524 %!error (NaN (3, "int8")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4525 %!error (NaN (2, 3, "int8")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4526 %!error (NaN (3, 2, "int8")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4527 %!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
|
4528 */ |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4529 |
5747 | 4530 DEFUN (e, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
4531 "-*- texinfo -*-\n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4532 @deftypefn {Built-in Function} {} e\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4533 @deftypefnx {Built-in Function} {} e (@var{n})\n\ |
5747 | 4534 @deftypefnx {Built-in Function} {} e (@var{n}, @var{m})\n\ |
4535 @deftypefnx {Built-in Function} {} e (@var{n}, @var{m}, @var{k}, @dots{})\n\ | |
4536 @deftypefnx {Built-in Function} {} 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
|
4537 Return a scalar, matrix, or N-dimensional array whose elements are all equal\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
4538 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:
20068
diff
changeset
|
4539 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
4540 The constant\n\ |
5747 | 4541 @tex\n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4542 $e$ satisfies the equation $\\log (e) = 1$.\n\ |
5747 | 4543 @end tex\n\ |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
8487
diff
changeset
|
4544 @ifnottex\n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4545 @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
|
4546 @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
|
4547 \n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
4548 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:
20068
diff
changeset
|
4549 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
4550 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:
20068
diff
changeset
|
4551 specified.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
4552 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
4553 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:
20068
diff
changeset
|
4554 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:
20068
diff
changeset
|
4555 additional matrix dimensions.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
4556 \n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4557 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
|
4558 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
|
4559 @seealso{log, exp, pi, I}\n\ |
5747 | 4560 @end deftypefn") |
4561 { | |
4562 #if defined (M_E) | |
4563 double e_val = M_E; | |
4564 #else | |
4565 double e_val = exp (1.0); | |
4566 #endif | |
4567 | |
4568 return fill_matrix (args, e_val, "e"); | |
4569 } | |
4570 | |
4571 DEFUN (eps, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
4572 "-*- texinfo -*-\n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4573 @deftypefn {Built-in Function} {} eps\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4574 @deftypefnx {Built-in Function} {} eps (@var{x})\n\ |
5747 | 4575 @deftypefnx {Built-in Function} {} eps (@var{n}, @var{m})\n\ |
4576 @deftypefnx {Built-in Function} {} eps (@var{n}, @var{m}, @var{k}, @dots{})\n\ | |
4577 @deftypefnx {Built-in Function} {} 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
|
4578 Return a scalar, matrix or N-dimensional array whose elements are all eps,\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
4579 the machine precision.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
4580 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
4581 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:
20068
diff
changeset
|
4582 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:
20068
diff
changeset
|
4583 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:
20068
diff
changeset
|
4584 @code{eps} is approximately\n\ |
5747 | 4585 @tex\n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4586 $2.2204\\times10^{-16}$ for double precision and $1.1921\\times10^{-7}$\n\ |
5747 | 4587 @end tex\n\ |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
8487
diff
changeset
|
4588 @ifnottex\n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4589 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
|
4590 @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
|
4591 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
|
4592 \n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4593 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
|
4594 @code{eps (1.0)}.\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
4595 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
4596 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:
20068
diff
changeset
|
4597 next largest value.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
4598 \n\ |
9197
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 more than one argument the first two arguments are taken as\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
4600 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:
20068
diff
changeset
|
4601 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:
20068
diff
changeset
|
4602 type and may be either @qcode{\"double\"} or @qcode{\"single\"}.\n\ |
20696 | 4603 @seealso{realmax, realmin, intmax, flintmax}\n\ |
5747 | 4604 @end deftypefn") |
4605 { | |
7795
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4606 int nargin = args.length (); |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4607 octave_value retval; |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4608 |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4609 if (nargin == 1 && ! args(0).is_string ()) |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4610 { |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4611 if (args(0).is_single_type ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4612 { |
15509
f0dfdc7faa71
Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15467
diff
changeset
|
4613 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
|
4614 |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4615 Array<float> epsval (x.dims ()); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4616 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4617 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
|
4618 { |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4619 float val = ::fabsf (x(i)); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4620 if (xisnan (val) || xisinf (val)) |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4621 epsval(i) = lo_ieee_nan_value (); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4622 else if (val < std::numeric_limits<float>::min ()) |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4623 epsval(i) = powf (2.0, -149e0); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4624 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4625 { |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4626 int expon; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4627 gnulib::frexpf (val, &expon); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4628 epsval(i) = std::pow (2.0f, |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4629 static_cast<float> (expon - 24)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4630 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4631 } |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4632 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4633 retval = epsval; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4634 } |
7795
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4635 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4636 { |
15509
f0dfdc7faa71
Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15467
diff
changeset
|
4637 Array<double> x = args(0).array_value (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4638 |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4639 Array<double> epsval (x.dims ()); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4640 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4641 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
|
4642 { |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4643 double val = ::fabs (x(i)); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4644 if (xisnan (val) || xisinf (val)) |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4645 epsval(i) = lo_ieee_nan_value (); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4646 else if (val < std::numeric_limits<double>::min ()) |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4647 epsval(i) = pow (2.0, -1074e0); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4648 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4649 { |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4650 int expon; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4651 gnulib::frexp (val, &expon); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4652 epsval(i) = std::pow (2.0, |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4653 static_cast<double> (expon - 53)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4654 } |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4655 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4656 retval = epsval; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4657 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4658 } |
7795
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4659 } |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4660 else |
15213
336f42406671
use numeric_limits functions instead of DBL_MIN, DBL_MAX, etc.
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
4661 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
|
4662 std::numeric_limits<float>::epsilon (), "eps"); |
7795
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4663 |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4664 return retval; |
5747 | 4665 } |
4666 | |
7795
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4667 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4668 %!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
|
4669 %!assert (eps (1), 2^(-52)) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4670 %!assert (eps (2), 2^(-51)) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4671 %!assert (eps (realmax), 2^971) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4672 %!assert (eps (0), 2^(-1074)) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4673 %!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
|
4674 %!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
|
4675 %!assert (eps (Inf), NaN) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4676 %!assert (eps (NaN), NaN) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
4677 %!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
|
4678 %! [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
|
4679 %!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
|
4680 %!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
|
4681 %!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
|
4682 %!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
|
4683 %!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
|
4684 %!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
|
4685 %!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
|
4686 %!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
|
4687 %!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
|
4688 %!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
|
4689 %! 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
|
4690 |
7795
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4691 */ |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4692 |
5747 | 4693 DEFUN (pi, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
4694 "-*- texinfo -*-\n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4695 @deftypefn {Built-in Function} {} pi\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4696 @deftypefnx {Built-in Function} {} pi (@var{n})\n\ |
5747 | 4697 @deftypefnx {Built-in Function} {} pi (@var{n}, @var{m})\n\ |
4698 @deftypefnx {Built-in Function} {} pi (@var{n}, @var{m}, @var{k}, @dots{})\n\ | |
4699 @deftypefnx {Built-in Function} {} 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
|
4700 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
|
4701 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
|
4702 @tex\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4703 diameter($\\pi$).\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4704 @end tex\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4705 @ifnottex\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4706 diameter.\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4707 @end ifnottex\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
4708 \n\ |
5747 | 4709 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
|
4710 \n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4711 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
|
4712 @tex\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4713 $\\pi$.\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4714 @end tex\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4715 @ifnottex\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4716 pi.\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4717 @end ifnottex\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
4718 \n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4719 When called with a single argument, return a square matrix with the dimension\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
4720 specified.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
4721 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
4722 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:
20068
diff
changeset
|
4723 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:
20068
diff
changeset
|
4724 additional matrix dimensions.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
4725 \n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4726 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
|
4727 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
|
4728 @seealso{e, I}\n\ |
5747 | 4729 @end deftypefn") |
4730 { | |
4731 #if defined (M_PI) | |
4732 double pi_val = M_PI; | |
4733 #else | |
4734 double pi_val = 4.0 * atan (1.0); | |
4735 #endif | |
4736 | |
4737 return fill_matrix (args, pi_val, "pi"); | |
4738 } | |
4739 | |
4740 DEFUN (realmax, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
4741 "-*- texinfo -*-\n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4742 @deftypefn {Built-in Function} {} realmax\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4743 @deftypefnx {Built-in Function} {} realmax (@var{n})\n\ |
5747 | 4744 @deftypefnx {Built-in Function} {} realmax (@var{n}, @var{m})\n\ |
4745 @deftypefnx {Built-in Function} {} realmax (@var{n}, @var{m}, @var{k}, @dots{})\n\ | |
4746 @deftypefnx {Built-in Function} {} realmax (@dots{}, @var{class})\n\ | |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
4747 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:
20068
diff
changeset
|
4748 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:
20068
diff
changeset
|
4749 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
4750 The actual value is system dependent. On machines that support IEEE\n\ |
5747 | 4751 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
|
4752 @tex\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4753 $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
|
4754 @end tex\n\ |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
8487
diff
changeset
|
4755 @ifnottex\n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4756 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
|
4757 @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
|
4758 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
|
4759 \n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4760 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
|
4761 @code{realmax (@qcode{\"double\"})}.\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
4762 \n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4763 When called with a single argument, return a square matrix with the dimension\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
4764 specified.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
4765 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
4766 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:
20068
diff
changeset
|
4767 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:
20068
diff
changeset
|
4768 additional matrix dimensions.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
4769 \n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4770 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
|
4771 either @qcode{\"double\"} or @qcode{\"single\"}.\n\ |
20696 | 4772 @seealso{realmin, intmax, flintmax, eps}\n\ |
5747 | 4773 @end deftypefn") |
4774 { | |
15213
336f42406671
use numeric_limits functions instead of DBL_MIN, DBL_MAX, etc.
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
4775 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
|
4776 std::numeric_limits<float>::max (), "realmax"); |
5747 | 4777 } |
4778 | |
4779 DEFUN (realmin, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
4780 "-*- texinfo -*-\n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4781 @deftypefn {Built-in Function} {} realmin\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4782 @deftypefnx {Built-in Function} {} realmin (@var{n})\n\ |
5747 | 4783 @deftypefnx {Built-in Function} {} realmin (@var{n}, @var{m})\n\ |
4784 @deftypefnx {Built-in Function} {} realmin (@var{n}, @var{m}, @var{k}, @dots{})\n\ | |
4785 @deftypefnx {Built-in Function} {} realmin (@dots{}, @var{class})\n\ | |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
4786 Return a scalar, matrix, or N-dimensional array whose elements are all equal\n\ |
5747 | 4787 to the smallest normalized floating point number that is representable.\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
4788 \n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4789 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
|
4790 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
|
4791 @tex\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4792 $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
|
4793 @end tex\n\ |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
8487
diff
changeset
|
4794 @ifnottex\n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4795 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
|
4796 @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
|
4797 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
|
4798 \n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4799 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
|
4800 @code{realmin (@qcode{\"double\"})}.\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
4801 \n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4802 When called with a single argument, return a square matrix with the dimension\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
4803 specified.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
4804 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
4805 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:
20068
diff
changeset
|
4806 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:
20068
diff
changeset
|
4807 additional matrix dimensions.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
4808 \n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4809 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
|
4810 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
|
4811 @seealso{realmax, intmin, eps}\n\ |
5747 | 4812 @end deftypefn") |
4813 { | |
15213
336f42406671
use numeric_limits functions instead of DBL_MIN, DBL_MAX, etc.
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
4814 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
|
4815 std::numeric_limits<float>::min (), "realmin"); |
5747 | 4816 } |
4817 | |
4818 DEFUN (I, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
4819 "-*- texinfo -*-\n\ |
14100
8a2dc08886ea
Fix Info referencing for i, I, j, J (Bug #35157)
Rik <octave@nomad.inbox5.com>
parents:
14085
diff
changeset
|
4820 @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
|
4821 @findex i\n\ |
8a2dc08886ea
Fix Info referencing for i, I, j, J (Bug #35157)
Rik <octave@nomad.inbox5.com>
parents:
14085
diff
changeset
|
4822 @findex j\n\ |
8a2dc08886ea
Fix Info referencing for i, I, j, J (Bug #35157)
Rik <octave@nomad.inbox5.com>
parents:
14085
diff
changeset
|
4823 @findex J\n\ |
8a2dc08886ea
Fix Info referencing for i, I, j, J (Bug #35157)
Rik <octave@nomad.inbox5.com>
parents:
14085
diff
changeset
|
4824 \n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4825 @deftypefn {Built-in Function} {} I\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4826 @deftypefnx {Built-in Function} {} I (@var{n})\n\ |
5747 | 4827 @deftypefnx {Built-in Function} {} I (@var{n}, @var{m})\n\ |
4828 @deftypefnx {Built-in Function} {} I (@var{n}, @var{m}, @var{k}, @dots{})\n\ | |
4829 @deftypefnx {Built-in Function} {} 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
|
4830 Return a scalar, matrix, or N-dimensional array whose elements are all equal\n\ |
5747 | 4831 to the pure imaginary unit, defined as\n\ |
4832 @tex\n\ | |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4833 $\\sqrt{-1}$.\n\ |
5747 | 4834 @end tex\n\ |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
8487
diff
changeset
|
4835 @ifnottex\n\ |
20780
c6059134f5d3
data.cc: Add @w{} around @code segments in docstrings to prevent line breaks.
Rik <rik@octave.org>
parents:
20608
diff
changeset
|
4836 @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
|
4837 @end ifnottex\n\ |
15028
397f0d80bd47
Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents:
15024
diff
changeset
|
4838 \n\ |
15034
1116864ee270
doc: Fix for bad cross-referencing due to use of aliases in Texinfo.
Rik <rik@octave.org>
parents:
15031
diff
changeset
|
4839 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
|
4840 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
|
4841 \n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
4842 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:
20068
diff
changeset
|
4843 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
4844 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:
20068
diff
changeset
|
4845 specified.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
4846 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
4847 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:
20068
diff
changeset
|
4848 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:
20068
diff
changeset
|
4849 additional matrix dimensions.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
4850 \n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4851 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
|
4852 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
|
4853 @seealso{e, pi, log, exp}\n\ |
5747 | 4854 @end deftypefn") |
4855 { | |
4856 return fill_matrix (args, Complex (0.0, 1.0), "I"); | |
4857 } | |
4858 | |
4859 DEFALIAS (i, I); | |
4860 DEFALIAS (J, I); | |
4861 DEFALIAS (j, I); | |
4862 | |
4863 DEFUN (NA, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
4864 "-*- texinfo -*-\n\ |
9308
f2bf62f62286
Update documentation for NA and isna functions
Rik <rdrider0-list@yahoo.com>
parents:
9198
diff
changeset
|
4865 @deftypefn {Built-in Function} {} NA\n\ |
f2bf62f62286
Update documentation for NA and isna functions
Rik <rdrider0-list@yahoo.com>
parents:
9198
diff
changeset
|
4866 @deftypefnx {Built-in Function} {} NA (@var{n})\n\ |
5747 | 4867 @deftypefnx {Built-in Function} {} NA (@var{n}, @var{m})\n\ |
4868 @deftypefnx {Built-in Function} {} NA (@var{n}, @var{m}, @var{k}, @dots{})\n\ | |
4869 @deftypefnx {Built-in Function} {} NA (@dots{}, @var{class})\n\ | |
9308
f2bf62f62286
Update documentation for NA and isna functions
Rik <rdrider0-list@yahoo.com>
parents:
9198
diff
changeset
|
4870 Return a scalar, matrix, or N-dimensional array whose elements are all equal\n\ |
5747 | 4871 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
|
4872 \n\ |
f2bf62f62286
Update documentation for NA and isna functions
Rik <rdrider0-list@yahoo.com>
parents:
9198
diff
changeset
|
4873 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
|
4874 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
|
4875 \n\ |
f2bf62f62286
Update documentation for NA and isna functions
Rik <rdrider0-list@yahoo.com>
parents:
9198
diff
changeset
|
4876 When called with no arguments, return a scalar with the value @samp{NA}.\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
4877 \n\ |
9308
f2bf62f62286
Update documentation for NA and isna functions
Rik <rdrider0-list@yahoo.com>
parents:
9198
diff
changeset
|
4878 When called with a single argument, return a square matrix with the dimension\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
4879 specified.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
4880 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
4881 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:
20068
diff
changeset
|
4882 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:
20068
diff
changeset
|
4883 additional matrix dimensions.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
4884 \n\ |
9308
f2bf62f62286
Update documentation for NA and isna functions
Rik <rdrider0-list@yahoo.com>
parents:
9198
diff
changeset
|
4885 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
|
4886 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
|
4887 @seealso{isna}\n\ |
5747 | 4888 @end deftypefn") |
4889 { | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
4890 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
|
4891 lo_ieee_float_na_value (), "NA"); |
5747 | 4892 } |
4893 | |
7991
139f47cf17ab
Change NA value to support single to double precision conversion
David Bateman <dbateman@free.fr>
parents:
7919
diff
changeset
|
4894 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4895 %!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
|
4896 %!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
|
4897 */ |
7991
139f47cf17ab
Change NA value to support single to double precision conversion
David Bateman <dbateman@free.fr>
parents:
7919
diff
changeset
|
4898 |
5747 | 4899 DEFUN (false, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
4900 "-*- texinfo -*-\n\ |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
4901 @deftypefn {Built-in Function} {} false (@var{x})\n\ |
5747 | 4902 @deftypefnx {Built-in Function} {} false (@var{n}, @var{m})\n\ |
4903 @deftypefnx {Built-in Function} {} false (@var{n}, @var{m}, @var{k}, @dots{})\n\ | |
4904 Return a matrix or N-dimensional array whose elements are all logical 0.\n\ | |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
4905 \n\ |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
4906 If invoked with a single scalar integer argument, return a square\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
4907 matrix of the specified size.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
4908 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
4909 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:
20068
diff
changeset
|
4910 values, return an array with given dimensions.\n\ |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
4911 @seealso{true}\n\ |
5747 | 4912 @end deftypefn") |
4913 { | |
4914 return fill_matrix (args, false, "false"); | |
4915 } | |
4916 | |
4917 DEFUN (true, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
4918 "-*- texinfo -*-\n\ |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
4919 @deftypefn {Built-in Function} {} true (@var{x})\n\ |
5747 | 4920 @deftypefnx {Built-in Function} {} true (@var{n}, @var{m})\n\ |
4921 @deftypefnx {Built-in Function} {} true (@var{n}, @var{m}, @var{k}, @dots{})\n\ | |
4922 Return a matrix or N-dimensional array whose elements are all logical 1.\n\ | |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
4923 \n\ |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
4924 If invoked with a single scalar integer argument, return a square\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
4925 matrix of the specified size.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
4926 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
4927 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:
20068
diff
changeset
|
4928 values, return an array with given dimensions.\n\ |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
4929 @seealso{false}\n\ |
5747 | 4930 @end deftypefn") |
4931 { | |
4932 return fill_matrix (args, true, "true"); | |
3354 | 4933 } |
523 | 4934 |
4946 | 4935 template <class MT> |
4936 octave_value | |
4937 identity_matrix (int nr, int nc) | |
4938 { | |
4939 octave_value retval; | |
4940 | |
9685 | 4941 typename MT::element_type one (1); |
4946 | 4942 |
4943 if (nr == 1 && nc == 1) | |
4944 retval = one; | |
4945 else | |
4946 { | |
4947 dim_vector dims (nr, nc); | |
4948 | |
9685 | 4949 typename MT::element_type zero (0); |
4946 | 4950 |
4951 MT m (dims, zero); | |
4952 | |
4953 if (nr > 0 && nc > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4954 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4955 int n = std::min (nr, nc); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4956 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4957 for (int i = 0; i < n; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4958 m(i,i) = one; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4959 } |
4946 | 4960 |
4961 retval = m; | |
4962 } | |
4963 | |
4964 return retval; | |
4965 } | |
4966 | |
5058 | 4967 #define INSTANTIATE_EYE(T) \ |
4968 template octave_value identity_matrix<T> (int, int) | |
4969 | |
4970 INSTANTIATE_EYE (int8NDArray); | |
4971 INSTANTIATE_EYE (uint8NDArray); | |
4972 INSTANTIATE_EYE (int16NDArray); | |
4973 INSTANTIATE_EYE (uint16NDArray); | |
4974 INSTANTIATE_EYE (int32NDArray); | |
4975 INSTANTIATE_EYE (uint32NDArray); | |
4976 INSTANTIATE_EYE (int64NDArray); | |
4977 INSTANTIATE_EYE (uint64NDArray); | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7743
diff
changeset
|
4978 INSTANTIATE_EYE (FloatNDArray); |
5058 | 4979 INSTANTIATE_EYE (NDArray); |
4980 INSTANTIATE_EYE (boolNDArray); | |
4981 | |
4945 | 4982 static octave_value |
4948 | 4983 identity_matrix (int nr, int nc, oct_data_conv::data_type dt) |
4945 | 4984 { |
4985 octave_value retval; | |
4986 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
4987 // FIXME: perhaps this should be made extensible by using |
4946 | 4988 // the class name to lookup a function to call to create the new |
4989 // value. | |
4990 | |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4991 switch (dt) |
4946 | 4992 { |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4993 case oct_data_conv::dt_int8: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4994 retval = identity_matrix<int8NDArray> (nr, nc); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4995 break; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4996 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4997 case oct_data_conv::dt_uint8: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4998 retval = identity_matrix<uint8NDArray> (nr, nc); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
4999 break; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5000 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5001 case oct_data_conv::dt_int16: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5002 retval = identity_matrix<int16NDArray> (nr, nc); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5003 break; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5004 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5005 case oct_data_conv::dt_uint16: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5006 retval = identity_matrix<uint16NDArray> (nr, nc); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5007 break; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5008 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5009 case oct_data_conv::dt_int32: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5010 retval = identity_matrix<int32NDArray> (nr, nc); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5011 break; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5012 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5013 case oct_data_conv::dt_uint32: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5014 retval = identity_matrix<uint32NDArray> (nr, nc); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5015 break; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5016 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5017 case oct_data_conv::dt_int64: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5018 retval = identity_matrix<int64NDArray> (nr, nc); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5019 break; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5020 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5021 case oct_data_conv::dt_uint64: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5022 retval = identity_matrix<uint64NDArray> (nr, nc); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5023 break; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5024 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5025 case oct_data_conv::dt_single: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5026 retval = FloatDiagMatrix (nr, nc, 1.0f); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5027 break; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5028 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5029 case oct_data_conv::dt_double: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5030 retval = DiagMatrix (nr, nc, 1.0); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5031 break; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5032 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5033 case oct_data_conv::dt_logical: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5034 retval = identity_matrix<boolNDArray> (nr, nc); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5035 break; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5036 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5037 default: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5038 error ("eye: invalid class name"); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5039 break; |
4945 | 5040 } |
5041 | |
5042 return retval; | |
5043 } | |
5044 | |
4946 | 5045 #undef INT_EYE_MATRIX |
5046 | |
1957 | 5047 DEFUN (eye, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
5048 "-*- texinfo -*-\n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
5049 @deftypefn {Built-in Function} {} eye (@var{n})\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
5050 @deftypefnx {Built-in Function} {} eye (@var{m}, @var{n})\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
5051 @deftypefnx {Built-in Function} {} eye ([@var{m} @var{n}])\n\ |
4948 | 5052 @deftypefnx {Built-in Function} {} eye (@dots{}, @var{class})\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
5053 Return an identity matrix.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
5054 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
5055 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:
20068
diff
changeset
|
5056 @nospell{NxN} identity matrix.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
5057 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
5058 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:
20068
diff
changeset
|
5059 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:
20068
diff
changeset
|
5060 @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:
20068
diff
changeset
|
5061 columns, respectively. For example:\n\ |
3369 | 5062 \n\ |
5063 @example\n\ | |
5064 @group\n\ | |
5065 eye (3)\n\ | |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
5066 @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
|
5067 0 1 0\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
5068 0 0 1\n\ |
3369 | 5069 @end group\n\ |
5070 @end example\n\ | |
5071 \n\ | |
5072 The following expressions all produce the same result:\n\ | |
5073 \n\ | |
5074 @example\n\ | |
5075 @group\n\ | |
5076 eye (2)\n\ | |
5077 @equiv{}\n\ | |
5078 eye (2, 2)\n\ | |
5079 @equiv{}\n\ | |
18834
a142f35f3cb6
doc: Fix unbalanced parentheses in documentation.
Rik <rik@octave.org>
parents:
18833
diff
changeset
|
5080 eye (size ([1, 2; 3, 4]))\n\ |
3369 | 5081 @end group\n\ |
5082 @end example\n\ | |
5083 \n\ | |
4945 | 5084 The optional argument @var{class}, allows @code{eye} to return an array of\n\ |
5085 the specified type, like\n\ | |
5086 \n\ | |
5087 @example\n\ | |
5088 val = zeros (n,m, \"uint8\")\n\ | |
5089 @end example\n\ | |
5090 \n\ | |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
5091 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:
20068
diff
changeset
|
5092 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:
20068
diff
changeset
|
5093 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
|
5094 @seealso{speye, ones, zeros}\n\ |
3369 | 5095 @end deftypefn") |
523 | 5096 { |
3354 | 5097 octave_value retval; |
523 | 5098 |
4948 | 5099 int nargin = args.length (); |
4945 | 5100 |
4948 | 5101 oct_data_conv::data_type dt = oct_data_conv::dt_double; |
523 | 5102 |
4945 | 5103 // Check for type information. |
5104 | |
5105 if (nargin > 0 && args(nargin-1).is_string ()) | |
5106 { | |
4948 | 5107 std::string nm = args(nargin-1).string_value (); |
4945 | 5108 nargin--; |
4948 | 5109 |
5110 dt = oct_data_conv::string_to_data_type (nm); | |
4945 | 5111 } |
5112 | |
523 | 5113 switch (nargin) |
5114 { | |
712 | 5115 case 0: |
4948 | 5116 retval = identity_matrix (1, 1, dt); |
712 | 5117 break; |
777 | 5118 |
610 | 5119 case 1: |
3354 | 5120 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5121 octave_idx_type nr, nc; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5122 get_dimensions (args(0), "eye", nr, nc); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5123 |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5124 retval = identity_matrix (nr, nc, dt); |
3354 | 5125 } |
610 | 5126 break; |
777 | 5127 |
523 | 5128 case 2: |
3354 | 5129 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5130 octave_idx_type nr, nc; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5131 get_dimensions (args(0), args(1), "eye", nr, nc); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5132 |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5133 retval = identity_matrix (nr, nc, dt); |
3354 | 5134 } |
523 | 5135 break; |
777 | 5136 |
523 | 5137 default: |
5823 | 5138 print_usage (); |
523 | 5139 break; |
5140 } | |
5141 | |
5142 return retval; | |
5143 } | |
5144 | |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5145 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5146 %!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
|
5147 %!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
|
5148 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5149 %!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
|
5150 %!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
|
5151 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5152 %!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
|
5153 %!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
|
5154 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5155 %!error eye (1, 2, 3) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5156 */ |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5157 |
9658
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5158 template <class MT> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
5159 static octave_value |
9658
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5160 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
|
5161 octave_idx_type n) |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5162 { |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5163 typedef typename MT::column_vector_type CVT; |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5164 typedef typename MT::element_type T; |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5165 |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5166 octave_value retval; |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5167 |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5168 if (base.is_scalar_type ()) |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5169 { |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5170 T bs = octave_value_extract<T> (base); |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5171 if (limit.is_scalar_type ()) |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5172 { |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5173 T ls = octave_value_extract<T> (limit); |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5174 retval = linspace (bs, ls, n); |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5175 } |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5176 else |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5177 { |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5178 CVT lv = octave_value_extract<CVT> (limit); |
20442
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20428
diff
changeset
|
5179 CVT bv (lv.numel (), bs); |
9658
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5180 retval = linspace (bv, lv, n); |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5181 } |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5182 } |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5183 else |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5184 { |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5185 CVT bv = octave_value_extract<CVT> (base); |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5186 if (limit.is_scalar_type ()) |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5187 { |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5188 T ls = octave_value_extract<T> (limit); |
20442
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20428
diff
changeset
|
5189 CVT lv (bv.numel (), ls); |
9658
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5190 retval = linspace (bv, lv, n); |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5191 } |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5192 else |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5193 { |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5194 CVT lv = octave_value_extract<CVT> (limit); |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5195 retval = linspace (bv, lv, n); |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5196 } |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5197 } |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5198 |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5199 return retval; |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5200 } |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
5201 |
1957 | 5202 DEFUN (linspace, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
5203 "-*- texinfo -*-\n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
5204 @deftypefn {Built-in Function} {} linspace (@var{base}, @var{limit})\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
5205 @deftypefnx {Built-in Function} {} linspace (@var{base}, @var{limit}, @var{n})\n\ |
3369 | 5206 Return a row vector with @var{n} linearly spaced elements between\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
5207 @var{base} and @var{limit}.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
5208 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
5209 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:
20068
diff
changeset
|
5210 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:
20068
diff
changeset
|
5211 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:
20068
diff
changeset
|
5212 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:
20068
diff
changeset
|
5213 \n\ |
20676
16b9ec39ff46
Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents:
20615
diff
changeset
|
5214 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:
20615
diff
changeset
|
5215 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:
20615
diff
changeset
|
5216 @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:
20615
diff
changeset
|
5217 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:
20615
diff
changeset
|
5218 @w{@code{@var{base}(@var{row_n}), @var{limit}(@var{row_n})}}.\n\ |
6630 | 5219 \n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
5220 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
|
5221 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
|
5222 @seealso{logspace}\n\ |
3369 | 5223 @end deftypefn") |
1100 | 5224 { |
3418 | 5225 octave_value retval; |
1100 | 5226 |
20785
780431fc4137
linspace: add tests for the use of vectors as base and limit.
Carnë Draug <carandraug@octave.org>
parents:
20784
diff
changeset
|
5227 octave_idx_type nargin = args.length (); |
1100 | 5228 |
6133 | 5229 octave_idx_type npoints = 100; |
1100 | 5230 |
1940 | 5231 if (nargin != 2 && nargin != 3) |
5232 { | |
5823 | 5233 print_usage (); |
1940 | 5234 return retval; |
5235 } | |
5236 | |
1100 | 5237 if (nargin == 3) |
16077
39129305b914
provide some undocumented matlab behavior for linspace (bug #38151)
John W. Eaton <jwe@octave.org>
parents:
15623
diff
changeset
|
5238 { |
39129305b914
provide some undocumented matlab behavior for linspace (bug #38151)
John W. Eaton <jwe@octave.org>
parents:
15623
diff
changeset
|
5239 // 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
|
5240 // 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
|
5241 |
39129305b914
provide some undocumented matlab behavior for linspace (bug #38151)
John W. Eaton <jwe@octave.org>
parents:
15623
diff
changeset
|
5242 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
|
5243 |
39129305b914
provide some undocumented matlab behavior for linspace (bug #38151)
John W. Eaton <jwe@octave.org>
parents:
15623
diff
changeset
|
5244 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
|
5245 npoints = 1; |
20676
16b9ec39ff46
Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents:
20615
diff
changeset
|
5246 else if (! arg_3.is_scalar_type ()) |
16b9ec39ff46
Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents:
20615
diff
changeset
|
5247 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
|
5248 else |
20784
32a0bf9906c1
linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents:
20769
diff
changeset
|
5249 // 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
|
5250 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
|
5251 } |
1100 | 5252 |
20784
32a0bf9906c1
linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents:
20769
diff
changeset
|
5253 octave_value arg_1 = args(0); |
32a0bf9906c1
linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents:
20769
diff
changeset
|
5254 octave_value arg_2 = args(1); |
32a0bf9906c1
linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents:
20769
diff
changeset
|
5255 |
32a0bf9906c1
linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents:
20769
diff
changeset
|
5256 dim_vector sz1 = arg_1.dims (); |
32a0bf9906c1
linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents:
20769
diff
changeset
|
5257 bool isvector1 = sz1.length () == 2 && (sz1(0) == 1 || sz1(1) == 1); |
32a0bf9906c1
linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents:
20769
diff
changeset
|
5258 dim_vector sz2 = arg_2.dims (); |
32a0bf9906c1
linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents:
20769
diff
changeset
|
5259 bool isvector2 = sz2.length () == 2 && (sz2(0) == 1 || sz2(1) == 1); |
32a0bf9906c1
linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents:
20769
diff
changeset
|
5260 |
32a0bf9906c1
linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents:
20769
diff
changeset
|
5261 if (! isvector1 || ! isvector2) |
32a0bf9906c1
linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents:
20769
diff
changeset
|
5262 error ("linspace: A, B must be scalars or vectors"); |
32a0bf9906c1
linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents:
20769
diff
changeset
|
5263 else if (arg_1.is_single_type () || arg_2.is_single_type ()) |
1100 | 5264 { |
20784
32a0bf9906c1
linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents:
20769
diff
changeset
|
5265 if (arg_1.is_complex_type () || arg_2.is_complex_type ()) |
32a0bf9906c1
linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents:
20769
diff
changeset
|
5266 retval = do_linspace<FloatComplexMatrix> (arg_1, arg_2, npoints); |
1100 | 5267 else |
20784
32a0bf9906c1
linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents:
20769
diff
changeset
|
5268 retval = do_linspace<FloatMatrix> (arg_1, arg_2, npoints); |
32a0bf9906c1
linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents:
20769
diff
changeset
|
5269 |
1100 | 5270 } |
4732 | 5271 else |
20784
32a0bf9906c1
linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents:
20769
diff
changeset
|
5272 { |
32a0bf9906c1
linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents:
20769
diff
changeset
|
5273 if (arg_1.is_complex_type () || arg_2.is_complex_type ()) |
32a0bf9906c1
linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents:
20769
diff
changeset
|
5274 retval = do_linspace<ComplexMatrix> (arg_1, arg_2, npoints); |
32a0bf9906c1
linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents:
20769
diff
changeset
|
5275 else |
32a0bf9906c1
linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents:
20769
diff
changeset
|
5276 retval = do_linspace<Matrix> (arg_1, arg_2, npoints); |
32a0bf9906c1
linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents:
20769
diff
changeset
|
5277 } |
1100 | 5278 |
5279 return retval; | |
5280 } | |
5281 | |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5282 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5283 /* |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5284 %!test |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5285 %! 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
|
5286 %! 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
|
5287 %! 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
|
5288 %! 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
|
5289 %! 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
|
5290 %! 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
|
5291 |
20676
16b9ec39ff46
Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents:
20615
diff
changeset
|
5292 ## Test complex values |
16b9ec39ff46
Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents:
20615
diff
changeset
|
5293 %!test |
16b9ec39ff46
Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents:
20615
diff
changeset
|
5294 %! 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:
20615
diff
changeset
|
5295 %! obs = linspace (1, 5-5i, 5); |
16b9ec39ff46
Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents:
20615
diff
changeset
|
5296 %! assert (obs, exp); |
16b9ec39ff46
Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents:
20615
diff
changeset
|
5297 |
20785
780431fc4137
linspace: add tests for the use of vectors as base and limit.
Carnë Draug <carandraug@octave.org>
parents:
20784
diff
changeset
|
5298 ## 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:
20784
diff
changeset
|
5299 %!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:
20784
diff
changeset
|
5300 %! [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:
20784
diff
changeset
|
5301 %!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:
20784
diff
changeset
|
5302 %! [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:
20784
diff
changeset
|
5303 %!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:
20784
diff
changeset
|
5304 %! [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:
20784
diff
changeset
|
5305 %!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:
20784
diff
changeset
|
5306 %! [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:
20784
diff
changeset
|
5307 %!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:
20784
diff
changeset
|
5308 %! [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:
20784
diff
changeset
|
5309 %!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:
20784
diff
changeset
|
5310 %! [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:
20784
diff
changeset
|
5311 |
20676
16b9ec39ff46
Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents:
20615
diff
changeset
|
5312 ## Test class of output |
16b9ec39ff46
Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents:
20615
diff
changeset
|
5313 %!assert (class (linspace (1, 2)), "double") |
16b9ec39ff46
Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents:
20615
diff
changeset
|
5314 %!assert (class (linspace (single (1), 2)), "single") |
16b9ec39ff46
Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents:
20615
diff
changeset
|
5315 %!assert (class (linspace (1, single (2))), "single") |
16b9ec39ff46
Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents:
20615
diff
changeset
|
5316 |
16b9ec39ff46
Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents:
20615
diff
changeset
|
5317 ## 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
|
5318 %!assert (linspace (0, 1, []), 1) |
20676
16b9ec39ff46
Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents:
20615
diff
changeset
|
5319 %!assert (linspace (10, 20, 2), [10 20]) |
16b9ec39ff46
Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents:
20615
diff
changeset
|
5320 %!assert (linspace (10, 20, 1), [20]) |
16b9ec39ff46
Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents:
20615
diff
changeset
|
5321 %!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:
20615
diff
changeset
|
5322 %!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:
20615
diff
changeset
|
5323 %!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:
20615
diff
changeset
|
5324 %!assert (numel (linspace (0, 1, 2-eps)), 1) |
20784
32a0bf9906c1
linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents:
20769
diff
changeset
|
5325 %!assert (linspace (10, 20, 2.1), [10 20]) |
32a0bf9906c1
linspace: remove use of error_state.
Carnë Draug <carandraug@octave.org>
parents:
20769
diff
changeset
|
5326 %!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
|
5327 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5328 %!error linspace () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5329 %!error linspace (1, 2, 3, 4) |
20676
16b9ec39ff46
Return empty matrix when linspace called with 0 points (bug #45820)
Rik <rik@octave.org>
parents:
20615
diff
changeset
|
5330 %!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:
20615
diff
changeset
|
5331 %!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:
20615
diff
changeset
|
5332 %!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:
20615
diff
changeset
|
5333 %!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
|
5334 */ |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5335 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
5336 // FIXME: should accept dimensions as separate args for N-d |
5734 | 5337 // arrays as well as 1-d and 2-d arrays. |
5338 | |
5731 | 5339 DEFUN (resize, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
5340 "-*- texinfo -*-\n\ |
10840 | 5341 @deftypefn {Built-in Function} {} resize (@var{x}, @var{m})\n\ |
8799
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
5342 @deftypefnx {Built-in Function} {} resize (@var{x}, @var{m}, @var{n}, @dots{})\n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
5343 @deftypefnx {Built-in Function} {} 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
|
5344 Resize @var{x} cutting off elements as necessary.\n\ |
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
5345 \n\ |
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
5346 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
|
5347 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
|
5348 otherwise, the element is set to zero.\n\ |
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
5349 \n\ |
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
5350 In other words, the statement\n\ |
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
5351 \n\ |
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
5352 @example\n\ |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
5353 y = resize (x, dv)\n\ |
8799
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
5354 @end example\n\ |
6174 | 5355 \n\ |
8799
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
5356 @noindent\n\ |
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
5357 is equivalent to the following code:\n\ |
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
5358 \n\ |
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
5359 @example\n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
9041
diff
changeset
|
5360 @group\n\ |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
5361 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
|
5362 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
|
5363 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
|
5364 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
|
5365 endfor\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
5366 y(idx@{:@}) = x(idx@{:@});\n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
9041
diff
changeset
|
5367 @end group\n\ |
8799
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
5368 @end example\n\ |
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
5369 \n\ |
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
5370 @noindent\n\ |
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
5371 but is performed more efficiently.\n\ |
6174 | 5372 \n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
5373 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
|
5374 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
|
5375 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
|
5376 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
|
5377 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
|
5378 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
|
5379 \n\ |
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
5380 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
|
5381 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
|
5382 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
|
5383 @seealso{reshape, postpad, prepad, cat}\n\ |
5731 | 5384 @end deftypefn") |
5385 { | |
5386 octave_value retval; | |
5387 int nargin = args.length (); | |
5388 | |
5389 if (nargin == 2) | |
5390 { | |
5391 Array<double> vec = args(1).vector_value (); | |
20442
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20428
diff
changeset
|
5392 int ndim = vec.numel (); |
5731 | 5393 if (ndim == 1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5394 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5395 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
|
5396 retval = args(0); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5397 retval = retval.resize (dim_vector (m, m), true); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5398 } |
5731 | 5399 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5400 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5401 dim_vector dv; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5402 dv.resize (ndim); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5403 for (int i = 0; i < ndim; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5404 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
|
5405 retval = args(0); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5406 retval = retval.resize (dv, true); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5407 } |
5731 | 5408 } |
8799
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
5409 else if (nargin > 2) |
5731 | 5410 { |
8799
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
5411 dim_vector dv; |
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
5412 dv.resize (nargin - 1); |
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
5413 for (octave_idx_type i = 1; i < nargin; i++) |
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
5414 dv(i-1) = static_cast<octave_idx_type> (args(i).scalar_value ()); |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5415 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5416 retval = args(0); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5417 retval = retval.resize (dv, true); |
5731 | 5418 } |
5419 else | |
5823 | 5420 print_usage (); |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5421 |
5731 | 5422 return retval; |
5423 } | |
5424 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
5425 // FIXME: should use octave_idx_type for dimensions. |
5734 | 5426 |
4567 | 5427 DEFUN (reshape, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
5428 "-*- texinfo -*-\n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
5429 @deftypefn {Built-in Function} {} reshape (@var{A}, @var{m}, @var{n}, @dots{})\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
5430 @deftypefnx {Built-in Function} {} reshape (@var{A}, [@var{m} @var{n} @dots{}])\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
5431 @deftypefnx {Built-in Function} {} reshape (@var{A}, @dots{}, [], @dots{})\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
5432 @deftypefnx {Built-in Function} {} reshape (@var{A}, @var{size})\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
5433 Return a matrix with the specified dimensions (@var{m}, @var{n}, @dots{})\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
5434 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:
20068
diff
changeset
|
5435 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
5436 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:
20068
diff
changeset
|
5437 arrays are stored).\n\ |
4567 | 5438 \n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
5439 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
|
5440 matrix.\n\ |
4567 | 5441 \n\ |
5442 @example\n\ | |
5443 @group\n\ | |
5444 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
|
5445 @result{} 1 3\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
5446 2 4\n\ |
4567 | 5447 @end group\n\ |
5448 @end example\n\ | |
5449 \n\ | |
5450 @noindent\n\ | |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
5451 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:
20068
diff
changeset
|
5452 (@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
|
5453 in the new matrix (@code{prod ([@var{m} @var{n} @dots{}])}).\n\ |
5013 | 5454 \n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
5455 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
|
5456 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
|
5457 the unspecified dimension.\n\ |
15028
397f0d80bd47
Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents:
15024
diff
changeset
|
5458 @seealso{resize, vec, postpad, cat, squeeze}\n\ |
4567 | 5459 @end deftypefn") |
5460 { | |
5461 octave_value retval; | |
5462 | |
5463 int nargin = args.length (); | |
5464 | |
10693 | 5465 dim_vector new_dims; |
4567 | 5466 |
5467 if (nargin == 2) | |
10693 | 5468 { |
5469 Array<octave_idx_type> new_size = args(1).octave_idx_type_vector_value (); | |
5470 | |
20442
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20428
diff
changeset
|
5471 if (new_size.numel () < 2) |
17915
56d2b6838405
Issue an error if reshape called with just a single dimension.
Rik <rik@octave.org>
parents:
17843
diff
changeset
|
5472 { |
56d2b6838405
Issue an error if reshape called with just a single dimension.
Rik <rik@octave.org>
parents:
17843
diff
changeset
|
5473 error ("reshape: SIZE must have 2 or more dimensions"); |
56d2b6838405
Issue an error if reshape called with just a single dimension.
Rik <rik@octave.org>
parents:
17843
diff
changeset
|
5474 return retval; |
56d2b6838405
Issue an error if reshape called with just a single dimension.
Rik <rik@octave.org>
parents:
17843
diff
changeset
|
5475 } |
56d2b6838405
Issue an error if reshape called with just a single dimension.
Rik <rik@octave.org>
parents:
17843
diff
changeset
|
5476 |
20442
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20428
diff
changeset
|
5477 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:
20428
diff
changeset
|
5478 |
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20428
diff
changeset
|
5479 for (octave_idx_type i = 0; i < new_size.numel (); i++) |
10693 | 5480 { |
5481 if (new_size(i) < 0) | |
5482 { | |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11591
diff
changeset
|
5483 error ("reshape: SIZE must be non-negative"); |
10693 | 5484 break; |
5485 } | |
5486 else | |
5487 new_dims(i) = new_size(i); | |
5488 } | |
5489 } | |
4567 | 5490 else if (nargin > 2) |
5491 { | |
10693 | 5492 new_dims = dim_vector::alloc (nargin-1); |
5013 | 5493 int empty_dim = -1; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
5494 |
4567 | 5495 for (int i = 1; i < nargin; i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5496 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5497 if (args(i).is_empty ()) |
10693 | 5498 { |
5499 if (empty_dim > 0) | |
5500 { | |
5501 error ("reshape: only a single dimension can be unknown"); | |
5502 break; | |
5503 } | |
5504 else | |
5505 { | |
5506 empty_dim = i; | |
5507 new_dims(i-1) = 1; | |
5508 } | |
5509 } | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5510 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5511 { |
10693 | 5512 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
|
5513 |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5514 if (new_dims(i-1) < 0) |
10693 | 5515 { |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11591
diff
changeset
|
5516 error ("reshape: SIZE must be non-negative"); |
10693 | 5517 break; |
5518 } | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5519 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5520 } |
5013 | 5521 |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5522 if (empty_dim > 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5523 { |
10693 | 5524 octave_idx_type nel = new_dims.numel (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5525 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5526 if (nel == 0) |
10693 | 5527 new_dims(empty_dim-1) = 0; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5528 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5529 { |
10693 | 5530 octave_idx_type a_nel = args(0).numel (); |
5531 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
|
5532 |
10693 | 5533 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
|
5534 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
|
5535 nel); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5536 else |
10693 | 5537 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
|
5538 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5539 } |
4567 | 5540 } |
5541 else | |
5542 { | |
5823 | 5543 print_usage (); |
4567 | 5544 return retval; |
5545 } | |
5546 | |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5547 retval = args(0).reshape (new_dims); |
4567 | 5548 |
5549 return retval; | |
5550 } | |
5551 | |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5552 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5553 %!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
|
5554 %!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
|
5555 %!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
|
5556 %!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
|
5557 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5558 %!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
|
5559 %!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
|
5560 %!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
|
5561 %!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
|
5562 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5563 %!test |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5564 %! s.a = 1; |
17915
56d2b6838405
Issue an error if reshape called with just a single dimension.
Rik <rik@octave.org>
parents:
17843
diff
changeset
|
5565 %! 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
|
5566 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5567 %!error reshape () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5568 %!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
|
5569 %!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
|
5570 %!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
|
5571 %!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
|
5572 %!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
|
5573 %!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
|
5574 */ |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5575 |
10694
d97165928d05
implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents:
10693
diff
changeset
|
5576 DEFUN (vec, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
5577 "-*- texinfo -*-\n\ |
12578
f5a780d675a1
Clean up operator and function indices in documentation.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
5578 @deftypefn {Built-in Function} {@var{v} =} vec (@var{x})\n\ |
f5a780d675a1
Clean up operator and function indices in documentation.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
5579 @deftypefnx {Built-in Function} {@var{v} =} vec (@var{x}, @var{dim})\n\ |
10694
d97165928d05
implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents:
10693
diff
changeset
|
5580 Return the vector obtained by stacking the columns of the matrix @var{x}\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
5581 one above the other.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
5582 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
5583 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:
20068
diff
changeset
|
5584 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
5585 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:
20068
diff
changeset
|
5586 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:
20068
diff
changeset
|
5587 @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
|
5588 @seealso{vech, resize, cat}\n\ |
10694
d97165928d05
implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents:
10693
diff
changeset
|
5589 @end deftypefn") |
d97165928d05
implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents:
10693
diff
changeset
|
5590 { |
d97165928d05
implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents:
10693
diff
changeset
|
5591 octave_value retval; |
11402
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
5592 int dim = 1; |
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
5593 |
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
5594 int nargin = args.length (); |
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
5595 |
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
5596 if (nargin < 1 || nargin > 2) |
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
5597 print_usage () ; |
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
5598 |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5599 if (nargin == 2) |
11402
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
5600 { |
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
5601 dim = args(1).idx_type_value (); |
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
5602 |
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
5603 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
|
5604 error ("vec: DIM must be greater than zero"); |
11402
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
5605 } |
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
5606 |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5607 octave_value colon (octave_value::magic_colon_t); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5608 octave_value arg = args(0); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5609 retval = arg.single_subsref ("(", colon); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5610 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5611 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5612 if (dim > 1) |
10694
d97165928d05
implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents:
10693
diff
changeset
|
5613 { |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5614 dim_vector new_dims = dim_vector::alloc (dim); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5615 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5616 for (int i = 0; i < dim-1; i++) |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5617 new_dims(i) = 1; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5618 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5619 new_dims(dim-1) = retval.numel (); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5620 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5621 retval = retval.reshape (new_dims); |
10694
d97165928d05
implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents:
10693
diff
changeset
|
5622 } |
d97165928d05
implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents:
10693
diff
changeset
|
5623 |
d97165928d05
implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents:
10693
diff
changeset
|
5624 return retval; |
d97165928d05
implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents:
10693
diff
changeset
|
5625 } |
d97165928d05
implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents:
10693
diff
changeset
|
5626 |
d97165928d05
implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents:
10693
diff
changeset
|
5627 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5628 %!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
|
5629 %!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
|
5630 %!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
|
5631 %!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
|
5632 %!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
|
5633 %!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
|
5634 %!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
|
5635 %!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
|
5636 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5637 %!error vec () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5638 %!error vec (1, 2, 3) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5639 %!error vec ([1, 2; 3, 4], 0) |
10694
d97165928d05
implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents:
10693
diff
changeset
|
5640 */ |
d97165928d05
implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents:
10693
diff
changeset
|
5641 |
4532 | 5642 DEFUN (squeeze, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
5643 "-*- texinfo -*-\n\ |
4532 | 5644 @deftypefn {Built-in Function} {} squeeze (@var{x})\n\ |
5645 Remove singleton dimensions from @var{x} and return the result.\n\ | |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
5646 \n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
9041
diff
changeset
|
5647 Note that for compatibility with @sc{matlab}, all objects have\n\ |
7007 | 5648 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
|
5649 @seealso{reshape}\n\ |
4532 | 5650 @end deftypefn") |
5651 { | |
5652 octave_value retval; | |
5653 | |
5654 if (args.length () == 1) | |
4545 | 5655 retval = args(0).squeeze (); |
4532 | 5656 else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
5657 print_usage (); |
4532 | 5658 |
5659 return retval; | |
5660 } | |
5661 | |
8458
d254a21e0120
reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents:
8433
diff
changeset
|
5662 DEFUN (full, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
5663 "-*- texinfo -*-\n\ |
15038
ab18578c2ade
doc: Update docstrings for built-in functions to not use "Loadable Function" as type.
Rik <rik@octave.org>
parents:
15034
diff
changeset
|
5664 @deftypefn {Built-in Function} {@var{FM} =} full (@var{SM})\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
5665 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
|
5666 or a range.\n\ |
19004
53af80da6781
doc: Update documentation of sparse functions including seealso links.
Rik <rik@octave.org>
parents:
18978
diff
changeset
|
5667 @seealso{sparse, issparse}\n\ |
8458
d254a21e0120
reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents:
8433
diff
changeset
|
5668 @end deftypefn") |
d254a21e0120
reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents:
8433
diff
changeset
|
5669 { |
d254a21e0120
reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents:
8433
diff
changeset
|
5670 octave_value retval; |
d254a21e0120
reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents:
8433
diff
changeset
|
5671 |
d254a21e0120
reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents:
8433
diff
changeset
|
5672 if (args.length () == 1) |
d254a21e0120
reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents:
8433
diff
changeset
|
5673 retval = args(0).full_value (); |
d254a21e0120
reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents:
8433
diff
changeset
|
5674 else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
5675 print_usage (); |
8458
d254a21e0120
reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents:
8433
diff
changeset
|
5676 |
d254a21e0120
reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents:
8433
diff
changeset
|
5677 return retval; |
d254a21e0120
reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents:
8433
diff
changeset
|
5678 } |
d254a21e0120
reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents:
8433
diff
changeset
|
5679 |
6945 | 5680 // Compute various norms of the vector X. |
5681 | |
6953 | 5682 DEFUN (norm, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
5683 "-*- texinfo -*-\n\ |
12584
7ef7e20057fa
Improve documentation strings in Linear Algebra chapter.
Rik <octave@nomad.inbox5.com>
parents:
12578
diff
changeset
|
5684 @deftypefn {Built-in Function} {} norm (@var{A})\n\ |
7ef7e20057fa
Improve documentation strings in Linear Algebra chapter.
Rik <octave@nomad.inbox5.com>
parents:
12578
diff
changeset
|
5685 @deftypefnx {Built-in Function} {} norm (@var{A}, @var{p})\n\ |
7ef7e20057fa
Improve documentation strings in Linear Algebra chapter.
Rik <octave@nomad.inbox5.com>
parents:
12578
diff
changeset
|
5686 @deftypefnx {Built-in Function} {} norm (@var{A}, @var{p}, @var{opt})\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
5687 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:
20068
diff
changeset
|
5688 \n\ |
20780
c6059134f5d3
data.cc: Add @w{} around @code segments in docstrings to prevent line breaks.
Rik <rik@octave.org>
parents:
20608
diff
changeset
|
5689 If the second argument is missing, @w{@code{p = 2}} is assumed.\n\ |
6953 | 5690 \n\ |
12584
7ef7e20057fa
Improve documentation strings in Linear Algebra chapter.
Rik <octave@nomad.inbox5.com>
parents:
12578
diff
changeset
|
5691 If @var{A} is a matrix (or sparse matrix):\n\ |
6953 | 5692 \n\ |
5693 @table @asis\n\ | |
5694 @item @var{p} = @code{1}\n\ | |
12584
7ef7e20057fa
Improve documentation strings in Linear Algebra chapter.
Rik <octave@nomad.inbox5.com>
parents:
12578
diff
changeset
|
5695 1-norm, the largest column sum of the absolute values of @var{A}.\n\ |
6953 | 5696 \n\ |
5697 @item @var{p} = @code{2}\n\ | |
12584
7ef7e20057fa
Improve documentation strings in Linear Algebra chapter.
Rik <octave@nomad.inbox5.com>
parents:
12578
diff
changeset
|
5698 Largest singular value of @var{A}.\n\ |
6953 | 5699 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17268
diff
changeset
|
5700 @item @var{p} = @code{Inf} or @qcode{\"inf\"}\n\ |
6953 | 5701 @cindex infinity norm\n\ |
12584
7ef7e20057fa
Improve documentation strings in Linear Algebra chapter.
Rik <octave@nomad.inbox5.com>
parents:
12578
diff
changeset
|
5702 Infinity norm, the largest row sum of the absolute values of @var{A}.\n\ |
6953 | 5703 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17268
diff
changeset
|
5704 @item @var{p} = @qcode{\"fro\"}\n\ |
6953 | 5705 @cindex Frobenius norm\n\ |
12584
7ef7e20057fa
Improve documentation strings in Linear Algebra chapter.
Rik <octave@nomad.inbox5.com>
parents:
12578
diff
changeset
|
5706 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
|
5707 \n\ |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
5708 @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
|
5709 @cindex general p-norm\n\ |
8303
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
5710 maximum @code{norm (A*x, p)} such that @code{norm (x, p) == 1}\n\ |
6953 | 5711 @end table\n\ |
5712 \n\ | |
12584
7ef7e20057fa
Improve documentation strings in Linear Algebra chapter.
Rik <octave@nomad.inbox5.com>
parents:
12578
diff
changeset
|
5713 If @var{A} is a vector or a scalar:\n\ |
6953 | 5714 \n\ |
5715 @table @asis\n\ | |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17268
diff
changeset
|
5716 @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
|
5717 @code{max (abs (@var{A}))}.\n\ |
6953 | 5718 \n\ |
5719 @item @var{p} = @code{-Inf}\n\ | |
12584
7ef7e20057fa
Improve documentation strings in Linear Algebra chapter.
Rik <octave@nomad.inbox5.com>
parents:
12578
diff
changeset
|
5720 @code{min (abs (@var{A}))}.\n\ |
6953 | 5721 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17268
diff
changeset
|
5722 @item @var{p} = @qcode{\"fro\"}\n\ |
12584
7ef7e20057fa
Improve documentation strings in Linear Algebra chapter.
Rik <octave@nomad.inbox5.com>
parents:
12578
diff
changeset
|
5723 Frobenius norm of @var{A}, @code{sqrt (sumsq (abs (A)))}.\n\ |
7189 | 5724 \n\ |
8303
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
5725 @item @var{p} = 0\n\ |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
5726 Hamming norm - the number of nonzero elements.\n\ |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
5727 \n\ |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
5728 @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
|
5729 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
|
5730 \n\ |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
5731 @item other @var{p} @code{@var{p} < 1}\n\ |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
5732 the p-pseudonorm defined as above.\n\ |
6953 | 5733 @end table\n\ |
8303
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
5734 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17268
diff
changeset
|
5735 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
|
5736 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
|
5737 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
|
5738 compute the norms of each column and return a row vector.\n\ |
6953 | 5739 @seealso{cond, svd}\n\ |
6508 | 5740 @end deftypefn") |
5741 { | |
6953 | 5742 octave_value_list retval; |
6508 | 5743 |
5744 int nargin = args.length (); | |
5745 | |
8303
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
5746 if (nargin >= 1 && nargin <= 3) |
6508 | 5747 { |
6953 | 5748 octave_value x_arg = args(0); |
5749 | |
10185
455759a5fcbe
fix norm and svd on empty matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10182
diff
changeset
|
5750 if (x_arg.ndims () == 2) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5751 { |
8303
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
5752 enum { sfmatrix, sfcols, sfrows, sffrob, sfinf } strflag = sfmatrix; |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
5753 if (nargin > 1 && args(nargin-1).is_string ()) |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
5754 { |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
5755 std::string str = args(nargin-1).string_value (); |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
5756 if (str == "cols" || str == "columns") |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
5757 strflag = sfcols; |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
5758 else if (str == "rows") |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
5759 strflag = sfrows; |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
5760 else if (str == "fro") |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
5761 strflag = sffrob; |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
5762 else if (str == "inf") |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
5763 strflag = sfinf; |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
5764 else |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
5765 error ("norm: unrecognized option: %s", str.c_str ()); |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
5766 // we've handled the last parameter, so act as if it was removed |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
5767 nargin --; |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
5768 } |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
5769 |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5770 octave_value p_arg = (nargin > 1) ? args(1) : octave_value (2); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5771 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5772 if (p_arg.is_empty ()) |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5773 p_arg = octave_value (2); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5774 else if (p_arg.is_string ()) |
8303
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
5775 { |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5776 std::string str = p_arg.string_value (); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5777 if ((strflag == sfcols || strflag == sfrows)) |
8303
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
5778 { |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5779 if (str == "cols" || str == "columns" || str == "rows") |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5780 error ("norm: invalid combination of options"); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5781 else if (str == "fro") |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5782 p_arg = octave_value (2); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5783 else if (str == "inf") |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5784 p_arg = octave_Inf; |
17115
00985134145e
norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents:
16892
diff
changeset
|
5785 else |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5786 error ("norm: unrecognized option: %s", str.c_str ()); |
17115
00985134145e
norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents:
16892
diff
changeset
|
5787 } |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5788 else |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5789 error ("norm: invalid combination of options"); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5790 } |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5791 else if (! p_arg.is_scalar_type ()) |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5792 gripe_wrong_type_arg ("norm", p_arg, true); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5793 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5794 switch (strflag) |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5795 { |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5796 case sfmatrix: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5797 retval(0) = xnorm (x_arg, p_arg); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5798 break; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5799 case sfcols: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5800 retval(0) = xcolnorms (x_arg, p_arg); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5801 break; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5802 case sfrows: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5803 retval(0) = xrownorms (x_arg, p_arg); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5804 break; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5805 case sffrob: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5806 retval(0) = xfrobnorm (x_arg); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5807 break; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5808 case sfinf: |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5809 retval(0) = xnorm (x_arg, octave_Inf); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
5810 break; |
8303
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
5811 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5812 } |
6508 | 5813 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5814 error ("norm: only valid for 2-D objects"); |
6508 | 5815 } |
5816 else | |
5817 print_usage (); | |
5818 | |
5819 return retval; | |
5820 } | |
5821 | |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5822 /* |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5823 %!shared x |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5824 %! 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
|
5825 %!assert (norm (x,1), 20) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5826 %!assert (norm (x,2), 10) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5827 %!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
|
5828 %!assert (norm (x,Inf), 7) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5829 %!assert (norm (x,-Inf), 1) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5830 %!assert (norm (x,"inf"), 7) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5831 %!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
|
5832 %!assert (norm (x), 10) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5833 %!assert (norm ([1e200, 1]), 1e200) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5834 %!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
|
5835 %!shared m |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5836 %! m = magic (4); |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5837 %!assert (norm (m,1), 34) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5838 %!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
|
5839 %!assert (norm (m,Inf), 34) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5840 %!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
|
5841 %!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
|
5842 %! 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
|
5843 %! 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
|
5844 %! fhi = 1e+300; |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5845 %!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
|
5846 %!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
|
5847 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5848 %!shared x |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5849 %! 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
|
5850 %!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
|
5851 %!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
|
5852 %!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
|
5853 %!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
|
5854 %!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
|
5855 %!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
|
5856 %!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
|
5857 %!assert (norm (x), single (10)) |
18831
5bd1ca29c5f0
Clean up questionable code bits identified by clang sanitize.
Rik <rik@octave.org>
parents:
18211
diff
changeset
|
5858 %!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
|
5859 %!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
|
5860 %!shared m |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5861 %! m = single (magic (4)); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5862 %!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
|
5863 %!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
|
5864 %!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
|
5865 %!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
|
5866 %!shared m2, flo, fhi |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5867 %! 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
|
5868 %! flo = single (1e-300); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5869 %! fhi = single (1e+300); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5870 %!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
|
5871 %!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
|
5872 |
17115
00985134145e
norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents:
16892
diff
changeset
|
5873 %!shared q |
00985134145e
norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents:
16892
diff
changeset
|
5874 %! q = rand (1e3, 3); |
00985134145e
norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents:
16892
diff
changeset
|
5875 %!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
|
5876 %!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
|
5877 %!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
|
5878 %!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
|
5879 %!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
|
5880 %!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
|
5881 %!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
|
5882 %!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
|
5883 %!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
|
5884 |
14520
c4ed0fdf2b62
Fix initialization in Higham's method for norm estimate (bug #36031).
Marco Caliari <marco.caliari@univr.it>
parents:
14491
diff
changeset
|
5885 %!test |
c4ed0fdf2b62
Fix initialization in Higham's method for norm estimate (bug #36031).
Marco Caliari <marco.caliari@univr.it>
parents:
14491
diff
changeset
|
5886 %! ## 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
|
5887 %! 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
|
5888 %! 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
|
5889 %! 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
|
5890 */ |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5891 |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5892 static octave_value |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5893 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
|
5894 const octave_value_list& args) |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5895 { |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5896 octave_value retval; |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5897 if (args.length () == 1) |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5898 retval = do_unary_op (op, args(0)); |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5899 else |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5900 print_usage (); |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5901 |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5902 return retval; |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5903 } |
6518 | 5904 |
5905 DEFUN (not, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
5906 "-*- texinfo -*-\n\ |
19380
c3611856cdd4
xor.m: Extend to handle more than 2 arguments as a reduction operator.
Rik <rik@octave.org>
parents:
19344
diff
changeset
|
5907 @deftypefn {Built-in Function} {@var{z} =} not (@var{x})\n\ |
c3611856cdd4
xor.m: Extend to handle more than 2 arguments as a reduction operator.
Rik <rik@octave.org>
parents:
19344
diff
changeset
|
5908 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:
19344
diff
changeset
|
5909 \n\ |
c3611856cdd4
xor.m: Extend to handle more than 2 arguments as a reduction operator.
Rik <rik@octave.org>
parents:
19344
diff
changeset
|
5910 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
|
5911 @seealso{and, or, xor}\n\ |
6518 | 5912 @end deftypefn") |
5913 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5914 return unary_op_defun_body (octave_value::op_not, args); |
6518 | 5915 } |
5916 | |
5917 DEFUN (uplus, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
5918 "-*- texinfo -*-\n\ |
6518 | 5919 @deftypefn {Built-in Function} {} uplus (@var{x})\n\ |
17268
1c21f264d26f
doc: Rename @xcode macro to @tcode (transpose code) for clarity.
Rik <rik@octave.org>
parents:
17206
diff
changeset
|
5920 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
|
5921 @seealso{uminus, plus, minus}\n\ |
6518 | 5922 @end deftypefn") |
5923 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5924 return unary_op_defun_body (octave_value::op_uplus, args); |
6518 | 5925 } |
5926 | |
5927 DEFUN (uminus, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
5928 "-*- texinfo -*-\n\ |
6518 | 5929 @deftypefn {Built-in Function} {} uminus (@var{x})\n\ |
17268
1c21f264d26f
doc: Rename @xcode macro to @tcode (transpose code) for clarity.
Rik <rik@octave.org>
parents:
17206
diff
changeset
|
5930 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
|
5931 @seealso{uplus, minus}\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 unary_op_defun_body (octave_value::op_uminus, args); |
6518 | 5935 } |
5936 | |
5937 DEFUN (transpose, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
5938 "-*- texinfo -*-\n\ |
6518 | 5939 @deftypefn {Built-in Function} {} 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
|
5940 Return the transpose of @var{x}.\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
5941 \n\ |
17268
1c21f264d26f
doc: Rename @xcode macro to @tcode (transpose code) for clarity.
Rik <rik@octave.org>
parents:
17206
diff
changeset
|
5942 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
|
5943 @seealso{ctranspose}\n\ |
6518 | 5944 @end deftypefn") |
5945 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5946 return unary_op_defun_body (octave_value::op_transpose, args); |
6518 | 5947 } |
5948 | |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5949 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5950 %!assert (2.', 2) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5951 %!assert (2i.', 2i) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5952 %!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
|
5953 %!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
|
5954 %!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
|
5955 %!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
|
5956 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5957 %!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
|
5958 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5959 %!assert (single (2).', single (2)) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5960 %!assert (single (2i).', single (2i)) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5961 %!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
|
5962 %!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
|
5963 %!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
|
5964 %!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
|
5965 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5966 %!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
|
5967 */ |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5968 |
6518 | 5969 DEFUN (ctranspose, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
5970 "-*- texinfo -*-\n\ |
6518 | 5971 @deftypefn {Built-in Function} {} 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
|
5972 Return the complex conjugate transpose of @var{x}.\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
5973 \n\ |
17268
1c21f264d26f
doc: Rename @xcode macro to @tcode (transpose code) for clarity.
Rik <rik@octave.org>
parents:
17206
diff
changeset
|
5974 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
|
5975 @seealso{transpose}\n\ |
6518 | 5976 @end deftypefn") |
5977 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5978 return unary_op_defun_body (octave_value::op_hermitian, args); |
6518 | 5979 } |
5980 | |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5981 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5982 %!assert (2', 2) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5983 %!assert (2i', -2i) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5984 %!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
|
5985 %!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
|
5986 %!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
|
5987 %!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
|
5988 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5989 %!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
|
5990 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5991 %!assert (single (2)', single (2)) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5992 %!assert (single (2i)', single (-2i)) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5993 %!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
|
5994 %!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
|
5995 %!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
|
5996 %!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
|
5997 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5998 %!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
|
5999 */ |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
6000 |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
6001 static octave_value |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
6002 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
|
6003 const octave_value_list& args) |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
6004 { |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
6005 octave_value retval; |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
6006 |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
6007 if (args.length () == 2) |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
6008 retval = do_binary_op (op, args(0), args(1)); |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
6009 else |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
6010 print_usage (); |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
6011 |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
6012 return retval; |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
6013 } |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
6014 |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
6015 static octave_value |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
6016 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
|
6017 octave_value::assign_op aop, |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
6018 const octave_value_list& args) |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
6019 { |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
6020 octave_value retval; |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
6021 int nargin = args.length (); |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
6022 |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
6023 switch (nargin) |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
6024 { |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
6025 case 0: |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
6026 print_usage (); |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
6027 break; |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
6028 case 1: |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
6029 retval = args(0); |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
6030 break; |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
6031 case 2: |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
6032 retval = do_binary_op (op, args(0), args(1)); |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
6033 break; |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
6034 default: |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
6035 retval = do_binary_op (op, args(0), args(1)); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
6036 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
|
6037 retval.assign (aop, args(i)); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
6038 break; |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
6039 } |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
6040 |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
6041 return retval; |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
6042 } |
9339
c0b104835d0d
allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
6043 |
6518 | 6044 DEFUN (plus, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
6045 "-*- texinfo -*-\n\ |
10840 | 6046 @deftypefn {Built-in Function} {} plus (@var{x}, @var{y})\n\ |
9339
c0b104835d0d
allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
6047 @deftypefnx {Built-in Function} {} 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
|
6048 This function and @w{@tcode{x + y}} are equivalent.\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
6049 \n\ |
9339
c0b104835d0d
allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
6050 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
|
6051 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
|
6052 \n\ |
c0b104835d0d
allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
6053 @example\n\ |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
6054 (@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
|
6055 @end example\n\ |
c0b104835d0d
allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
6056 \n\ |
11422
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
6057 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
|
6058 @seealso{minus, uplus}\n\ |
6518 | 6059 @end deftypefn") |
6060 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
6061 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
|
6062 octave_value::op_add_eq, args); |
6518 | 6063 } |
6064 | |
6065 DEFUN (minus, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
6066 "-*- texinfo -*-\n\ |
6518 | 6067 @deftypefn {Built-in Function} {} 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
|
6068 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
|
6069 @seealso{plus, uminus}\n\ |
6518 | 6070 @end deftypefn") |
6071 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
6072 return binary_op_defun_body (octave_value::op_sub, args); |
6518 | 6073 } |
6074 | |
6075 DEFUN (mtimes, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
6076 "-*- texinfo -*-\n\ |
10840 | 6077 @deftypefn {Built-in Function} {} mtimes (@var{x}, @var{y})\n\ |
9339
c0b104835d0d
allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
6078 @deftypefnx {Built-in Function} {} mtimes (@var{x1}, @var{x2}, @dots{})\n\ |
11575
d6619410e79c
Spellcheck documentation before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents:
11572
diff
changeset
|
6079 Return the matrix multiplication product of inputs.\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
6080 \n\ |
17268
1c21f264d26f
doc: Rename @xcode macro to @tcode (transpose code) for clarity.
Rik <rik@octave.org>
parents:
17206
diff
changeset
|
6081 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
|
6082 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
|
6083 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
|
6084 \n\ |
c0b104835d0d
allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
6085 @example\n\ |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
6086 (@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
|
6087 @end example\n\ |
c0b104835d0d
allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
6088 \n\ |
11575
d6619410e79c
Spellcheck documentation before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents:
11572
diff
changeset
|
6089 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
|
6090 @seealso{times, plus, minus, rdivide, mrdivide, mldivide, mpower}\n\ |
6518 | 6091 @end deftypefn") |
6092 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
6093 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
|
6094 octave_value::op_mul_eq, args); |
6518 | 6095 } |
6096 | |
6097 DEFUN (mrdivide, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
6098 "-*- texinfo -*-\n\ |
6518 | 6099 @deftypefn {Built-in Function} {} mrdivide (@var{x}, @var{y})\n\ |
11422
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
6100 Return the matrix right division of @var{x} and @var{y}.\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
6101 \n\ |
17268
1c21f264d26f
doc: Rename @xcode macro to @tcode (transpose code) for clarity.
Rik <rik@octave.org>
parents:
17206
diff
changeset
|
6102 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
|
6103 @seealso{mldivide, rdivide, plus, minus}\n\ |
6518 | 6104 @end deftypefn") |
6105 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
6106 return binary_op_defun_body (octave_value::op_div, args); |
6518 | 6107 } |
6108 | |
6109 DEFUN (mpower, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
6110 "-*- texinfo -*-\n\ |
6518 | 6111 @deftypefn {Built-in Function} {} mpower (@var{x}, @var{y})\n\ |
11422
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
6112 Return the matrix power operation of @var{x} raised to the @var{y} power.\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
6113 \n\ |
17268
1c21f264d26f
doc: Rename @xcode macro to @tcode (transpose code) for clarity.
Rik <rik@octave.org>
parents:
17206
diff
changeset
|
6114 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
|
6115 @seealso{power, mtimes, plus, minus}\n\ |
6518 | 6116 @end deftypefn") |
6117 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
6118 return binary_op_defun_body (octave_value::op_pow, args); |
6518 | 6119 } |
6120 | |
6121 DEFUN (mldivide, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
6122 "-*- texinfo -*-\n\ |
6518 | 6123 @deftypefn {Built-in Function} {} mldivide (@var{x}, @var{y})\n\ |
11422
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
6124 Return the matrix left division of @var{x} and @var{y}.\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
6125 \n\ |
17268
1c21f264d26f
doc: Rename @xcode macro to @tcode (transpose code) for clarity.
Rik <rik@octave.org>
parents:
17206
diff
changeset
|
6126 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
|
6127 @seealso{mrdivide, ldivide, rdivide}\n\ |
6518 | 6128 @end deftypefn") |
6129 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
6130 return binary_op_defun_body (octave_value::op_ldiv, args); |
6518 | 6131 } |
6132 | |
6133 DEFUN (lt, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
6134 "-*- texinfo -*-\n\ |
6518 | 6135 @deftypefn {Built-in Function} {} lt (@var{x}, @var{y})\n\ |
11422
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
6136 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
|
6137 @seealso{le, eq, ge, gt, ne}\n\ |
6518 | 6138 @end deftypefn") |
6139 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
6140 return binary_op_defun_body (octave_value::op_lt, args); |
6518 | 6141 } |
6142 | |
6143 DEFUN (le, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
6144 "-*- texinfo -*-\n\ |
6518 | 6145 @deftypefn {Built-in Function} {} le (@var{x}, @var{y})\n\ |
11422
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
6146 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
|
6147 @seealso{eq, ge, gt, ne, lt}\n\ |
6518 | 6148 @end deftypefn") |
6149 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
6150 return binary_op_defun_body (octave_value::op_le, args); |
6518 | 6151 } |
6152 | |
6153 DEFUN (eq, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
6154 "-*- texinfo -*-\n\ |
6518 | 6155 @deftypefn {Built-in Function} {} eq (@var{x}, @var{y})\n\ |
11422
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
6156 Return true if the two inputs are equal.\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
6157 \n\ |
11422
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
6158 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
|
6159 @seealso{ne, isequal, le, ge, gt, ne, lt}\n\ |
6518 | 6160 @end deftypefn") |
6161 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
6162 return binary_op_defun_body (octave_value::op_eq, args); |
6518 | 6163 } |
6164 | |
6165 DEFUN (ge, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
6166 "-*- texinfo -*-\n\ |
6518 | 6167 @deftypefn {Built-in Function} {} ge (@var{x}, @var{y})\n\ |
11422
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
6168 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
|
6169 @seealso{le, eq, gt, ne, lt}\n\ |
6518 | 6170 @end deftypefn") |
6171 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
6172 return binary_op_defun_body (octave_value::op_ge, args); |
6518 | 6173 } |
6174 | |
6175 DEFUN (gt, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
6176 "-*- texinfo -*-\n\ |
6518 | 6177 @deftypefn {Built-in Function} {} gt (@var{x}, @var{y})\n\ |
11422
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
6178 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
|
6179 @seealso{le, eq, ge, ne, lt}\n\ |
6518 | 6180 @end deftypefn") |
6181 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
6182 return binary_op_defun_body (octave_value::op_gt, args); |
6518 | 6183 } |
6184 | |
6185 DEFUN (ne, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
6186 "-*- texinfo -*-\n\ |
6518 | 6187 @deftypefn {Built-in Function} {} ne (@var{x}, @var{y})\n\ |
11422
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
6188 Return true if the two inputs are not equal.\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
6189 \n\ |
11422
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
6190 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
|
6191 @seealso{eq, isequal, le, ge, lt}\n\ |
6518 | 6192 @end deftypefn") |
6193 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
6194 return binary_op_defun_body (octave_value::op_ne, args); |
6518 | 6195 } |
6196 | |
6197 DEFUN (times, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
6198 "-*- texinfo -*-\n\ |
10840 | 6199 @deftypefn {Built-in Function} {} times (@var{x}, @var{y})\n\ |
9339
c0b104835d0d
allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
6200 @deftypefnx {Built-in Function} {} 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
|
6201 Return the element-by-element multiplication product of inputs.\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
6202 \n\ |
17268
1c21f264d26f
doc: Rename @xcode macro to @tcode (transpose code) for clarity.
Rik <rik@octave.org>
parents:
17206
diff
changeset
|
6203 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
|
6204 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
|
6205 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
|
6206 \n\ |
c0b104835d0d
allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
6207 @example\n\ |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
6208 (@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
|
6209 @end example\n\ |
c0b104835d0d
allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
6210 \n\ |
11422
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
6211 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
|
6212 @seealso{mtimes, rdivide}\n\ |
6518 | 6213 @end deftypefn") |
6214 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
6215 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
|
6216 octave_value::op_el_mul_eq, args); |
6518 | 6217 } |
6218 | |
6219 DEFUN (rdivide, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
6220 "-*- texinfo -*-\n\ |
6518 | 6221 @deftypefn {Built-in Function} {} rdivide (@var{x}, @var{y})\n\ |
11422
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
6222 Return the element-by-element right division of @var{x} and @var{y}.\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
6223 \n\ |
17268
1c21f264d26f
doc: Rename @xcode macro to @tcode (transpose code) for clarity.
Rik <rik@octave.org>
parents:
17206
diff
changeset
|
6224 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
|
6225 @seealso{ldivide, mrdivide, times, plus}\n\ |
6518 | 6226 @end deftypefn") |
6227 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
6228 return binary_op_defun_body (octave_value::op_el_div, args); |
6518 | 6229 } |
6230 | |
6231 DEFUN (power, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
6232 "-*- texinfo -*-\n\ |
6518 | 6233 @deftypefn {Built-in Function} {} power (@var{x}, @var{y})\n\ |
11422
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
6234 Return the element-by-element operation of @var{x} raised to the\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
6235 @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
|
6236 \n\ |
17268
1c21f264d26f
doc: Rename @xcode macro to @tcode (transpose code) for clarity.
Rik <rik@octave.org>
parents:
17206
diff
changeset
|
6237 This function and @w{@tcode{x .^ y}} are equivalent.\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
6238 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
6239 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:
20068
diff
changeset
|
6240 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:
20068
diff
changeset
|
6241 @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:
20068
diff
changeset
|
6242 \n\ |
14169
c0ca47ab7641
doc: Better explain which complex result is chosen by .^
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
6243 @seealso{mpower, realpow, realsqrt, cbrt, nthroot}\n\ |
6518 | 6244 @end deftypefn") |
6245 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
6246 return binary_op_defun_body (octave_value::op_el_pow, args); |
6518 | 6247 } |
6248 | |
6249 DEFUN (ldivide, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
6250 "-*- texinfo -*-\n\ |
6518 | 6251 @deftypefn {Built-in Function} {} ldivide (@var{x}, @var{y})\n\ |
11422
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
6252 Return the element-by-element left division of @var{x} and @var{y}.\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
6253 \n\ |
17268
1c21f264d26f
doc: Rename @xcode macro to @tcode (transpose code) for clarity.
Rik <rik@octave.org>
parents:
17206
diff
changeset
|
6254 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
|
6255 @seealso{rdivide, mldivide, times, plus}\n\ |
6518 | 6256 @end deftypefn") |
6257 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
6258 return binary_op_defun_body (octave_value::op_el_ldiv, args); |
6518 | 6259 } |
6260 | |
6261 DEFUN (and, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
6262 "-*- texinfo -*-\n\ |
19380
c3611856cdd4
xor.m: Extend to handle more than 2 arguments as a reduction operator.
Rik <rik@octave.org>
parents:
19344
diff
changeset
|
6263 @deftypefn {Built-in Function} {@var{z} =} and (@var{x}, @var{y})\n\ |
c3611856cdd4
xor.m: Extend to handle more than 2 arguments as a reduction operator.
Rik <rik@octave.org>
parents:
19344
diff
changeset
|
6264 @deftypefnx {Built-in Function} {@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
|
6265 Return the logical AND of @var{x} and @var{y}.\n\ |
19380
c3611856cdd4
xor.m: Extend to handle more than 2 arguments as a reduction operator.
Rik <rik@octave.org>
parents:
19344
diff
changeset
|
6266 \n\ |
c3611856cdd4
xor.m: Extend to handle more than 2 arguments as a reduction operator.
Rik <rik@octave.org>
parents:
19344
diff
changeset
|
6267 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:
19344
diff
changeset
|
6268 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:
19344
diff
changeset
|
6269 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
|
6270 \n\ |
c0b104835d0d
allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
6271 @example\n\ |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
6272 (@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
|
6273 @end example\n\ |
c0b104835d0d
allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
6274 \n\ |
11422
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
6275 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
|
6276 @seealso{or, not, xor}\n\ |
6518 | 6277 @end deftypefn") |
6278 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
6279 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
|
6280 octave_value::op_el_and_eq, args); |
6518 | 6281 } |
6282 | |
6283 DEFUN (or, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
6284 "-*- texinfo -*-\n\ |
19380
c3611856cdd4
xor.m: Extend to handle more than 2 arguments as a reduction operator.
Rik <rik@octave.org>
parents:
19344
diff
changeset
|
6285 @deftypefn {Built-in Function} {@var{z} =} or (@var{x}, @var{y})\n\ |
c3611856cdd4
xor.m: Extend to handle more than 2 arguments as a reduction operator.
Rik <rik@octave.org>
parents:
19344
diff
changeset
|
6286 @deftypefnx {Built-in Function} {@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
|
6287 Return the logical OR of @var{x} and @var{y}.\n\ |
19380
c3611856cdd4
xor.m: Extend to handle more than 2 arguments as a reduction operator.
Rik <rik@octave.org>
parents:
19344
diff
changeset
|
6288 \n\ |
c3611856cdd4
xor.m: Extend to handle more than 2 arguments as a reduction operator.
Rik <rik@octave.org>
parents:
19344
diff
changeset
|
6289 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:
19344
diff
changeset
|
6290 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:
19344
diff
changeset
|
6291 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
|
6292 \n\ |
c0b104835d0d
allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
6293 @example\n\ |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
6294 (@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
|
6295 @end example\n\ |
c0b104835d0d
allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
6296 \n\ |
11422
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
6297 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
|
6298 @seealso{and, not, xor}\n\ |
6518 | 6299 @end deftypefn") |
6300 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
6301 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
|
6302 octave_value::op_el_or_eq, args); |
6518 | 6303 } |
6304 | |
19954
c913247c85a8
make colon function work (bug #44290)
John W. Eaton <jwe@octave.org>
parents:
19948
diff
changeset
|
6305 DEFUN (colon, args, , |
c913247c85a8
make colon function work (bug #44290)
John W. Eaton <jwe@octave.org>
parents:
19948
diff
changeset
|
6306 "-*- texinfo -*-\n\ |
c913247c85a8
make colon function work (bug #44290)
John W. Eaton <jwe@octave.org>
parents:
19948
diff
changeset
|
6307 @deftypefn {Built-in Function} {@var{r} =} colon (@var{base}, @var{limit})\n\ |
20000
ca7599ae464d
doc: Grammarcheck documentation ahead of 4.0 release.
Rik <rik@octave.org>
parents:
19954
diff
changeset
|
6308 @deftypefnx {Built-in Function} {@var{r} =} colon (@var{base}, @var{increment}, @var{limit})\n\ |
ca7599ae464d
doc: Grammarcheck documentation ahead of 4.0 release.
Rik <rik@octave.org>
parents:
19954
diff
changeset
|
6309 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:
19954
diff
changeset
|
6310 @var{limit}, and optionally, @var{increment}.\n\ |
19954
c913247c85a8
make colon function work (bug #44290)
John W. Eaton <jwe@octave.org>
parents:
19948
diff
changeset
|
6311 \n\ |
c913247c85a8
make colon function work (bug #44290)
John W. Eaton <jwe@octave.org>
parents:
19948
diff
changeset
|
6312 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:
19948
diff
changeset
|
6313 or @w{@code{base : increment : limit}}.\n\ |
c913247c85a8
make colon function work (bug #44290)
John W. Eaton <jwe@octave.org>
parents:
19948
diff
changeset
|
6314 @end deftypefn") |
c913247c85a8
make colon function work (bug #44290)
John W. Eaton <jwe@octave.org>
parents:
19948
diff
changeset
|
6315 { |
c913247c85a8
make colon function work (bug #44290)
John W. Eaton <jwe@octave.org>
parents:
19948
diff
changeset
|
6316 octave_value retval; |
c913247c85a8
make colon function work (bug #44290)
John W. Eaton <jwe@octave.org>
parents:
19948
diff
changeset
|
6317 int nargin = args.length (); |
c913247c85a8
make colon function work (bug #44290)
John W. Eaton <jwe@octave.org>
parents:
19948
diff
changeset
|
6318 |
c913247c85a8
make colon function work (bug #44290)
John W. Eaton <jwe@octave.org>
parents:
19948
diff
changeset
|
6319 switch (nargin) |
c913247c85a8
make colon function work (bug #44290)
John W. Eaton <jwe@octave.org>
parents:
19948
diff
changeset
|
6320 { |
c913247c85a8
make colon function work (bug #44290)
John W. Eaton <jwe@octave.org>
parents:
19948
diff
changeset
|
6321 case 2: |
c913247c85a8
make colon function work (bug #44290)
John W. Eaton <jwe@octave.org>
parents:
19948
diff
changeset
|
6322 retval = do_colon_op (args(0), args(1)); |
c913247c85a8
make colon function work (bug #44290)
John W. Eaton <jwe@octave.org>
parents:
19948
diff
changeset
|
6323 break; |
c913247c85a8
make colon function work (bug #44290)
John W. Eaton <jwe@octave.org>
parents:
19948
diff
changeset
|
6324 |
c913247c85a8
make colon function work (bug #44290)
John W. Eaton <jwe@octave.org>
parents:
19948
diff
changeset
|
6325 case 3: |
c913247c85a8
make colon function work (bug #44290)
John W. Eaton <jwe@octave.org>
parents:
19948
diff
changeset
|
6326 retval = do_colon_op (args(0), args(1), args (2)); |
c913247c85a8
make colon function work (bug #44290)
John W. Eaton <jwe@octave.org>
parents:
19948
diff
changeset
|
6327 break; |
c913247c85a8
make colon function work (bug #44290)
John W. Eaton <jwe@octave.org>
parents:
19948
diff
changeset
|
6328 |
c913247c85a8
make colon function work (bug #44290)
John W. Eaton <jwe@octave.org>
parents:
19948
diff
changeset
|
6329 default: |
c913247c85a8
make colon function work (bug #44290)
John W. Eaton <jwe@octave.org>
parents:
19948
diff
changeset
|
6330 print_usage (); |
c913247c85a8
make colon function work (bug #44290)
John W. Eaton <jwe@octave.org>
parents:
19948
diff
changeset
|
6331 break; |
c913247c85a8
make colon function work (bug #44290)
John W. Eaton <jwe@octave.org>
parents:
19948
diff
changeset
|
6332 } |
c913247c85a8
make colon function work (bug #44290)
John W. Eaton <jwe@octave.org>
parents:
19948
diff
changeset
|
6333 |
c913247c85a8
make colon function work (bug #44290)
John W. Eaton <jwe@octave.org>
parents:
19948
diff
changeset
|
6334 return retval; |
c913247c85a8
make colon function work (bug #44290)
John W. Eaton <jwe@octave.org>
parents:
19948
diff
changeset
|
6335 } |
c913247c85a8
make colon function work (bug #44290)
John W. Eaton <jwe@octave.org>
parents:
19948
diff
changeset
|
6336 |
7065 | 6337 static double tic_toc_timestamp = -1.0; |
7045 | 6338 |
6339 DEFUN (tic, args, nargout, | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
6340 "-*- texinfo -*-\n\ |
10840 | 6341 @deftypefn {Built-in Function} {} tic ()\n\ |
14853
72b8b39e12be
doc: Periodic grammarcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents:
14849
diff
changeset
|
6342 @deftypefnx {Built-in Function} {@var{id} =} tic ()\n\ |
7045 | 6343 @deftypefnx {Built-in Function} {} toc ()\n\ |
14635
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
6344 @deftypefnx {Built-in Function} {} toc (@var{id})\n\ |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
6345 @deftypefnx {Built-in Function} {@var{val} =} toc (@dots{})\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
6346 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:
20068
diff
changeset
|
6347 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
6348 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:
20068
diff
changeset
|
6349 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:
20068
diff
changeset
|
6350 was set.\n\ |
14635
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
6351 For example,\n\ |
7045 | 6352 \n\ |
6353 @example\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
9041
diff
changeset
|
6354 @group\n\ |
7045 | 6355 tic ();\n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
9041
diff
changeset
|
6356 # many computations later@dots{}\n\ |
7045 | 6357 elapsed_time = toc ();\n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
9041
diff
changeset
|
6358 @end group\n\ |
7045 | 6359 @end example\n\ |
6360 \n\ | |
6361 @noindent\n\ | |
6362 will set the variable @code{elapsed_time} to the number of seconds since\n\ | |
6363 the most recent call to the function @code{tic}.\n\ | |
6364 \n\ | |
14635
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
6365 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
|
6366 of type @code{uint64} that may be later passed to @code{toc}.\n\ |
7045 | 6367 \n\ |
6368 @example\n\ | |
6369 @group\n\ | |
14635
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
6370 id = tic; sleep (5); toc (id)\n\ |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
6371 @result{} 5.0010\n\ |
7045 | 6372 @end group\n\ |
6373 @end example\n\ | |
6374 \n\ | |
14635
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
6375 Calling @code{tic} and @code{toc} this way allows nested timing calls.\n\ |
7045 | 6376 \n\ |
6377 If you are more interested in the CPU time that your process used, you\n\ | |
6378 should use the @code{cputime} function instead. The @code{tic} and\n\ | |
6379 @code{toc} functions report the actual wall clock time that elapsed\n\ | |
6380 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
|
6381 doing nothing at all.\n\ |
15028
397f0d80bd47
Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents:
15024
diff
changeset
|
6382 @seealso{toc, cputime}\n\ |
7045 | 6383 @end deftypefn") |
6384 { | |
6385 octave_value retval; | |
7065 | 6386 |
7045 | 6387 int nargin = args.length (); |
6388 | |
6389 if (nargin != 0) | |
6390 warning ("tic: ignoring extra arguments"); | |
6391 | |
7065 | 6392 octave_time now; |
6393 | |
6394 double tmp = now.double_value (); | |
6395 | |
7045 | 6396 if (nargout > 0) |
14635
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
6397 { |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
6398 double ip = 0.0; |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
6399 double frac = modf (tmp, &ip); |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
6400 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
|
6401 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
|
6402 retval = octave_uint64 (microsecs); |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
6403 } |
7045 | 6404 else |
7065 | 6405 tic_toc_timestamp = tmp; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
6406 |
7045 | 6407 return retval; |
6408 } | |
6409 | |
6410 DEFUN (toc, args, nargout, | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
6411 "-*- texinfo -*-\n\ |
14853
72b8b39e12be
doc: Periodic grammarcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents:
14849
diff
changeset
|
6412 @deftypefn {Built-in Function} {} toc ()\n\ |
14635
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
6413 @deftypefnx {Built-in Function} {} toc (@var{id})\n\ |
14853
72b8b39e12be
doc: Periodic grammarcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents:
14849
diff
changeset
|
6414 @deftypefnx {Built-in Function} {@var{val} =} toc (@dots{})\n\ |
15028
397f0d80bd47
Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents:
15024
diff
changeset
|
6415 @seealso{tic, cputime}\n\ |
7045 | 6416 @end deftypefn") |
6417 { | |
6418 octave_value retval; | |
7065 | 6419 |
7045 | 6420 int nargin = args.length (); |
6421 | |
14635
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
6422 double start_time = tic_toc_timestamp; |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
6423 |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
6424 if (nargin > 1) |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
6425 print_usage (); |
7045 | 6426 else |
7065 | 6427 { |
14635
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
6428 if (nargin == 1) |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
6429 { |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
6430 octave_uint64 id = args(0).uint64_scalar_value (); |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
6431 |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
6432 if (! error_state) |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
6433 { |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
6434 uint64_t val = id.value (); |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
6435 |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
6436 start_time |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
6437 = (static_cast<double> (val / CLOCKS_PER_SEC) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
6438 + static_cast<double> (val % CLOCKS_PER_SEC) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
6439 / CLOCKS_PER_SEC); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
6440 |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
6441 // FIXME: should we also check to see whether the start |
14635
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
6442 // time is after the beginning of this Octave session? |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
6443 } |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
6444 else |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
6445 error ("toc: invalid ID"); |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
6446 } |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
6447 |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
6448 if (start_time < 0) |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
6449 error ("toc called before timer set"); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
6450 else |
14635
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
6451 { |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
6452 octave_time now; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
6453 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
6454 double tmp = now.double_value () - start_time; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
6455 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
6456 if (nargout > 0) |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
6457 retval = tmp; |
14635
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
6458 else |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
6459 octave_stdout << "Elapsed time is " << tmp << " seconds.\n"; |
14635
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
6460 } |
7065 | 6461 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
6462 |
7045 | 6463 return retval; |
6464 } | |
6465 | |
14635
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
6466 /* |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
6467 %!shared id |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
6468 %! id = tic (); |
14849
f6d3d5b0bd42
test: Use Octave coding conventions for tests for line() and toc().
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
6469 %!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
|
6470 %!assert (isa (toc (id), "double")) |
14635
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
6471 */ |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
6472 |
7045 | 6473 DEFUN (cputime, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
6474 "-*- texinfo -*-\n\ |
7045 | 6475 @deftypefn {Built-in Function} {[@var{total}, @var{user}, @var{system}] =} cputime ();\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
6476 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:
20068
diff
changeset
|
6477 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
6478 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:
20068
diff
changeset
|
6479 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:
20068
diff
changeset
|
6480 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:
20068
diff
changeset
|
6481 in system mode, respectively.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
6482 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
6483 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:
20068
diff
changeset
|
6484 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:
20068
diff
changeset
|
6485 \n\ |
7045 | 6486 Note that because Octave used some CPU time to start, it is reasonable\n\ |
6487 to check to see if @code{cputime} works by checking to see if the total\n\ | |
6488 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
|
6489 @seealso{tic, toc}\n\ |
7045 | 6490 @end deftypefn") |
6491 { | |
6492 octave_value_list retval; | |
6493 int nargin = args.length (); | |
6494 double usr = 0.0; | |
6495 double sys = 0.0; | |
6496 | |
6497 if (nargin != 0) | |
6498 warning ("tic: ignoring extra arguments"); | |
6499 | |
6500 #if defined (HAVE_GETRUSAGE) | |
6501 | |
6502 struct rusage ru; | |
6503 | |
6504 getrusage (RUSAGE_SELF, &ru); | |
6505 | |
6506 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
|
6507 static_cast<double> (ru.ru_utime.tv_usec) * 1e-6; |
7045 | 6508 |
6509 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
|
6510 static_cast<double> (ru.ru_stime.tv_usec) * 1e-6; |
7045 | 6511 |
10240
fa7b5751730c
use gnulib time, sys_time, and sys_times modules
John W. Eaton <jwe@octave.org>
parents:
10185
diff
changeset
|
6512 #else |
7045 | 6513 |
6514 struct tms t; | |
6515 | |
6516 times (&t); | |
6517 | |
6518 unsigned long ticks; | |
6519 unsigned long seconds; | |
6520 unsigned long fraction; | |
6521 | |
6522 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
|
6523 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
|
6524 seconds = ticks / CLOCKS_PER_SEC; |
7045 | 6525 |
6526 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
|
6527 static_cast<double>(CLOCKS_PER_SEC); |
7045 | 6528 |
6529 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
|
6530 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
|
6531 seconds = ticks / CLOCKS_PER_SEC; |
7045 | 6532 |
6533 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
|
6534 static_cast<double>(CLOCKS_PER_SEC); |
7045 | 6535 |
6536 #endif | |
6537 | |
14843
7d4f87c75dbb
data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents:
14635
diff
changeset
|
6538 retval(2) = sys; |
7d4f87c75dbb
data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents:
14635
diff
changeset
|
6539 retval(1) = usr; |
7d4f87c75dbb
data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents:
14635
diff
changeset
|
6540 retval(0) = sys + usr; |
7045 | 6541 |
6542 return retval; | |
6543 } | |
6544 | |
7433 | 6545 DEFUN (sort, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
6546 "-*- texinfo -*-\n\ |
15038
ab18578c2ade
doc: Update docstrings for built-in functions to not use "Loadable Function" as type.
Rik <rik@octave.org>
parents:
15034
diff
changeset
|
6547 @deftypefn {Built-in Function} {[@var{s}, @var{i}] =} sort (@var{x})\n\ |
ab18578c2ade
doc: Update docstrings for built-in functions to not use "Loadable Function" as type.
Rik <rik@octave.org>
parents:
15034
diff
changeset
|
6548 @deftypefnx {Built-in Function} {[@var{s}, @var{i}] =} sort (@var{x}, @var{dim})\n\ |
ab18578c2ade
doc: Update docstrings for built-in functions to not use "Loadable Function" as type.
Rik <rik@octave.org>
parents:
15034
diff
changeset
|
6549 @deftypefnx {Built-in Function} {[@var{s}, @var{i}] =} sort (@var{x}, @var{mode})\n\ |
ab18578c2ade
doc: Update docstrings for built-in functions to not use "Loadable Function" as type.
Rik <rik@octave.org>
parents:
15034
diff
changeset
|
6550 @deftypefnx {Built-in Function} {[@var{s}, @var{i}] =} sort (@var{x}, @var{dim}, @var{mode})\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
6551 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:
20068
diff
changeset
|
6552 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
6553 For matrices, @code{sort} orders the elements within columns\n\ |
7433 | 6554 \n\ |
10840 | 6555 For example:\n\ |
7433 | 6556 \n\ |
6557 @example\n\ | |
6558 @group\n\ | |
6559 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
|
6560 @result{} 1 1\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
6561 2 2\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
6562 3 3\n\ |
7433 | 6563 @end group\n\ |
6564 @end example\n\ | |
6565 \n\ | |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
6566 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
|
6567 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
|
6568 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
|
6569 @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
|
6570 \n\ |
7433 | 6571 The @code{sort} function may also be used to produce a matrix\n\ |
6572 containing the original row indices of the elements in the sorted\n\ | |
10840 | 6573 matrix. For example:\n\ |
7433 | 6574 \n\ |
6575 @example\n\ | |
6576 @group\n\ | |
6577 [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
|
6578 @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
|
6579 2 2\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
6580 3 3\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
6581 @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
|
6582 2 1\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
6583 3 2\n\ |
7433 | 6584 @end group\n\ |
6585 @end example\n\ | |
6586 \n\ | |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
6587 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
|
6588 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
|
6589 \n\ |
20780
c6059134f5d3
data.cc: Add @w{} around @code segments in docstrings to prevent line breaks.
Rik <rik@octave.org>
parents:
20608
diff
changeset
|
6590 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:
20608
diff
changeset
|
6591 (@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:
20608
diff
changeset
|
6592 (@w{@code{angle (z)}}). For example:\n\ |
7433 | 6593 \n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
6594 @example\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
6595 @group\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
6596 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
|
6597 @result{} 1 + 0i\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
6598 1 - 1i\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
6599 1 + 1i\n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
6600 @end group\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
6601 @end example\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
6602 \n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
6603 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
|
6604 to the end of the list.\n\ |
7433 | 6605 \n\ |
6606 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
|
6607 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
|
6608 lowercase 'a') of the strings is used.\n\ |
7433 | 6609 \n\ |
6610 The algorithm used in @code{sort} is optimized for the sorting of partially\n\ | |
6611 ordered lists.\n\ | |
15028
397f0d80bd47
Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents:
15024
diff
changeset
|
6612 @seealso{sortrows, issorted}\n\ |
7433 | 6613 @end deftypefn") |
6614 { | |
6615 octave_value_list retval; | |
6616 | |
6617 int nargin = args.length (); | |
6618 sortmode smode = ASCENDING; | |
6619 | |
6620 if (nargin < 1 || nargin > 3) | |
6621 { | |
6622 print_usage (); | |
6623 return retval; | |
6624 } | |
6625 | |
6626 bool return_idx = nargout > 1; | |
6627 | |
6628 octave_value arg = args(0); | |
6629 | |
6630 int dim = 0; | |
6631 if (nargin > 1) | |
6632 { | |
6633 if (args(1).is_string ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
6634 { |
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
|
6635 std::string mode = args(1).string_value (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
6636 if (mode == "ascend") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
6637 smode = ASCENDING; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
6638 else if (mode == "descend") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
6639 smode = DESCENDING; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
6640 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
6641 { |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11591
diff
changeset
|
6642 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
|
6643 return retval; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
6644 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
6645 } |
7433 | 6646 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
6647 dim = args(1).nint_value () - 1; |
7433 | 6648 } |
6649 | |
6650 if (nargin > 2) | |
6651 { | |
6652 if (args(1).is_string ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
6653 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
6654 print_usage (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
6655 return retval; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
6656 } |
7433 | 6657 |
20793
ba2b07c13913
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6658 std::string mode = args(2).string_value ("sort: MODE must be a string"); |
ba2b07c13913
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6659 |
7433 | 6660 if (mode == "ascend") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
6661 smode = ASCENDING; |
7433 | 6662 else if (mode == "descend") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
6663 smode = DESCENDING; |
7433 | 6664 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
6665 { |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11591
diff
changeset
|
6666 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
|
6667 return retval; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
6668 } |
7433 | 6669 } |
6670 | |
10285
22a7913bbeb5
optimize return values of find and sort
Jaroslav Hajek <highegg@gmail.com>
parents:
10277
diff
changeset
|
6671 const dim_vector dv = arg.dims (); |
7433 | 6672 if (nargin == 1 || args(1).is_string ()) |
6673 { | |
6674 // Find first non singleton dimension | |
10285
22a7913bbeb5
optimize return values of find and sort
Jaroslav Hajek <highegg@gmail.com>
parents:
10277
diff
changeset
|
6675 dim = dv.first_non_singleton (); |
7433 | 6676 } |
6677 else | |
6678 { | |
10703
5eb420d92307
fix sort and nth_element when trailing singleton dim is specified
Jaroslav Hajek <highegg@gmail.com>
parents:
10695
diff
changeset
|
6679 if (dim < 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
6680 { |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11591
diff
changeset
|
6681 error ("sort: DIM must be a valid dimension"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
6682 return retval; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
6683 } |
7433 | 6684 } |
6685 | |
6686 if (return_idx) | |
6687 { | |
14022
de90542b7afc
Return retval(1) before retval(0) to avoid re-sizing call on retval.
Rik <octave@nomad.inbox5.com>
parents:
13929
diff
changeset
|
6688 retval.resize (2); |
de90542b7afc
Return retval(1) before retval(0) to avoid re-sizing call on retval.
Rik <octave@nomad.inbox5.com>
parents:
13929
diff
changeset
|
6689 |
7433 | 6690 Array<octave_idx_type> sidx; |
6691 | |
14843
7d4f87c75dbb
data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents:
14635
diff
changeset
|
6692 retval(0) = arg.sort (sidx, dim, smode); |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
6693 retval(1) = idx_vector (sidx, dv(dim)); // No checking, extent is known. |
7433 | 6694 } |
6695 else | |
6696 retval(0) = arg.sort (dim, smode); | |
6697 | |
6698 return retval; | |
6699 } | |
6700 | |
6701 /* | |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6702 ## Double |
7433 | 6703 %!assert (sort ([NaN, 1, -1, 2, Inf]), [-1, 1, 2, Inf, NaN]) |
6704 %!assert (sort ([NaN, 1, -1, 2, Inf], 1), [NaN, 1, -1, 2, Inf]) | |
6705 %!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
|
6706 %!assert (sort ([NaN, 1, -1, 2, Inf], 3), [NaN, 1, -1, 2, Inf]) |
7433 | 6707 %!assert (sort ([NaN, 1, -1, 2, Inf], "ascend"), [-1, 1, 2, Inf, NaN]) |
6708 %!assert (sort ([NaN, 1, -1, 2, Inf], 2, "ascend"), [-1, 1, 2, Inf, NaN]) | |
6709 %!assert (sort ([NaN, 1, -1, 2, Inf], "descend"), [NaN, Inf, 2, 1, -1]) | |
6710 %!assert (sort ([NaN, 1, -1, 2, Inf], 2, "descend"), [NaN, Inf, 2, 1, -1]) | |
6711 %!assert (sort ([3, 1, 7, 5; 8, 2, 6, 4]), [3, 1, 6, 4; 8, 2, 7, 5]) | |
6712 %!assert (sort ([3, 1, 7, 5; 8, 2, 6, 4], 1), [3, 1, 6, 4; 8, 2, 7, 5]) | |
6713 %!assert (sort ([3, 1, 7, 5; 8, 2, 6, 4], 2), [1, 3, 5, 7; 2, 4, 6, 8]) | |
6714 %!assert (sort (1), 1) | |
6715 | |
6716 %!test | |
6717 %! [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
|
6718 %! 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
|
6719 %! 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
|
6720 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6721 ## Complex |
7433 | 6722 %!assert (sort ([NaN, 1i, -1, 2, Inf]), [1i, -1, 2, Inf, NaN]) |
6723 %!assert (sort ([NaN, 1i, -1, 2, Inf], 1), [NaN, 1i, -1, 2, Inf]) | |
6724 %!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
|
6725 %!assert (sort ([NaN, 1i, -1, 2, Inf], 3), [NaN, 1i, -1, 2, Inf]) |
7433 | 6726 %!assert (sort ([NaN, 1i, -1, 2, Inf], "ascend"), [1i, -1, 2, Inf, NaN]) |
6727 %!assert (sort ([NaN, 1i, -1, 2, Inf], 2, "ascend"), [1i, -1, 2, Inf, NaN]) | |
6728 %!assert (sort ([NaN, 1i, -1, 2, Inf], "descend"), [NaN, Inf, 2, -1, 1i]) | |
6729 %!assert (sort ([NaN, 1i, -1, 2, Inf], 2, "descend"), [NaN, Inf, 2, -1, 1i]) | |
6730 %!assert (sort ([3, 1i, 7, 5; 8, 2, 6, 4]), [3, 1i, 6, 4; 8, 2, 7, 5]) | |
6731 %!assert (sort ([3, 1i, 7, 5; 8, 2, 6, 4], 1), [3, 1i, 6, 4; 8, 2, 7, 5]) | |
6732 %!assert (sort ([3, 1i, 7, 5; 8, 2, 6, 4], 2), [1i, 3, 5, 7; 2, 4, 6, 8]) | |
6733 %!assert (sort (1i), 1i) | |
6734 | |
6735 %!test | |
6736 %! [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
|
6737 %! 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
|
6738 %! 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
|
6739 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6740 ## Single |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6741 %!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
|
6742 %!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
|
6743 %!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
|
6744 %!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
|
6745 %!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
|
6746 %!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
|
6747 %!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
|
6748 %!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
|
6749 %!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
|
6750 %!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
|
6751 %!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
|
6752 %!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
|
6753 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
6754 %!test |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6755 %! [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
|
6756 %! 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
|
6757 %! 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
|
6758 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6759 ## Single Complex |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6760 %!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
|
6761 %!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
|
6762 %!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
|
6763 %!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
|
6764 %!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
|
6765 %!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
|
6766 %!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
|
6767 %!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
|
6768 %!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
|
6769 %!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
|
6770 %!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
|
6771 %!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
|
6772 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
6773 %!test |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6774 %! [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
|
6775 %! 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
|
6776 %! 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
|
6777 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6778 ## Bool |
7433 | 6779 %!assert (sort ([true, false, true, false]), [false, false, true, true]) |
6780 %!assert (sort ([true, false, true, false], 1), [true, false, true, false]) | |
6781 %!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
|
6782 %!assert (sort ([true, false, true, false], 3), [true, false, true, false]) |
7433 | 6783 %!assert (sort ([true, false, true, false], "ascend"), [false, false, true, true]) |
6784 %!assert (sort ([true, false, true, false], 2, "ascend"), [false, false, true, true]) | |
6785 %!assert (sort ([true, false, true, false], "descend"), [true, true, false, false]) | |
6786 %!assert (sort ([true, false, true, false], 2, "descend"), [true, true, false, false]) | |
6787 %!assert (sort (true), true) | |
6788 | |
6789 %!test | |
6790 %! [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
|
6791 %! 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
|
6792 %! 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
|
6793 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6794 ## Sparse Double |
7433 | 6795 %!assert (sort (sparse ([0, NaN, 1, 0, -1, 2, Inf])), sparse ([-1, 0, 0, 1, 2, Inf, NaN])) |
6796 %!assert (sort (sparse ([0, NaN, 1, 0, -1, 2, Inf]), 1), sparse ([0, NaN, 1, 0, -1, 2, Inf])) | |
6797 %!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
|
6798 %!assert (sort (sparse ([0, NaN, 1, 0, -1, 2, Inf]), 3), sparse ([0, NaN, 1, 0, -1, 2, Inf])) |
7433 | 6799 %!assert (sort (sparse ([0, NaN, 1, 0, -1, 2, Inf]), "ascend"), sparse ([-1, 0, 0, 1, 2, Inf, NaN])) |
6800 %!assert (sort (sparse ([0, NaN, 1, 0, -1, 2, Inf]), 2, "ascend"), sparse ([-1, 0, 0, 1, 2, Inf, NaN])) | |
6801 %!assert (sort (sparse ([0, NaN, 1, 0, -1, 2, Inf]), "descend"), sparse ([NaN, Inf, 2, 1, 0, 0, -1])) | |
6802 %!assert (sort (sparse ([0, NaN, 1, 0, -1, 2, Inf]), 2, "descend"), sparse ([NaN, Inf, 2, 1, 0, 0, -1])) | |
6803 | |
6804 %!shared a | |
6805 %! a = randn (10, 10); | |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6806 %! a(a < 0) = 0; |
7433 | 6807 %!assert (sort (sparse (a)), sparse (sort (a))) |
6808 %!assert (sort (sparse (a), 1), sparse (sort (a, 1))) | |
6809 %!assert (sort (sparse (a), 2), sparse (sort (a, 2))) | |
6810 %!test | |
6811 %! [v, i] = sort (a); | |
6812 %! [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
|
6813 %! assert (vs, sparse (v)); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6814 %! assert (is, i); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6815 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6816 ## Sparse Complex |
7433 | 6817 %!assert (sort (sparse ([0, NaN, 1i, 0, -1, 2, Inf])), sparse ([0, 0, 1i, -1, 2, Inf, NaN])) |
6818 %!assert (sort (sparse ([0, NaN, 1i, 0, -1, 2, Inf]), 1), sparse ([0, NaN, 1i, 0, -1, 2, Inf])) | |
6819 %!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
|
6820 %!assert (sort (sparse ([0, NaN, 1i, 0, -1, 2, Inf]), 3), sparse ([0, NaN, 1i, 0, -1, 2, Inf])) |
7433 | 6821 %!assert (sort (sparse ([0, NaN, 1i, 0, -1, 2, Inf]), "ascend"), sparse ([0, 0, 1i, -1, 2, Inf, NaN])) |
6822 %!assert (sort (sparse ([0, NaN, 1i, 0, -1, 2, Inf]), 2, "ascend"), sparse ([0, 0, 1i, -1, 2, Inf, NaN])) | |
6823 %!assert (sort (sparse ([0, NaN, 1i, 0, -1, 2, Inf]), "descend"), sparse ([NaN, Inf, 2, -1, 1i, 0, 0])) | |
6824 %!assert (sort (sparse ([0, NaN, 1i, 0, -1, 2, Inf]), 2, "descend"), sparse ([NaN, Inf, 2, -1, 1i, 0, 0])) | |
6825 | |
6826 %!shared a | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
6827 %! a = randn (10, 10); |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6828 %! a(a < 0) = 0; |
7433 | 6829 %! a = 1i * a; |
6830 %!assert (sort (sparse (a)), sparse (sort (a))) | |
6831 %!assert (sort (sparse (a), 1), sparse (sort (a, 1))) | |
6832 %!assert (sort (sparse (a), 2), sparse (sort (a, 2))) | |
6833 %!test | |
6834 %! [v, i] = sort (a); | |
6835 %! [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
|
6836 %! assert (vs, sparse (v)); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6837 %! assert (is, i); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6838 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6839 ## Sparse Bool |
7433 | 6840 %!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
|
6841 %!assert (sort (sparse ([true, false, true, false]), 1), sparse ([true, false, true, false])) |
7433 | 6842 %!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
|
6843 %!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
|
6844 %!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
|
6845 %!assert (sort (sparse ([true, false, true, false]), 2, "ascend"), sparse ([false, false, true, true])) |
7433 | 6846 %!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
|
6847 %!assert (sort (sparse ([true, false, true, false]), 2, "descend"), sparse ([true, true, false, false])) |
7433 | 6848 |
6849 %!test | |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6850 %! [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
|
6851 %! 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
|
6852 %! 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
|
6853 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6854 ## Cell string array |
7433 | 6855 %!shared a, b, c |
6856 %! a = {"Alice", "Cecile", "Eric", "Barry", "David"}; | |
6857 %! b = {"Alice", "Barry", "Cecile", "David", "Eric"}; | |
6858 %! 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
|
6859 %!assert (sort (a), b) |
7433 | 6860 %!assert (sort (a, 1), a) |
6861 %!assert (sort (a, 2), b) | |
10707
69c5f5ec55d7
fix invalid sort tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10703
diff
changeset
|
6862 %!assert (sort (a, 3), a) |
7433 | 6863 %!assert (sort (a, "ascend"), b) |
6864 %!assert (sort (a, 2, "ascend"), b) | |
6865 %!assert (sort (a, "descend"), c) | |
6866 %!assert (sort (a, 2, "descend"), c) | |
6867 | |
6868 %!test | |
6869 %! [v, i] = sort (a); | |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6870 %! 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
|
6871 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6872 %!error sort () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6873 %!error sort (1, 2, 3, 4) |
7433 | 6874 */ |
6875 | |
8812
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
8799
diff
changeset
|
6876 // 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
|
6877 // 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
|
6878 // 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
|
6879 // |
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
8799
diff
changeset
|
6880 // 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
|
6881 |
8733
3ef774603887
rename all uses of sortrows_idx to sort_rows_idx
John W. Eaton <jwe@octave.org>
parents:
8721
diff
changeset
|
6882 DEFUN (__sort_rows_idx__, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
6883 "-*- texinfo -*-\n\ |
9517
a85dbf7b6ff9
fix some functions help markup
Jaroslav Hajek <highegg@gmail.com>
parents:
9513
diff
changeset
|
6884 @deftypefn {Built-in Function} {} __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
|
6885 Undocumented internal function.\n\ |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6886 @end deftypefn\n") |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6887 { |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6888 octave_value retval; |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6889 |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6890 int nargin = args.length (); |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6891 sortmode smode = ASCENDING; |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6892 |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6893 if (nargin < 1 || nargin > 2 || (nargin == 2 && ! args(1).is_string ())) |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6894 { |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6895 print_usage (); |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6896 return retval; |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6897 } |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6898 |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6899 if (nargin > 1) |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6900 { |
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
|
6901 std::string mode = args(1).string_value (); |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6902 if (mode == "ascend") |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6903 smode = ASCENDING; |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6904 else if (mode == "descend") |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6905 smode = DESCENDING; |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6906 else |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6907 { |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11591
diff
changeset
|
6908 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
|
6909 return retval; |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6910 } |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6911 } |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6912 |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6913 octave_value arg = args(0); |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6914 |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6915 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
|
6916 error ("__sort_rows_idx__: sparse matrices not yet supported"); |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6917 if (arg.ndims () == 2) |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6918 { |
8733
3ef774603887
rename all uses of sortrows_idx to sort_rows_idx
John W. Eaton <jwe@octave.org>
parents:
8721
diff
changeset
|
6919 Array<octave_idx_type> idx = arg.sort_rows_idx (smode); |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6920 |
9351
e2344f4af0cb
autocache indices returned from find et al.
Jaroslav Hajek <highegg@gmail.com>
parents:
9339
diff
changeset
|
6921 retval = octave_value (idx, true, true); |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6922 } |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6923 else |
8733
3ef774603887
rename all uses of sortrows_idx to sort_rows_idx
John W. Eaton <jwe@octave.org>
parents:
8721
diff
changeset
|
6924 error ("__sort_rows_idx__: needs a 2-dimensional object"); |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6925 |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6926 return retval; |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6927 } |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6928 |
9765
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6929 static sortmode |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6930 get_sort_mode_option (const octave_value& arg, const char *argn) |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6931 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
6932 // FIXME: we initialize to UNSORTED here to avoid a GCC warning |
10076
4b270d1540f7
avoid various GCC warnings
John W. Eaton <jwe@octave.org>
parents:
10073
diff
changeset
|
6933 // about possibly using sortmode uninitialized. |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
6934 // 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
|
6935 sortmode smode = UNSORTED; |
9765
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6936 |
20793
ba2b07c13913
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6937 std::string mode = arg.string_value ("issorted: expecting %s argument to be a string", argn); |
ba2b07c13913
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6938 |
ba2b07c13913
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6939 if (mode == "ascending") |
ba2b07c13913
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6940 smode = ASCENDING; |
ba2b07c13913
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6941 else if (mode == "descending") |
ba2b07c13913
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6942 smode = DESCENDING; |
ba2b07c13913
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6943 else if (mode == "either") |
ba2b07c13913
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6944 smode = UNSORTED; |
9765
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6945 else |
20793
ba2b07c13913
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6946 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
|
6947 |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6948 return smode; |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6949 } |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6950 |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6951 DEFUN (issorted, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
6952 "-*- texinfo -*-\n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
6953 @deftypefn {Built-in Function} {} issorted (@var{a})\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
6954 @deftypefnx {Built-in Function} {} issorted (@var{a}, @var{mode})\n\ |
12681
c09ed93d1a8b
doc: Don't use @code{} within @deftypefn macro
Rik <octave@nomad.inbox5.com>
parents:
12642
diff
changeset
|
6955 @deftypefnx {Built-in Function} {} issorted (@var{a}, \"rows\", @var{mode})\n\ |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11422
diff
changeset
|
6956 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
|
6957 may be either @qcode{\"ascending\"}, @qcode{\"descending\"}, or\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
6958 @qcode{\"either\"}.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
6959 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
6960 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:
20068
diff
changeset
|
6961 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
|
6962 \n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17268
diff
changeset
|
6963 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
|
6964 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
|
6965 (with no options).\n\ |
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11422
diff
changeset
|
6966 \n\ |
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11422
diff
changeset
|
6967 This function does not support sparse matrices.\n\ |
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11422
diff
changeset
|
6968 @seealso{sort, sortrows}\n\ |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6969 @end deftypefn\n") |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6970 { |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6971 octave_value retval; |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6972 |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6973 int nargin = args.length (); |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6974 |
9765
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6975 if (nargin < 1 || nargin > 3) |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6976 { |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6977 print_usage (); |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6978 return retval; |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6979 } |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6980 |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6981 bool by_rows = false; |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6982 |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6983 sortmode smode = ASCENDING; |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6984 |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6985 if (nargin > 1) |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6986 { |
9765
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6987 octave_value mode_arg; |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6988 |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6989 if (nargin == 3) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
6990 smode = get_sort_mode_option (args(2), "third"); |
9765
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6991 |
20793
ba2b07c13913
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6992 std::string tmp = args(1).string_value ("issorted: second argument must be a string"); |
ba2b07c13913
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6993 if (tmp == "rows") |
ba2b07c13913
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6994 by_rows = true; |
9765
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6995 else |
20793
ba2b07c13913
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20785
diff
changeset
|
6996 smode = get_sort_mode_option (args(1), "second"); |
9765
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6997 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
6998 |
9765
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6999 octave_value arg = args(0); |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
7000 |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
7001 if (by_rows) |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
7002 { |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
7003 if (arg.is_sparse_type ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
7004 error ("issorted: sparse matrices not yet supported"); |
9765
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
7005 if (arg.ndims () == 2) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
7006 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
|
7007 else |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11591
diff
changeset
|
7008 error ("issorted: A must be a 2-dimensional object"); |
9765
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
7009 } |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
7010 else |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
7011 { |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
7012 if (arg.dims ().is_vector ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
7013 retval = args(0).is_sorted (smode) != UNSORTED; |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
7014 else |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
7015 error ("issorted: needs a vector"); |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
7016 } |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
7017 |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
7018 return retval; |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
7019 } |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
7020 |
9765
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
7021 /* |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
7022 %!shared sm, um, sv, uv |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
7023 %! sm = [1, 2; 3, 4]; |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
7024 %! um = [3, 1; 2, 4]; |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
7025 %! sv = [1, 2, 3, 4]; |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
7026 %! uv = [2, 1, 4, 3]; |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
7027 %!assert (issorted (sm, "rows")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
7028 %!assert (!issorted (um, "rows")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
7029 %!assert (issorted (sv)) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
7030 %!assert (!issorted (uv)) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
7031 %!assert (issorted (sv')) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
7032 %!assert (!issorted (uv')) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
7033 %!assert (issorted (sm, "rows", "ascending")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
7034 %!assert (!issorted (um, "rows", "ascending")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
7035 %!assert (issorted (sv, "ascending")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
7036 %!assert (!issorted (uv, "ascending")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
7037 %!assert (issorted (sv', "ascending")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
7038 %!assert (!issorted (uv', "ascending")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
7039 %!assert (!issorted (sm, "rows", "descending")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
7040 %!assert (issorted (flipud (sm), "rows", "descending")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
7041 %!assert (!issorted (sv, "descending")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
7042 %!assert (issorted (fliplr (sv), "descending")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
7043 %!assert (!issorted (sv', "descending")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
7044 %!assert (issorted (fliplr (sv)', "descending")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
7045 %!assert (!issorted (um, "rows", "either")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
7046 %!assert (!issorted (uv, "either")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
7047 %!assert (issorted (sm, "rows", "either")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
7048 %!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
|
7049 %!assert (issorted (sv, "either")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
7050 %!assert (issorted (fliplr (sv), "either")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
7051 %!assert (issorted (sv', "either")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
7052 %!assert (issorted (fliplr (sv)', "either")) |
9765
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
7053 */ |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
7054 |
9725 | 7055 DEFUN (nth_element, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
7056 "-*- texinfo -*-\n\ |
10840 | 7057 @deftypefn {Built-in Function} {} nth_element (@var{x}, @var{n})\n\ |
9725 | 7058 @deftypefnx {Built-in Function} {} nth_element (@var{x}, @var{n}, @var{dim})\n\ |
10840 | 7059 Select the n-th smallest element of a vector, using the ordering defined by\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
7060 @code{sort}.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
7061 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
7062 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:
20068
diff
changeset
|
7063 \n\ |
9725 | 7064 @var{n} can also be a contiguous range, either ascending @code{l:u}\n\ |
7065 or descending @code{u:-1:l}, in which case a range of elements is returned.\n\ | |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
7066 \n\ |
10846
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10840
diff
changeset
|
7067 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
|
7068 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
|
7069 not given.\n\ |
9725 | 7070 \n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
7071 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:
20068
diff
changeset
|
7072 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:
20068
diff
changeset
|
7073 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:
20068
diff
changeset
|
7074 @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:
20068
diff
changeset
|
7075 the ratio K/M is small; otherwise, it may be better to use @code{sort}.\n\ |
9725 | 7076 @seealso{sort, min, max}\n\ |
7077 @end deftypefn") | |
7078 { | |
7079 octave_value retval; | |
7080 int nargin = args.length (); | |
7081 | |
7082 if (nargin == 2 || nargin == 3) | |
7083 { | |
7084 octave_value argx = args(0); | |
7085 | |
7086 int dim = -1; | |
7087 if (nargin == 3) | |
7088 { | |
7089 dim = args(2).int_value (true) - 1; | |
10703
5eb420d92307
fix sort and nth_element when trailing singleton dim is specified
Jaroslav Hajek <highegg@gmail.com>
parents:
10695
diff
changeset
|
7090 if (dim < 0) |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11591
diff
changeset
|
7091 error ("nth_element: DIM must be a valid dimension"); |
9725 | 7092 } |
7093 if (dim < 0) | |
7094 dim = argx.dims ().first_non_singleton (); | |
7095 | |
20749
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20696
diff
changeset
|
7096 try |
9725 | 7097 { |
20749
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20696
diff
changeset
|
7098 idx_vector n = args(1).index_vector (); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20696
diff
changeset
|
7099 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20696
diff
changeset
|
7100 switch (argx.builtin_type ()) |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20696
diff
changeset
|
7101 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20696
diff
changeset
|
7102 case btyp_double: |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20696
diff
changeset
|
7103 retval = argx.array_value ().nth_element (n, dim); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20696
diff
changeset
|
7104 break; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20696
diff
changeset
|
7105 case btyp_float: |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20696
diff
changeset
|
7106 retval = argx.float_array_value ().nth_element (n, dim); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20696
diff
changeset
|
7107 break; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20696
diff
changeset
|
7108 case btyp_complex: |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20696
diff
changeset
|
7109 retval = argx.complex_array_value ().nth_element (n, dim); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20696
diff
changeset
|
7110 break; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20696
diff
changeset
|
7111 case btyp_float_complex: |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20696
diff
changeset
|
7112 retval = argx.float_complex_array_value ().nth_element (n, dim); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20696
diff
changeset
|
7113 break; |
9725 | 7114 #define MAKE_INT_BRANCH(X) \ |
20749
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20696
diff
changeset
|
7115 case btyp_ ## X: \ |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20696
diff
changeset
|
7116 retval = argx.X ## _array_value ().nth_element (n, dim); \ |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20696
diff
changeset
|
7117 break; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20696
diff
changeset
|
7118 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20696
diff
changeset
|
7119 MAKE_INT_BRANCH (int8); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20696
diff
changeset
|
7120 MAKE_INT_BRANCH (int16); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20696
diff
changeset
|
7121 MAKE_INT_BRANCH (int32); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20696
diff
changeset
|
7122 MAKE_INT_BRANCH (int64); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20696
diff
changeset
|
7123 MAKE_INT_BRANCH (uint8); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20696
diff
changeset
|
7124 MAKE_INT_BRANCH (uint16); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20696
diff
changeset
|
7125 MAKE_INT_BRANCH (uint32); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20696
diff
changeset
|
7126 MAKE_INT_BRANCH (uint64); |
9725 | 7127 #undef MAKE_INT_BRANCH |
20749
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20696
diff
changeset
|
7128 default: |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20696
diff
changeset
|
7129 if (argx.is_cellstr ()) |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20696
diff
changeset
|
7130 retval = argx.cellstr_value ().nth_element (n, dim); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20696
diff
changeset
|
7131 else |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20696
diff
changeset
|
7132 gripe_wrong_type_arg ("nth_element", argx); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20696
diff
changeset
|
7133 } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20696
diff
changeset
|
7134 } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20696
diff
changeset
|
7135 catch (index_exception& e) |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20696
diff
changeset
|
7136 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20696
diff
changeset
|
7137 error ("nth_element: invalid N value %s. %s", e.idx (), e.explain ()); |
9725 | 7138 } |
7139 } | |
7140 else | |
7141 print_usage (); | |
7142 | |
7143 return retval; | |
7144 } | |
7145 | |
8934
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
7146 template <class NDT> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
7147 static NDT |
8934
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
7148 do_accumarray_sum (const idx_vector& idx, const NDT& vals, |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
7149 octave_idx_type n = -1) |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
7150 { |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
7151 typedef typename NDT::element_type T; |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
7152 if (n < 0) |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
7153 n = idx.extent (0); |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
7154 else if (idx.extent (n) > n) |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
7155 error ("accumarray: index out of range"); |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
7156 |
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
|
7157 NDT retval (dim_vector (n, 1), T ()); |
8934
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
7158 |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
7159 if (vals.numel () == 1) |
9858
47c5af1868df
move idx_add methods to MArrayN
Jaroslav Hajek <highegg@gmail.com>
parents:
9856
diff
changeset
|
7160 retval.idx_add (idx, vals (0)); |
47c5af1868df
move idx_add methods to MArrayN
Jaroslav Hajek <highegg@gmail.com>
parents:
9856
diff
changeset
|
7161 else if (vals.numel () == idx.length (n)) |
47c5af1868df
move idx_add methods to MArrayN
Jaroslav Hajek <highegg@gmail.com>
parents:
9856
diff
changeset
|
7162 retval.idx_add (idx, vals); |
8934
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
7163 else |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
7164 error ("accumarray: dimensions mismatch"); |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
7165 |
9858
47c5af1868df
move idx_add methods to MArrayN
Jaroslav Hajek <highegg@gmail.com>
parents:
9856
diff
changeset
|
7166 return retval; |
8934
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
7167 } |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
7168 |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
7169 DEFUN (__accumarray_sum__, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
7170 "-*- texinfo -*-\n\ |
8934
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
7171 @deftypefn {Built-in Function} {} __accumarray_sum__ (@var{idx}, @var{vals}, @var{n})\n\ |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
7172 Undocumented internal function.\n\ |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
7173 @end deftypefn") |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
7174 { |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
7175 octave_value retval; |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
7176 int nargin = args.length (); |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
7177 if (nargin >= 2 && nargin <= 3 && args(0).is_numeric_type ()) |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
7178 { |
20749
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20696
diff
changeset
|
7179 try |
8934
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
7180 { |
20749
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20696
diff
changeset
|
7181 idx_vector idx = args(0).index_vector (); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20696
diff
changeset
|
7182 octave_idx_type n = -1; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20696
diff
changeset
|
7183 if (nargin == 3) |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20696
diff
changeset
|
7184 n = args(2).idx_type_value (true); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20696
diff
changeset
|
7185 |
8934
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
7186 octave_value vals = args(1); |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
7187 |
9198
3b9aacf07744
optimize accumarray with constant ranges
Jaroslav Hajek <highegg@gmail.com>
parents:
9197
diff
changeset
|
7188 if (vals.is_range ()) |
3b9aacf07744
optimize accumarray with constant ranges
Jaroslav Hajek <highegg@gmail.com>
parents:
9197
diff
changeset
|
7189 { |
3b9aacf07744
optimize accumarray with constant ranges
Jaroslav Hajek <highegg@gmail.com>
parents:
9197
diff
changeset
|
7190 Range r = vals.range_value (); |
3b9aacf07744
optimize accumarray with constant ranges
Jaroslav Hajek <highegg@gmail.com>
parents:
9197
diff
changeset
|
7191 if (r.inc () == 0) |
3b9aacf07744
optimize accumarray with constant ranges
Jaroslav Hajek <highegg@gmail.com>
parents:
9197
diff
changeset
|
7192 vals = r.base (); |
3b9aacf07744
optimize accumarray with constant ranges
Jaroslav Hajek <highegg@gmail.com>
parents:
9197
diff
changeset
|
7193 } |
3b9aacf07744
optimize accumarray with constant ranges
Jaroslav Hajek <highegg@gmail.com>
parents:
9197
diff
changeset
|
7194 |
8934
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
7195 if (vals.is_single_type ()) |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
7196 { |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
7197 if (vals.is_complex_type ()) |
19790
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19596
diff
changeset
|
7198 retval = do_accumarray_sum (idx, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
7199 vals.float_complex_array_value (), |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
7200 n); |
8934
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
7201 else |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
7202 retval = do_accumarray_sum (idx, vals.float_array_value (), n); |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
7203 } |
10269
217d36560dfa
small fixes to accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10268
diff
changeset
|
7204 else if (vals.is_numeric_type () || vals.is_bool_type ()) |
8934
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
7205 { |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
7206 if (vals.is_complex_type ()) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
7207 retval = do_accumarray_sum (idx, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
7208 vals.complex_array_value (), |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
7209 n); |
8934
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
7210 else |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
7211 retval = do_accumarray_sum (idx, vals.array_value (), n); |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
7212 } |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
7213 else |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
7214 gripe_wrong_type_arg ("accumarray", vals); |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
7215 } |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
7216 catch (index_exception& e) |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
7217 { |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
7218 error ("__accumarray_sum__: invalid IDX %s. %s", |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
7219 e.idx(), e.explain ()); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
7220 } |
8934
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
7221 } |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
7222 else |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
7223 print_usage (); |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
7224 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
7225 return retval; |
8934
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
7226 } |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
7227 |
9473
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7228 template <class NDT> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
7229 static NDT |
10268
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7230 do_accumarray_minmax (const idx_vector& idx, const NDT& vals, |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7231 octave_idx_type n, bool ismin, |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7232 const typename NDT::element_type& zero_val) |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7233 { |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7234 typedef typename NDT::element_type T; |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7235 if (n < 0) |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7236 n = idx.extent (0); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7237 else if (idx.extent (n) > n) |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7238 error ("accumarray: index out of range"); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7239 |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7240 NDT retval (dim_vector (n, 1), zero_val); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7241 |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7242 // Pick minimizer or maximizer. |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
7243 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
|
7244 ismin ? (&MArray<T>::idx_min) : (&MArray<T>::idx_max); |
10268
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7245 |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7246 octave_idx_type l = idx.length (n); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7247 if (vals.numel () == 1) |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7248 (retval.*op) (idx, NDT (dim_vector (l, 1), vals(0))); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7249 else if (vals.numel () == l) |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7250 (retval.*op) (idx, vals); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7251 else |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7252 error ("accumarray: dimensions mismatch"); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7253 |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7254 return retval; |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7255 } |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7256 |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7257 static octave_value_list |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7258 do_accumarray_minmax_fun (const octave_value_list& args, |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7259 bool ismin) |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7260 { |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7261 octave_value retval; |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7262 int nargin = args.length (); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7263 if (nargin >= 3 && nargin <= 4 && args(0).is_numeric_type ()) |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7264 { |
20749
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20696
diff
changeset
|
7265 try |
10268
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7266 { |
20749
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20696
diff
changeset
|
7267 idx_vector idx = args(0).index_vector (); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20696
diff
changeset
|
7268 octave_idx_type n = -1; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20696
diff
changeset
|
7269 if (nargin == 4) |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20696
diff
changeset
|
7270 n = args(3).idx_type_value (true); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20696
diff
changeset
|
7271 |
18099
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17915
diff
changeset
|
7272 octave_value vals = args(1); |
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17915
diff
changeset
|
7273 octave_value zero = args(2); |
10268
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7274 |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7275 switch (vals.builtin_type ()) |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7276 { |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7277 case btyp_double: |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7278 retval = do_accumarray_minmax (idx, vals.array_value (), n, ismin, |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7279 zero.double_value ()); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7280 break; |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7281 case btyp_float: |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
7282 retval = do_accumarray_minmax (idx, vals.float_array_value (), n, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
7283 ismin, zero.float_value ()); |
10268
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7284 break; |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7285 case btyp_complex: |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
7286 retval = do_accumarray_minmax (idx, vals.complex_array_value (), |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
7287 n, ismin, zero.complex_value ()); |
10268
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7288 break; |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7289 case btyp_float_complex: |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
7290 retval = do_accumarray_minmax (idx, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
7291 vals.float_complex_array_value (), |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
7292 n, ismin, |
10268
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7293 zero.float_complex_value ()); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7294 break; |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7295 #define MAKE_INT_BRANCH(X) \ |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
7296 case btyp_ ## X: \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
7297 retval = do_accumarray_minmax (idx, vals.X ## _array_value (), \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
7298 n, ismin, \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
7299 zero.X ## _scalar_value ()); \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
7300 break; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
7301 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
7302 MAKE_INT_BRANCH (int8); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
7303 MAKE_INT_BRANCH (int16); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
7304 MAKE_INT_BRANCH (int32); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
7305 MAKE_INT_BRANCH (int64); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
7306 MAKE_INT_BRANCH (uint8); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
7307 MAKE_INT_BRANCH (uint16); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
7308 MAKE_INT_BRANCH (uint32); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
7309 MAKE_INT_BRANCH (uint64); |
10268
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7310 #undef MAKE_INT_BRANCH |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7311 case btyp_bool: |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7312 retval = do_accumarray_minmax (idx, vals.array_value (), n, ismin, |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7313 zero.bool_value ()); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7314 break; |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7315 default: |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7316 gripe_wrong_type_arg ("accumarray", vals); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7317 } |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7318 } |
20749
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20696
diff
changeset
|
7319 catch (index_exception& e) |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20696
diff
changeset
|
7320 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20696
diff
changeset
|
7321 error ("do_accumarray_minmax_fun: invalid index %s. %s", |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20696
diff
changeset
|
7322 e.idx (), e.explain ()); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20696
diff
changeset
|
7323 } |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20696
diff
changeset
|
7324 |
10268
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7325 } |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7326 else |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7327 print_usage (); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7328 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
7329 return retval; |
10268
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7330 } |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7331 |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7332 DEFUN (__accumarray_min__, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
7333 "-*- texinfo -*-\n\ |
10268
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7334 @deftypefn {Built-in Function} {} __accumarray_min__ (@var{idx}, @var{vals}, @var{zero}, @var{n})\n\ |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7335 Undocumented internal function.\n\ |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7336 @end deftypefn") |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7337 { |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7338 return do_accumarray_minmax_fun (args, true); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7339 } |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7340 |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7341 DEFUN (__accumarray_max__, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
7342 "-*- texinfo -*-\n\ |
10268
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7343 @deftypefn {Built-in Function} {} __accumarray_max__ (@var{idx}, @var{vals}, @var{zero}, @var{n})\n\ |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7344 Undocumented internal function.\n\ |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7345 @end deftypefn") |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7346 { |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7347 return do_accumarray_minmax_fun (args, false); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7348 } |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7349 |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
7350 template <class NDT> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
7351 static NDT |
10396
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7352 do_accumdim_sum (const idx_vector& idx, const NDT& vals, |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7353 int dim = -1, octave_idx_type n = -1) |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7354 { |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7355 typedef typename NDT::element_type T; |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7356 if (n < 0) |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7357 n = idx.extent (0); |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7358 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
|
7359 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
|
7360 |
18099
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17915
diff
changeset
|
7361 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
|
7362 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
|
7363 |
10396
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7364 if (dim < 0) |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7365 dim = vals.dims ().first_non_singleton (); |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7366 else if (dim >= rdv.length ()) |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7367 rdv.resize (dim+1, 1); |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7368 |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7369 rdv(dim) = n; |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7370 |
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
|
7371 NDT retval (rdv, T ()); |
10396
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7372 |
14113
dac62c415e8b
Do more error checking on accumarray and accumdim input.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14100
diff
changeset
|
7373 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
|
7374 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
|
7375 |
10396
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7376 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
|
7377 |
10396
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7378 return retval; |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7379 } |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7380 |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7381 DEFUN (__accumdim_sum__, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
7382 "-*- texinfo -*-\n\ |
10396
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7383 @deftypefn {Built-in Function} {} __accumdim_sum__ (@var{idx}, @var{vals}, @var{dim}, @var{n})\n\ |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7384 Undocumented internal function.\n\ |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7385 @end deftypefn") |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7386 { |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7387 octave_value retval; |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7388 int nargin = args.length (); |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7389 if (nargin >= 2 && nargin <= 4 && args(0).is_numeric_type ()) |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7390 { |
20749
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20696
diff
changeset
|
7391 try |
10396
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7392 { |
20749
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20696
diff
changeset
|
7393 idx_vector idx = args(0).index_vector (); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20696
diff
changeset
|
7394 int dim = -1; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20696
diff
changeset
|
7395 if (nargin >= 3) |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20696
diff
changeset
|
7396 dim = args(2).int_value () - 1; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20696
diff
changeset
|
7397 |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20696
diff
changeset
|
7398 octave_idx_type n = -1; |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20696
diff
changeset
|
7399 if (nargin == 4) |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20696
diff
changeset
|
7400 n = args(3).idx_type_value (true); |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20696
diff
changeset
|
7401 |
10396
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7402 octave_value vals = args(1); |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7403 |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7404 if (vals.is_single_type ()) |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7405 { |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7406 if (vals.is_complex_type ()) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
7407 retval = do_accumdim_sum (idx, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
7408 vals.float_complex_array_value (), |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
7409 dim, n); |
10396
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7410 else |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
7411 retval = do_accumdim_sum (idx, vals.float_array_value (), |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
7412 dim, n); |
10396
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7413 } |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7414 else if (vals.is_numeric_type () || vals.is_bool_type ()) |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7415 { |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7416 if (vals.is_complex_type ()) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
7417 retval = do_accumdim_sum (idx, vals.complex_array_value (), |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
7418 dim, n); |
10396
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7419 else |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7420 retval = do_accumdim_sum (idx, vals.array_value (), dim, n); |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7421 } |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7422 else |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7423 gripe_wrong_type_arg ("accumdim", vals); |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7424 } |
20749
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20696
diff
changeset
|
7425 catch (index_exception& e) |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20696
diff
changeset
|
7426 { |
dd6345fd8a97
use exceptions for better invalid index error reporting (bug #45957)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20696
diff
changeset
|
7427 error ("__accumdim_sum__: invalid IDX %s. %s", e.idx(), e.explain ()); |
10396
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7428 } |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7429 } |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7430 else |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7431 print_usage (); |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7432 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
7433 return retval; |
10396
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7434 } |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7435 |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
7436 template <class NDT> |
9473
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7437 static NDT |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7438 do_merge (const Array<bool>& mask, |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7439 const NDT& tval, const NDT& fval) |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7440 { |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7441 typedef typename NDT::element_type T; |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7442 dim_vector dv = mask.dims (); |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7443 NDT retval (dv); |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7444 |
18099
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17915
diff
changeset
|
7445 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
|
7446 bool fscl = fval.numel () == 1; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
7447 |
9473
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7448 if ((! tscl && tval.dims () != dv) |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7449 || (! 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
|
7450 error ("merge: MASK, TVAL, and FVAL dimensions must match"); |
9473
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7451 else |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7452 { |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7453 T *rv = retval.fortran_vec (); |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7454 octave_idx_type n = retval.numel (); |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7455 |
18099
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17915
diff
changeset
|
7456 const T *tv = tval.data (); |
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17915
diff
changeset
|
7457 const T *fv = fval.data (); |
9473
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7458 const bool *mv = mask.data (); |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7459 |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7460 if (tscl) |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7461 { |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7462 if (fscl) |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7463 { |
18099
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17915
diff
changeset
|
7464 T ts = tv[0]; |
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17915
diff
changeset
|
7465 T fs = fv[0]; |
9473
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7466 for (octave_idx_type i = 0; i < n; i++) |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7467 rv[i] = mv[i] ? ts : fs; |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7468 } |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7469 else |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7470 { |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7471 T ts = tv[0]; |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7472 for (octave_idx_type i = 0; i < n; i++) |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7473 rv[i] = mv[i] ? ts : fv[i]; |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7474 } |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7475 } |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7476 else |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7477 { |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7478 if (fscl) |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7479 { |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7480 T fs = fv[0]; |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7481 for (octave_idx_type i = 0; i < n; i++) |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7482 rv[i] = mv[i] ? tv[i] : fs; |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7483 } |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7484 else |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7485 { |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7486 for (octave_idx_type i = 0; i < n; i++) |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7487 rv[i] = mv[i] ? tv[i] : fv[i]; |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7488 } |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7489 } |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7490 } |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7491 |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7492 return retval; |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7493 } |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7494 |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7495 #define MAKE_INT_BRANCH(INTX) \ |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7496 else if (tval.is_ ## INTX ## _type () && fval.is_ ## INTX ## _type ()) \ |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7497 { \ |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7498 retval = do_merge (mask, \ |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7499 tval.INTX ## _array_value (), \ |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7500 fval.INTX ## _array_value ()); \ |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7501 } |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7502 |
9505
a321a1c227c8
make ifelse an alias or merge
Jaroslav Hajek <highegg@gmail.com>
parents:
9475
diff
changeset
|
7503 DEFUN (merge, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
7504 "-*- texinfo -*-\n\ |
10840 | 7505 @deftypefn {Built-in Function} {} merge (@var{mask}, @var{tval}, @var{fval})\n\ |
9505
a321a1c227c8
make ifelse an alias or merge
Jaroslav Hajek <highegg@gmail.com>
parents:
9475
diff
changeset
|
7506 @deftypefnx {Built-in Function} {} 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
|
7507 Merge elements of @var{true_val} and @var{false_val}, depending on the\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
7508 value of @var{mask}.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
7509 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
7510 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:
20068
diff
changeset
|
7511 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:
20068
diff
changeset
|
7512 @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:
20068
diff
changeset
|
7513 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:
20068
diff
changeset
|
7514 @var{fval} is returned.\n\ |
9473
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7515 \n\ |
10846
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10840
diff
changeset
|
7516 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
|
7517 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
|
7518 constructed as follows:\n\ |
10840 | 7519 \n\ |
9473
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7520 @example\n\ |
9758
09da0bd91412
Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents:
9736
diff
changeset
|
7521 @group\n\ |
9473
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7522 result(mask) = tval(mask);\n\ |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7523 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
|
7524 @end group\n\ |
9473
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7525 @end example\n\ |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7526 \n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
7527 @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:
20068
diff
changeset
|
7528 converted to logical.\n\ |
15028
397f0d80bd47
Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents:
15024
diff
changeset
|
7529 @seealso{logical, diff}\n\ |
9473
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7530 @end deftypefn") |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7531 { |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7532 int nargin = args.length (); |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7533 octave_value retval; |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7534 |
9856 | 7535 if (nargin == 3 && (args(0).is_bool_type () || args(0).is_numeric_type ())) |
9473
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7536 { |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7537 octave_value mask_val = args(0); |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7538 |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7539 if (mask_val.is_scalar_type ()) |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7540 retval = mask_val.is_true () ? args(1) : args(2); |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7541 else |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7542 { |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7543 boolNDArray mask = mask_val.bool_array_value (); |
18099
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17915
diff
changeset
|
7544 octave_value tval = args(1); |
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17915
diff
changeset
|
7545 octave_value fval = args(2); |
9473
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7546 if (tval.is_double_type () && fval.is_double_type ()) |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7547 { |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7548 if (tval.is_complex_type () || fval.is_complex_type ()) |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7549 retval = do_merge (mask, |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7550 tval.complex_array_value (), |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7551 fval.complex_array_value ()); |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7552 else |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7553 retval = do_merge (mask, |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7554 tval.array_value (), |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7555 fval.array_value ()); |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7556 } |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7557 else if (tval.is_single_type () && fval.is_single_type ()) |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7558 { |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7559 if (tval.is_complex_type () || fval.is_complex_type ()) |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7560 retval = do_merge (mask, |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7561 tval.float_complex_array_value (), |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7562 fval.float_complex_array_value ()); |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7563 else |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7564 retval = do_merge (mask, |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7565 tval.float_array_value (), |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7566 fval.float_array_value ()); |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7567 } |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7568 else if (tval.is_string () && fval.is_string ()) |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7569 { |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7570 bool sq_string = tval.is_sq_string () || fval.is_sq_string (); |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7571 retval = octave_value (do_merge (mask, |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7572 tval.char_array_value (), |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7573 fval.char_array_value ()), |
9689
34d6f005db4b
eliminate is_string argument from octave_value character array constructors
John W. Eaton <jwe@octave.org>
parents:
9685
diff
changeset
|
7574 sq_string ? '\'' : '"'); |
9473
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7575 } |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7576 else if (tval.is_cell () && fval.is_cell ()) |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7577 { |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7578 retval = do_merge (mask, |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7579 tval.cell_value (), |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7580 fval.cell_value ()); |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7581 } |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7582 |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7583 MAKE_INT_BRANCH (int8) |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7584 MAKE_INT_BRANCH (int16) |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7585 MAKE_INT_BRANCH (int32) |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7586 MAKE_INT_BRANCH (int64) |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7587 MAKE_INT_BRANCH (uint8) |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7588 MAKE_INT_BRANCH (uint16) |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7589 MAKE_INT_BRANCH (uint32) |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7590 MAKE_INT_BRANCH (uint64) |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7591 |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7592 else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
7593 error ("merge: cannot merge %s with %s with array mask", |
9473
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7594 tval.class_name ().c_str (), |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7595 fval.class_name ().c_str ()); |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7596 } |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7597 } |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7598 else |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7599 print_usage (); |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7600 |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7601 return retval; |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7602 } |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7603 |
9505
a321a1c227c8
make ifelse an alias or merge
Jaroslav Hajek <highegg@gmail.com>
parents:
9475
diff
changeset
|
7604 DEFALIAS (ifelse, merge); |
a321a1c227c8
make ifelse an alias or merge
Jaroslav Hajek <highegg@gmail.com>
parents:
9475
diff
changeset
|
7605 |
9473
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
7606 #undef MAKE_INT_BRANCH |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
7607 |
9513
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7608 template <class SparseT> |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7609 static SparseT |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7610 do_sparse_diff (const SparseT& array, octave_idx_type order, |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7611 int dim) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7612 { |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7613 SparseT retval = array; |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7614 if (dim == 1) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7615 { |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7616 octave_idx_type k = retval.columns (); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7617 while (order > 0 && k > 0) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7618 { |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7619 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
|
7620 retval = SparseT (retval.index (col1, sl1)) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
7621 - SparseT (retval.index (col2, sl2)); |
9513
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7622 assert (retval.columns () == k-1); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7623 order--; |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7624 k--; |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7625 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7626 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7627 else |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7628 { |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7629 octave_idx_type k = retval.rows (); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7630 while (order > 0 && k > 0) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7631 { |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7632 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
|
7633 retval = SparseT (retval.index (sl1, col1)) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
7634 - SparseT (retval.index (sl2, col2)); |
9513
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7635 assert (retval.rows () == k-1); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7636 order--; |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7637 k--; |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7638 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7639 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7640 |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7641 return retval; |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7642 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7643 |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7644 static octave_value |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7645 do_diff (const octave_value& array, octave_idx_type order, |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7646 int dim = -1) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7647 { |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7648 octave_value retval; |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7649 |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7650 const dim_vector& dv = array.dims (); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7651 if (dim == -1) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7652 { |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7653 dim = array.dims ().first_non_singleton (); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7654 |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7655 // Bother Matlab. This behavior is really wicked. |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7656 if (dv(dim) <= order) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7657 { |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7658 if (dv(dim) == 1) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7659 retval = array.resize (dim_vector (0, 0)); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7660 else |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7661 { |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7662 retval = array; |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7663 while (order > 0) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7664 { |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7665 if (dim == dv.length ()) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7666 { |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7667 retval = do_diff (array, order, dim - 1); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7668 order = 0; |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7669 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7670 else if (dv(dim) == 1) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7671 dim++; |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7672 else |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7673 { |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7674 retval = do_diff (array, dv(dim) - 1, dim); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7675 order -= dv(dim) - 1; |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7676 dim++; |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7677 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7678 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7679 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7680 |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7681 return retval; |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7682 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7683 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7684 |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7685 if (array.is_integer_type ()) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7686 { |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7687 if (array.is_int8_type ()) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7688 retval = array.int8_array_value ().diff (order, dim); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7689 else if (array.is_int16_type ()) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7690 retval = array.int16_array_value ().diff (order, dim); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7691 else if (array.is_int32_type ()) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7692 retval = array.int32_array_value ().diff (order, dim); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7693 else if (array.is_int64_type ()) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7694 retval = array.int64_array_value ().diff (order, dim); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7695 else if (array.is_uint8_type ()) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7696 retval = array.uint8_array_value ().diff (order, dim); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7697 else if (array.is_uint16_type ()) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7698 retval = array.uint16_array_value ().diff (order, dim); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7699 else if (array.is_uint32_type ()) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7700 retval = array.uint32_array_value ().diff (order, dim); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7701 else if (array.is_uint64_type ()) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7702 retval = array.uint64_array_value ().diff (order, dim); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7703 else |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7704 panic_impossible (); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7705 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7706 else if (array.is_sparse_type ()) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7707 { |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7708 if (array.is_complex_type ()) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
7709 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
|
7710 order, dim); |
9513
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7711 else |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7712 retval = do_sparse_diff (array.sparse_matrix_value (), order, dim); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7713 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7714 else if (array.is_single_type ()) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7715 { |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7716 if (array.is_complex_type ()) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7717 retval = array.float_complex_array_value ().diff (order, dim); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7718 else |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7719 retval = array.float_array_value ().diff (order, dim); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7720 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7721 else |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7722 { |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7723 if (array.is_complex_type ()) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7724 retval = array.complex_array_value ().diff (order, dim); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7725 else |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7726 retval = array.array_value ().diff (order, dim); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7727 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7728 |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7729 return retval; |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7730 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7731 |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7732 DEFUN (diff, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
7733 "-*- texinfo -*-\n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
7734 @deftypefn {Built-in Function} {} diff (@var{x})\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
7735 @deftypefnx {Built-in Function} {} diff (@var{x}, @var{k})\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
7736 @deftypefnx {Built-in Function} {} diff (@var{x}, @var{k}, @var{dim})\n\ |
20780
c6059134f5d3
data.cc: Add @w{} around @code segments in docstrings to prevent line breaks.
Rik <rik@octave.org>
parents:
20608
diff
changeset
|
7737 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
|
7738 vector of first differences\n\ |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7739 @tex\n\ |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7740 $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
|
7741 @end tex\n\ |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7742 @ifnottex\n\ |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7743 @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
|
7744 @end ifnottex\n\ |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7745 \n\ |
20780
c6059134f5d3
data.cc: Add @w{} around @code segments in docstrings to prevent line breaks.
Rik <rik@octave.org>
parents:
20608
diff
changeset
|
7746 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
|
7747 differences along the first non-singleton dimension.\n\ |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7748 \n\ |
20780
c6059134f5d3
data.cc: Add @w{} around @code segments in docstrings to prevent line breaks.
Rik <rik@octave.org>
parents:
20608
diff
changeset
|
7749 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:
20608
diff
changeset
|
7750 @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:
20608
diff
changeset
|
7751 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:
20608
diff
changeset
|
7752 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
|
7753 @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
|
7754 non-singleton dimension.\n\ |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7755 \n\ |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7756 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
|
7757 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
|
7758 @var{k}-th order differences are calculated along this dimension.\n\ |
20780
c6059134f5d3
data.cc: Add @w{} around @code segments in docstrings to prevent line breaks.
Rik <rik@octave.org>
parents:
20608
diff
changeset
|
7759 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
|
7760 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
|
7761 @seealso{sort, merge}\n\ |
9513
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7762 @end deftypefn") |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7763 { |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7764 int nargin = args.length (); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7765 octave_value retval; |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7766 |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7767 if (nargin < 1 || nargin > 3) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7768 print_usage (); |
10880 | 7769 else if (! (args(0).is_numeric_type () || args(0).is_bool_type ())) |
7770 error ("diff: X must be numeric or logical"); | |
9513
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7771 |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
7772 int dim = -1; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
7773 octave_idx_type order = 1; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
7774 if (nargin > 1) |
9513
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7775 { |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
7776 if (args(1).is_scalar_type ()) |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
7777 order = args(1).idx_type_value (true, false); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
7778 else if (! args(1).is_zero_by_zero ()) |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
7779 error ("order K must be a scalar or []"); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
7780 if (order < 0) |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
7781 error ("order K must be non-negative"); |
9513
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7782 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7783 |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
7784 if (nargin > 2) |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
7785 { |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
7786 dim = args(2).int_value (true, false); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
7787 if (dim < 1 || dim > args(0).ndims ()) |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
7788 error ("DIM must be a valid dimension"); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
7789 else |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
7790 dim -= 1; |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
7791 } |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
7792 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
7793 retval = do_diff (args(0), order, dim); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
7794 |
9513
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7795 return retval; |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7796 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7797 |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7798 /* |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7799 %!assert (diff ([1, 2, 3, 4]), [1, 1, 1]) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7800 %!assert (diff ([1, 3, 7, 19], 2), [2, 8]) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7801 %!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
|
7802 %!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
|
7803 %!assert (isempty (diff (1))) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
7804 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
7805 %!error diff () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
7806 %!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
|
7807 %!error diff ("foo") |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
7808 %!error diff ([1, 2; 3, 4], -1) |
9513
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7809 */ |
10799
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7810 |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7811 template <class T> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
7812 static Array<T> |
10799
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7813 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
|
7814 { |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7815 Array<T> retval; |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7816 |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7817 assert (rep.ndims () == 2 && rep.rows () == 2); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7818 |
18099
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17915
diff
changeset
|
7819 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
|
7820 octave_idx_type l = 0; |
10799
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7821 for (octave_idx_type i = 0; i < n; i++) |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7822 { |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7823 octave_idx_type k = rep(1, i); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7824 if (k < 0) |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7825 { |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11591
diff
changeset
|
7826 error ("repelems: second row must contain non-negative numbers"); |
10799
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7827 return retval; |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7828 } |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7829 |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7830 l += k; |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7831 } |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7832 |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7833 retval.clear (1, l); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7834 T *dest = retval.fortran_vec (); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7835 l = 0; |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7836 for (octave_idx_type i = 0; i < n; i++) |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7837 { |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7838 octave_idx_type k = rep(1, i); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7839 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
|
7840 dest += k; |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7841 } |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7842 |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7843 return retval; |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7844 } |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7845 |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7846 DEFUN (repelems, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
7847 "-*- texinfo -*-\n\ |
10799
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7848 @deftypefn {Built-in Function} {} repelems (@var{x}, @var{r})\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
7849 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:
20068
diff
changeset
|
7850 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
7851 @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:
20068
diff
changeset
|
7852 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:
20068
diff
changeset
|
7853 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:
20068
diff
changeset
|
7854 @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:
20068
diff
changeset
|
7855 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:
20068
diff
changeset
|
7856 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
|
7857 \n\ |
a40e32927b3a
Improve documentation for new repelems function.
Rik <octave@nomad.inbox5.com>
parents:
10799
diff
changeset
|
7858 Conceptually the result is calculated as follows:\n\ |
10799
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7859 \n\ |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7860 @example\n\ |
10840 | 7861 @group\n\ |
10801
a40e32927b3a
Improve documentation for new repelems function.
Rik <octave@nomad.inbox5.com>
parents:
10799
diff
changeset
|
7862 y = [];\n\ |
a40e32927b3a
Improve documentation for new repelems function.
Rik <octave@nomad.inbox5.com>
parents:
10799
diff
changeset
|
7863 for i = 1:columns (@var{r})\n\ |
a40e32927b3a
Improve documentation for new repelems function.
Rik <octave@nomad.inbox5.com>
parents:
10799
diff
changeset
|
7864 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
|
7865 endfor\n\ |
10840 | 7866 @end group\n\ |
10799
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7867 @end example\n\ |
15028
397f0d80bd47
Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents:
15024
diff
changeset
|
7868 @seealso{repmat, cat}\n\ |
10799
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7869 @end deftypefn") |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7870 { |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7871 octave_value retval; |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7872 |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7873 if (args.length () == 2) |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7874 { |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7875 octave_value x = args(0); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7876 |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7877 const Matrix rm = args(1).matrix_value (); |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
7878 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
7879 if (rm.rows () != 2 || rm.ndims () != 2) |
10799
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7880 { |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11591
diff
changeset
|
7881 error ("repelems: R must be a matrix with two rows"); |
10799
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7882 return retval; |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7883 } |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7884 else |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7885 { |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7886 NoAlias< Array<octave_idx_type> > r (rm.dims ()); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7887 |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7888 for (octave_idx_type i = 0; i < rm.numel (); i++) |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7889 { |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7890 octave_idx_type rx = rm(i); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7891 if (static_cast<double> (rx) != rm(i)) |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7892 { |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11591
diff
changeset
|
7893 error ("repelems: R must be a matrix of integers"); |
10799
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7894 return retval; |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7895 } |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7896 |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7897 r(i) = rx; |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7898 } |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7899 |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7900 switch (x.builtin_type ()) |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7901 { |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7902 #define BTYP_BRANCH(X, EX) \ |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7903 case btyp_ ## X: \ |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7904 retval = do_repelems (x.EX ## _value (), r); \ |
18891
5baada25d5a2
Rewrite docstring of sum() to match prod().
Rik <rik@octave.org>
parents:
18890
diff
changeset
|
7905 break; |
10799
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7906 |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7907 BTYP_BRANCH (double, array); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7908 BTYP_BRANCH (float, float_array); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7909 BTYP_BRANCH (complex, complex_array); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7910 BTYP_BRANCH (float_complex, float_complex_array); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7911 BTYP_BRANCH (bool, bool_array); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7912 BTYP_BRANCH (char, char_array); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7913 |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7914 BTYP_BRANCH (int8, int8_array); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7915 BTYP_BRANCH (int16, int16_array); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7916 BTYP_BRANCH (int32, int32_array); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7917 BTYP_BRANCH (int64, int64_array); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7918 BTYP_BRANCH (uint8, uint8_array); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7919 BTYP_BRANCH (uint16, uint16_array); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7920 BTYP_BRANCH (uint32, uint32_array); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7921 BTYP_BRANCH (uint64, uint64_array); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7922 |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7923 BTYP_BRANCH (cell, cell); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7924 //BTYP_BRANCH (struct, map);//FIXME |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7925 #undef BTYP_BRANCH |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7926 |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7927 default: |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7928 gripe_wrong_type_arg ("repelems", x); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7929 } |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7930 } |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7931 } |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7932 else |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7933 print_usage (); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7934 |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7935 return retval; |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7936 } |
15050
abc858bc5165
Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15038
diff
changeset
|
7937 |
15252
fa0118cb67d9
move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents:
15213
diff
changeset
|
7938 DEFUN (base64_encode, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
7939 "-*- texinfo -*-\n\ |
15052
70a1b50bcb45
maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents:
15050
diff
changeset
|
7940 @deftypefn {Built-in Function} {@var{s} =} base64_encode (@var{x})\n\ |
70a1b50bcb45
maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents:
15050
diff
changeset
|
7941 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
|
7942 @var{s}.\n\ |
70a1b50bcb45
maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents:
15050
diff
changeset
|
7943 \n\ |
15050
abc858bc5165
Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15038
diff
changeset
|
7944 @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
|
7945 @end deftypefn") |
abc858bc5165
Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15038
diff
changeset
|
7946 { |
abc858bc5165
Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15038
diff
changeset
|
7947 octave_value_list retval; |
abc858bc5165
Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15038
diff
changeset
|
7948 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
|
7949 |
15050
abc858bc5165
Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15038
diff
changeset
|
7950 if (nargin != 1) |
abc858bc5165
Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15038
diff
changeset
|
7951 print_usage (); |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
7952 else |
15050
abc858bc5165
Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15038
diff
changeset
|
7953 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
7954 if (! args(0).is_numeric_type ()) |
15111
5dd599df36de
generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15094
diff
changeset
|
7955 error ("base64_encode: encoding is supported only for numeric arrays"); |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
7956 else if (args(0).is_complex_type () |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
7957 || args(0).is_sparse_type ()) |
15111
5dd599df36de
generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15094
diff
changeset
|
7958 error ("base64_encode: encoding complex or sparse data is not supported"); |
5dd599df36de
generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15094
diff
changeset
|
7959 else if (args(0).is_integer_type ()) |
15052
70a1b50bcb45
maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents:
15050
diff
changeset
|
7960 { |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
7961 #define MAKE_INT_BRANCH(X) \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
7962 if (args(0).is_ ## X ## _type ()) \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
7963 { \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
7964 const X##NDArray in = args(0). X## _array_value (); \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
7965 size_t inlen = \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
7966 in.numel () * sizeof (X## _t) / sizeof (char); \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
7967 const char* inc = \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
7968 reinterpret_cast<const char*> (in.data ()); \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
7969 char* out; \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
7970 if (octave_base64_encode (inc, inlen, &out)) \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
7971 { \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
7972 retval(0) = octave_value (out); \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
7973 ::free (out); \ |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
7974 } \ |
15111
5dd599df36de
generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15094
diff
changeset
|
7975 } |
17621
d41c8f96ed06
avoid memory leaks in base_64_encode and base_64_decode (bug #40228)
John W. Eaton <jwe@octave.org>
parents:
17281
diff
changeset
|
7976 |
15111
5dd599df36de
generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15094
diff
changeset
|
7977 MAKE_INT_BRANCH(int8) |
5dd599df36de
generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15094
diff
changeset
|
7978 else MAKE_INT_BRANCH(int16) |
5dd599df36de
generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15094
diff
changeset
|
7979 else MAKE_INT_BRANCH(int32) |
5dd599df36de
generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15094
diff
changeset
|
7980 else MAKE_INT_BRANCH(int64) |
5dd599df36de
generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15094
diff
changeset
|
7981 else MAKE_INT_BRANCH(uint8) |
5dd599df36de
generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15094
diff
changeset
|
7982 else MAKE_INT_BRANCH(uint16) |
5dd599df36de
generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15094
diff
changeset
|
7983 else MAKE_INT_BRANCH(uint32) |
5dd599df36de
generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15094
diff
changeset
|
7984 else MAKE_INT_BRANCH(uint64) |
5dd599df36de
generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15094
diff
changeset
|
7985 #undef MAKE_INT_BRANCH |
5dd599df36de
generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15094
diff
changeset
|
7986 |
5dd599df36de
generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15094
diff
changeset
|
7987 else |
5dd599df36de
generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15094
diff
changeset
|
7988 panic_impossible (); |
5dd599df36de
generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15094
diff
changeset
|
7989 } |
5dd599df36de
generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15094
diff
changeset
|
7990 else if (args(0).is_single_type ()) |
5dd599df36de
generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15094
diff
changeset
|
7991 { |
5dd599df36de
generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15094
diff
changeset
|
7992 const Array<float> in = args(0).float_array_value (); |
5dd599df36de
generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15094
diff
changeset
|
7993 size_t inlen; |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
7994 inlen = in.numel () * sizeof (float) / sizeof (char); |
15111
5dd599df36de
generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15094
diff
changeset
|
7995 const char* inc; |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
7996 inc = reinterpret_cast<const char*> (in.data ()); |
15050
abc858bc5165
Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15038
diff
changeset
|
7997 char* out; |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
7998 if (octave_base64_encode (inc, inlen, &out)) |
17621
d41c8f96ed06
avoid memory leaks in base_64_encode and base_64_decode (bug #40228)
John W. Eaton <jwe@octave.org>
parents:
17281
diff
changeset
|
7999 { |
d41c8f96ed06
avoid memory leaks in base_64_encode and base_64_decode (bug #40228)
John W. Eaton <jwe@octave.org>
parents:
17281
diff
changeset
|
8000 retval(0) = octave_value (out); |
d41c8f96ed06
avoid memory leaks in base_64_encode and base_64_decode (bug #40228)
John W. Eaton <jwe@octave.org>
parents:
17281
diff
changeset
|
8001 ::free (out); |
d41c8f96ed06
avoid memory leaks in base_64_encode and base_64_decode (bug #40228)
John W. Eaton <jwe@octave.org>
parents:
17281
diff
changeset
|
8002 } |
15050
abc858bc5165
Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15038
diff
changeset
|
8003 } |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
8004 else |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
8005 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
8006 const Array<double> in = args(0).array_value (); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
8007 size_t inlen; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
8008 inlen = in.numel () * sizeof (double) / sizeof (char); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
8009 const char* inc; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
8010 inc = reinterpret_cast<const char*> (in.data ()); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
8011 char* out; |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
8012 if (octave_base64_encode (inc, inlen, &out)) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
8013 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
8014 retval(0) = octave_value (out); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
8015 ::free (out); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
8016 } |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
8017 } |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
8018 } |
15052
70a1b50bcb45
maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents:
15050
diff
changeset
|
8019 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
|
8020 } |
abc858bc5165
Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15038
diff
changeset
|
8021 |
abc858bc5165
Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15038
diff
changeset
|
8022 /* |
15111
5dd599df36de
generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15094
diff
changeset
|
8023 %!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
|
8024 %!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
|
8025 %!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
|
8026 %!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
|
8027 %!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
|
8028 %!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
|
8029 |
70a1b50bcb45
maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents:
15050
diff
changeset
|
8030 %!error base64_encode () |
70a1b50bcb45
maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents:
15050
diff
changeset
|
8031 %!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
|
8032 %!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
|
8033 %!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
|
8034 %!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
|
8035 */ |
abc858bc5165
Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15038
diff
changeset
|
8036 |
15252
fa0118cb67d9
move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents:
15213
diff
changeset
|
8037 DEFUN (base64_decode, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
8038 "-*- texinfo -*-\n\ |
15052
70a1b50bcb45
maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents:
15050
diff
changeset
|
8039 @deftypefn {Built-in Function} {@var{x} =} base64_decode (@var{s})\n\ |
70a1b50bcb45
maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents:
15050
diff
changeset
|
8040 @deftypefnx {Built-in Function} {@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
|
8041 Decode the double matrix or array @var{x} from the base64 encoded string\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
8042 @var{s}.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
8043 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20068
diff
changeset
|
8044 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:
20068
diff
changeset
|
8045 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
|
8046 @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
|
8047 @end deftypefn") |
abc858bc5165
Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15038
diff
changeset
|
8048 { |
15252
fa0118cb67d9
move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents:
15213
diff
changeset
|
8049 octave_value retval; |
15050
abc858bc5165
Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15038
diff
changeset
|
8050 |
abc858bc5165
Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15038
diff
changeset
|
8051 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
|
8052 |
15050
abc858bc5165
Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15038
diff
changeset
|
8053 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
|
8054 print_usage (); |
15052
70a1b50bcb45
maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents:
15050
diff
changeset
|
8055 else |
15050
abc858bc5165
Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15038
diff
changeset
|
8056 { |
15252
fa0118cb67d9
move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents:
15213
diff
changeset
|
8057 dim_vector dims; |
15052
70a1b50bcb45
maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents:
15050
diff
changeset
|
8058 |
15050
abc858bc5165
Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15038
diff
changeset
|
8059 if (nargin > 1) |
abc858bc5165
Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15038
diff
changeset
|
8060 { |
15252
fa0118cb67d9
move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents:
15213
diff
changeset
|
8061 const Array<octave_idx_type> size = |
15111
5dd599df36de
generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15094
diff
changeset
|
8062 args(1).octave_idx_type_vector_value (); |
15252
fa0118cb67d9
move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents:
15213
diff
changeset
|
8063 |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
8064 dims = dim_vector::alloc (size.numel ()); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
8065 for (octave_idx_type i = 0; i < size.numel (); i++) |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
8066 dims(i) = size(i); |
15052
70a1b50bcb45
maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents:
15050
diff
changeset
|
8067 } |
15050
abc858bc5165
Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15038
diff
changeset
|
8068 |
15252
fa0118cb67d9
move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents:
15213
diff
changeset
|
8069 const std::string str = args(0).string_value (); |
15050
abc858bc5165
Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15038
diff
changeset
|
8070 |
20769
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
8071 Array<double> res = octave_base64_decode (str); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
8072 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
8073 if (nargin > 1) |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
8074 res = res.reshape (dims); |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
8075 |
a05a0432dff4
eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20749
diff
changeset
|
8076 retval = res; |
15050
abc858bc5165
Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15038
diff
changeset
|
8077 } |
15052
70a1b50bcb45
maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents:
15050
diff
changeset
|
8078 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
8079 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
|
8080 } |
abc858bc5165
Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15038
diff
changeset
|
8081 |
abc858bc5165
Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15038
diff
changeset
|
8082 /* |
15052
70a1b50bcb45
maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents:
15050
diff
changeset
|
8083 %!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
|
8084 %! |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
8085 %!test |
15052
70a1b50bcb45
maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents:
15050
diff
changeset
|
8086 %! in = randn (10); |
70a1b50bcb45
maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents:
15050
diff
changeset
|
8087 %! 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
|
8088 %! 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
|
8089 %! assert (outv, in(:).'); |
70a1b50bcb45
maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents:
15050
diff
changeset
|
8090 %! assert (outm, in); |
70a1b50bcb45
maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents:
15050
diff
changeset
|
8091 |
70a1b50bcb45
maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents:
15050
diff
changeset
|
8092 %!error base64_decode () |
70a1b50bcb45
maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents:
15050
diff
changeset
|
8093 %!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
|
8094 %!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
|
8095 %!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
|
8096 %!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
|
8097 %!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
|
8098 */ |