Mercurial > octave-antonio
annotate libinterp/corefcn/data.cc @ 17115:00985134145e
norm: fix argument handling to match the docstring (bug #34778)
* data.cc (Fnorm): Handle the 3-argument case properly when two string
options are given or when argument 2 is empty. Add test cases.
author | Mike Miller <mtmiller@ieee.org> |
---|---|
date | Tue, 30 Jul 2013 21:29:57 -0400 |
parents | 68fc671a9339 |
children | ea5830dc6b19 |
rev | line source |
---|---|
523 | 1 /* |
2 | |
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
14113
diff
changeset
|
3 Copyright (C) 1994-2012 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, , |
3369 | 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\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
115 are nonzero.\n\ |
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\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
119 corresponding column of the matrix are nonzero. For example:\n\ |
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\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
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, , |
3369 | 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\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
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\ |
10840 | 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, , |
3428 | 214 "-*- texinfo -*-\n\ |
215 @deftypefn {Mapping Function} {} atan2 (@var{y}, @var{x})\n\ | |
216 Compute atan (@var{y} / @var{x}) for corresponding elements of @var{y}\n\ | |
9155
ad20b967e1c9
Update section 17.3 (Trigonometry) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9142
diff
changeset
|
217 and @var{x}. Signal an error if @var{y} and @var{x} do not match in size\n\ |
ad20b967e1c9
Update section 17.3 (Trigonometry) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9142
diff
changeset
|
218 and orientation.\n\ |
15028
397f0d80bd47
Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents:
15024
diff
changeset
|
219 @seealso{tan, tand, tanh, atanh}\n\ |
3439 | 220 @end deftypefn") |
649 | 221 { |
4233 | 222 octave_value retval; |
649 | 223 |
712 | 224 int nargin = args.length (); |
225 | |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
226 if (nargin == 2) |
649 | 227 { |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
228 if (! args(0).is_numeric_type ()) |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
229 gripe_wrong_type_arg ("atan2", args(0)); |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
230 else if (! args(1).is_numeric_type ()) |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
231 gripe_wrong_type_arg ("atan2", args(1)); |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
232 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
|
233 error ("atan2: not defined for complex numbers"); |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
234 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
|
235 { |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
236 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
|
237 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
|
238 else |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
239 { |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
240 FloatNDArray a0 = args(0).float_array_value (); |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
241 FloatNDArray a1 = args(1).float_array_value (); |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
242 retval = binmap<float> (a0, a1, ::atan2f, "atan2"); |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
243 } |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
244 } |
7494
bd2bd04e68ca
Treat integer types for mod/rem correctly
David Bateman <dbateman@free.fr>
parents:
7433
diff
changeset
|
245 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
246 { |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
247 bool a0_scalar = args(0).is_scalar_type (); |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
248 bool a1_scalar = args(1).is_scalar_type (); |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
249 if (a0_scalar && a1_scalar) |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
250 retval = atan2 (args(0).scalar_value (), args(1).scalar_value ()); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
251 else if ((a0_scalar || args(0).is_sparse_type ()) |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
252 && (a1_scalar || args(1).is_sparse_type ())) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
253 { |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
254 SparseMatrix m0 = args(0).sparse_matrix_value (); |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
255 SparseMatrix m1 = args(1).sparse_matrix_value (); |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
256 retval = binmap<double> (m0, m1, ::atan2, "atan2"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
257 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
258 else |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
259 { |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
260 NDArray a0 = args(0).array_value (); |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
261 NDArray a1 = args(1).array_value (); |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
262 retval = binmap<double> (a0, a1, ::atan2, "atan2"); |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
263 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
264 } |
649 | 265 } |
712 | 266 else |
5823 | 267 print_usage (); |
649 | 268 |
269 return retval; | |
270 } | |
271 | |
7506
798b0a00e80c
atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents:
7505
diff
changeset
|
272 /* |
7741 | 273 %!assert (size (atan2 (zeros (0, 2), zeros (0, 2))), [0, 2]) |
274 %!assert (size (atan2 (rand (2, 3, 4), zeros (2, 3, 4))), [2, 3, 4]) | |
275 %!assert (size (atan2 (rand (2, 3, 4), 1)), [2, 3, 4]) | |
276 %!assert (size (atan2 (1, rand (2, 3, 4))), [2, 3, 4]) | |
277 %!assert (size (atan2 (1, 2)), [1, 1]) | |
7815
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
278 |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
279 %!test |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
280 %! rt2 = sqrt (2); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
281 %! rt3 = sqrt (3); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
282 %! v = [0, pi/6, pi/4, pi/3, -pi/3, -pi/4, -pi/6, 0]; |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
283 %! y = [0, rt3, 1, rt3, -rt3, -1, -rt3, 0]; |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
284 %! x = [1, 3, 1, 1, 1, 1, 3, 1]; |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
285 %! assert (atan2 (y, x), v, sqrt (eps)); |
7815
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
286 |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
287 %!test |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
288 %! rt2 = sqrt (2); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
289 %! rt3 = sqrt (3); |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
290 %! v = single ([0, pi/6, pi/4, pi/3, -pi/3, -pi/4, -pi/6, 0]); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
291 %! y = single ([0, rt3, 1, rt3, -rt3, -1, -rt3, 0]); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
292 %! x = single ([1, 3, 1, 1, 1, 1, 3, 1]); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
293 %! assert (atan2 (y, x), v, sqrt (eps ("single"))); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
294 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
295 %!error atan2 () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
296 %!error atan2 (1, 2, 3) |
7506
798b0a00e80c
atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents:
7505
diff
changeset
|
297 */ |
798b0a00e80c
atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents:
7505
diff
changeset
|
298 |
7815
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
299 |
10538
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
300 static octave_value |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
301 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
|
302 { |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
303 octave_value retval; |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
304 |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
305 octave_value arg0 = x, arg1 = y; |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
306 if (! arg0.is_numeric_type ()) |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
307 gripe_wrong_type_arg ("hypot", arg0); |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
308 else if (! arg1.is_numeric_type ()) |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
309 gripe_wrong_type_arg ("hypot", arg1); |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
310 else |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
311 { |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
312 if (arg0.is_complex_type ()) |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
313 arg0 = arg0.abs (); |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
314 if (arg1.is_complex_type ()) |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
315 arg1 = arg1.abs (); |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
316 |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
317 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
|
318 { |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
319 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
|
320 retval = hypotf (arg0.float_value (), arg1.float_value ()); |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
321 else |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
322 { |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
323 FloatNDArray a0 = arg0.float_array_value (); |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
324 FloatNDArray a1 = arg1.float_array_value (); |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
325 retval = binmap<float> (a0, a1, ::hypotf, "hypot"); |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
326 } |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
327 } |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
328 else |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
329 { |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
330 bool a0_scalar = arg0.is_scalar_type (); |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
331 bool a1_scalar = arg1.is_scalar_type (); |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
332 if (a0_scalar && a1_scalar) |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
333 retval = hypot (arg0.scalar_value (), arg1.scalar_value ()); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
334 else if ((a0_scalar || arg0.is_sparse_type ()) |
10538
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
335 && (a1_scalar || arg1.is_sparse_type ())) |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
336 { |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
337 SparseMatrix m0 = arg0.sparse_matrix_value (); |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
338 SparseMatrix m1 = arg1.sparse_matrix_value (); |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
339 retval = binmap<double> (m0, m1, ::hypot, "hypot"); |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
340 } |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
341 else |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
342 { |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
343 NDArray a0 = arg0.array_value (); |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
344 NDArray a1 = arg1.array_value (); |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
345 retval = binmap<double> (a0, a1, ::hypot, "hypot"); |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
346 } |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
347 } |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
348 } |
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 return retval; |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
351 } |
7815
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
352 |
7631 | 353 DEFUN (hypot, args, , |
354 "-*- texinfo -*-\n\ | |
10840 | 355 @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
|
356 @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
|
357 Compute the element-by-element square root of the sum of the squares of\n\ |
8c71a86c4bf4
Update section 17.5 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9163
diff
changeset
|
358 @var{x} and @var{y}. This is equivalent to\n\ |
8c71a86c4bf4
Update section 17.5 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9163
diff
changeset
|
359 @code{sqrt (@var{x}.^2 + @var{y}.^2)}, but calculated in a manner that\n\ |
8c71a86c4bf4
Update section 17.5 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9163
diff
changeset
|
360 avoids overflows for large values of @var{x} or @var{y}.\n\ |
10538
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
361 @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
|
362 the arguments are accumulated from left to right:\n\ |
10840 | 363 \n\ |
10538
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
364 @example\n\ |
10711
fbd7843974fa
Periodic grammar check of documentation files to ensure common format.
Rik <octave@nomad.inbox5.com>
parents:
10707
diff
changeset
|
365 @group\n\ |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
366 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
|
367 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
|
368 @end group\n\ |
10538
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
369 @end example\n\ |
7631 | 370 @end deftypefn") |
371 { | |
372 octave_value retval; | |
373 | |
374 int nargin = args.length (); | |
375 | |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
376 if (nargin == 2) |
7631 | 377 { |
10538
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
378 retval = do_hypot (args(0), args(1)); |
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 else if (nargin >= 3) |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
381 { |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
382 retval = args(0); |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
383 for (int i = 1; i < nargin && ! error_state; i++) |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
384 retval = do_hypot (retval, args(i)); |
7631 | 385 } |
386 else | |
387 print_usage (); | |
388 | |
389 return retval; | |
390 } | |
391 | |
392 /* | |
7741 | 393 %!assert (size (hypot (zeros (0, 2), zeros (0, 2))), [0, 2]) |
394 %!assert (size (hypot (rand (2, 3, 4), zeros (2, 3, 4))), [2, 3, 4]) | |
395 %!assert (size (hypot (rand (2, 3, 4), 1)), [2, 3, 4]) | |
396 %!assert (size (hypot (1, rand (2, 3, 4))), [2, 3, 4]) | |
397 %!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
|
398 %!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
|
399 %!assert (hypot (single (1:10), single (1:10)), single (sqrt (2) * [1:10])) |
7631 | 400 */ |
401 | |
9813
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
402 template<typename T, typename ET> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
403 void |
9813
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
404 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
|
405 { |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
406 f = Array<T>(x.dims ()); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
407 e = Array<ET>(x.dims ()); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
408 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
|
409 { |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
410 int exp; |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
411 f.xelem (i) = xlog2 (x(i), exp); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
412 e.xelem (i) = exp; |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
413 } |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
414 } |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
415 |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
416 DEFUN (log2, args, nargout, |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
417 "-*- texinfo -*-\n\ |
10840 | 418 @deftypefn {Mapping Function} {} log2 (@var{x})\n\ |
9813
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
419 @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
|
420 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
|
421 \n\ |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
422 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
|
423 binary mantissa and exponent so that\n\ |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
424 @tex\n\ |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
425 ${1 \\over 2} \\le \\left| f \\right| < 1$\n\ |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
426 @end tex\n\ |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
427 @ifnottex\n\ |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
428 @code{1/2 <= abs(f) < 1}\n\ |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
429 @end ifnottex\n\ |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
430 and @var{e} is an integer. If\n\ |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
431 @tex\n\ |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
432 $x = 0$, $f = e = 0$.\n\ |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
433 @end tex\n\ |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
434 @ifnottex\n\ |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
435 @code{x = 0}, @code{f = e = 0}.\n\ |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
436 @end ifnottex\n\ |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
437 @seealso{pow2, log, log10, exp}\n\ |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
438 @end deftypefn") |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
439 { |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
440 octave_value_list retval; |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
441 |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
442 if (args.length () == 1) |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
443 { |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
444 if (nargout < 2) |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
445 retval(0) = args(0).log2 (); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
446 else if (args(0).is_single_type ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
447 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
448 if (args(0).is_real_type ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
449 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
450 FloatNDArray f; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
451 FloatNDArray x = args(0).float_array_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
452 // FIXME -- should E be an int value? |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
453 FloatMatrix e; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
454 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
|
455 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
|
456 retval(0) = f; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
457 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
458 else if (args(0).is_complex_type ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
459 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
460 FloatComplexNDArray f; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
461 FloatComplexNDArray x = args(0).float_complex_array_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
462 // FIXME -- should E be an int value? |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
463 FloatNDArray e; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
464 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
|
465 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
|
466 retval(0) = f; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
467 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
468 } |
9813
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
469 else if (args(0).is_real_type ()) |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
470 { |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
471 NDArray f; |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
472 NDArray x = args(0).array_value (); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
473 // FIXME -- should E be an int value? |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
474 Matrix e; |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
475 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
|
476 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
|
477 retval(0) = f; |
9813
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
478 } |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
479 else if (args(0).is_complex_type ()) |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
480 { |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
481 ComplexNDArray f; |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
482 ComplexNDArray x = args(0).complex_array_value (); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
483 // FIXME -- should E be an int value? |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
484 NDArray e; |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
485 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
|
486 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
|
487 retval(0) = f; |
9813
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
488 } |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
489 else |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
490 gripe_wrong_type_arg ("log2", args(0)); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
491 } |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
492 else |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
493 print_usage (); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
494 |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
495 return retval; |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
496 } |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
497 |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
498 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
499 %!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
|
500 %!assert (log2 (Inf), Inf) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
501 %!assert (isnan (log2 (NaN))) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
502 %!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
|
503 %!assert (log2 (complex (0,Inf)), Inf + log2 (i)) |
9813
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
504 |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
505 %!test |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
506 %! [f, e] = log2 ([0,-1; 2,-4; Inf,-Inf]); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
507 %! 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
|
508 %! assert (e(1:2,:), [0,1;2,3]); |
9813
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
509 |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
510 %!test |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
511 %! [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
|
512 %! 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
|
513 %! assert (e(1:2,:), [0,1; 2,3]); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
514 */ |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
515 |
10436
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
516 DEFUN (rem, args, , |
4311 | 517 "-*- texinfo -*-\n\ |
10840 | 518 @deftypefn {Mapping Function} {} rem (@var{x}, @var{y})\n\ |
10436
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
519 @deftypefnx {Mapping Function} {} fmod (@var{x}, @var{y})\n\ |
12642
f96b9b9f141b
doc: Periodic grammarcheck and spellcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
520 Return the remainder of the division @code{@var{x} / @var{y}}, computed\n\ |
10436
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
521 using the expression\n\ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
522 \n\ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
523 @example\n\ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
524 x - y .* fix (x ./ y)\n\ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
525 @end example\n\ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
526 \n\ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
527 An error message is printed if the dimensions of the arguments do not\n\ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
528 agree, or if either of the arguments is complex.\n\ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
529 @seealso{mod}\n\ |
4311 | 530 @end deftypefn") |
531 { | |
532 octave_value retval; | |
533 | |
534 int nargin = args.length (); | |
535 | |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
536 if (nargin == 2) |
4311 | 537 { |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
538 if (! args(0).is_numeric_type ()) |
10436
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
539 gripe_wrong_type_arg ("rem", args(0)); |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
540 else if (! args(1).is_numeric_type ()) |
10436
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
541 gripe_wrong_type_arg ("rem", args(1)); |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
542 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
|
543 error ("rem: not defined for complex numbers"); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
544 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
|
545 { |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
546 builtin_type_t btyp0 = args(0).builtin_type (); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
547 builtin_type_t btyp1 = args(1).builtin_type (); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
548 if (btyp0 == btyp_double || btyp0 == btyp_float) |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
549 btyp0 = btyp1; |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
550 if (btyp1 == btyp_double || btyp1 == btyp_float) |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
551 btyp1 = btyp0; |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
552 |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
553 if (btyp0 == btyp1) |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
554 { |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
555 switch (btyp0) |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
556 { |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
557 #define MAKE_INT_BRANCH(X) \ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
558 case btyp_ ## X: \ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
559 { \ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
560 X##NDArray a0 = args(0).X##_array_value (); \ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
561 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
|
562 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
|
563 } \ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
564 break |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
565 MAKE_INT_BRANCH (int8); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
566 MAKE_INT_BRANCH (int16); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
567 MAKE_INT_BRANCH (int32); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
568 MAKE_INT_BRANCH (int64); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
569 MAKE_INT_BRANCH (uint8); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
570 MAKE_INT_BRANCH (uint16); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
571 MAKE_INT_BRANCH (uint32); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
572 MAKE_INT_BRANCH (uint64); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
573 #undef MAKE_INT_BRANCH |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
574 default: |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
575 panic_impossible (); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
576 } |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
577 } |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
578 else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
579 error ("rem: cannot combine %s and %d", |
10436
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
580 args(0).class_name ().c_str (), args(1).class_name ().c_str ()); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
581 } |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
582 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
|
583 { |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
584 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
|
585 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
|
586 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
587 { |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
588 FloatNDArray a0 = args(0).float_array_value (); |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
589 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
|
590 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
|
591 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
592 } |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
593 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
594 { |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
595 bool a0_scalar = args(0).is_scalar_type (); |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
596 bool a1_scalar = args(1).is_scalar_type (); |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
597 if (a0_scalar && a1_scalar) |
11209
94d9d412a2a0
improve Matlab compatibility of rem and mod
John W. Eaton <jwe@octave.org>
parents:
10983
diff
changeset
|
598 retval = xrem (args(0).scalar_value (), args(1).scalar_value ()); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
599 else if ((a0_scalar || args(0).is_sparse_type ()) |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
600 && (a1_scalar || args(1).is_sparse_type ())) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
601 { |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
602 SparseMatrix m0 = args(0).sparse_matrix_value (); |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
603 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
|
604 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
|
605 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
606 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
607 { |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
608 NDArray a0 = args(0).array_value (); |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
609 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
|
610 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
|
611 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
612 } |
4311 | 613 } |
614 else | |
5823 | 615 print_usage (); |
4311 | 616 |
617 return retval; | |
618 } | |
619 | |
7506
798b0a00e80c
atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents:
7505
diff
changeset
|
620 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
621 %!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
|
622 %!assert (rem ([1, 2, 3; -1, -2, -3], 2 * ones (2, 3)),[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
|
623 %!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
|
624 %!assert (uint8 (rem ([1, 2, 3; -1, -2, -3], 2 * ones (2, 3))),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
|
625 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
626 %!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
|
627 %!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
|
628 %!error rem () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
629 %!error rem (1, 2, 3) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
630 %!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
|
631 %!error rem (i, 1) |
10436
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
632 */ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
633 |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
634 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
635 |
7741 | 636 %!assert (size (fmod (zeros (0, 2), zeros (0, 2))), [0, 2]) |
637 %!assert (size (fmod (rand (2, 3, 4), zeros (2, 3, 4))), [2, 3, 4]) | |
7743 | 638 %!assert (size (fmod (rand (2, 3, 4), 1)), [2, 3, 4]) |
639 %!assert (size (fmod (1, rand (2, 3, 4))), [2, 3, 4]) | |
640 %!assert (size (fmod (1, 2)), [1, 1]) | |
7506
798b0a00e80c
atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents:
7505
diff
changeset
|
641 */ |
798b0a00e80c
atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents:
7505
diff
changeset
|
642 |
10436
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
643 DEFALIAS (fmod, rem) |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
644 |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
645 DEFUN (mod, args, , |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
646 "-*- texinfo -*-\n\ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
647 @deftypefn {Mapping Function} {} mod (@var{x}, @var{y})\n\ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
648 Compute the modulo of @var{x} and @var{y}. Conceptually this is given by\n\ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
649 \n\ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
650 @example\n\ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
651 x - y .* floor (x ./ y)\n\ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
652 @end example\n\ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
653 \n\ |
10846
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10840
diff
changeset
|
654 @noindent\n\ |
10436
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
655 and is written such that the correct modulus is returned for\n\ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
656 integer types. This function handles negative values correctly. That\n\ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
657 is, @code{mod (-1, 3)} is 2, not -1, as @code{rem (-1, 3)} returns.\n\ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
658 @code{mod (@var{x}, 0)} returns @var{x}.\n\ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
659 \n\ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
660 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
|
661 either of the arguments is complex.\n\ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
662 @seealso{rem}\n\ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
663 @end deftypefn") |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
664 { |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
665 octave_value retval; |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
666 |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
667 int nargin = args.length (); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
668 |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
669 if (nargin == 2) |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
670 { |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
671 if (! args(0).is_numeric_type ()) |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
672 gripe_wrong_type_arg ("mod", args(0)); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
673 else if (! args(1).is_numeric_type ()) |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
674 gripe_wrong_type_arg ("mod", args(1)); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
675 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
|
676 error ("mod: not defined for complex numbers"); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
677 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
|
678 { |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
679 builtin_type_t btyp0 = args(0).builtin_type (); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
680 builtin_type_t btyp1 = args(1).builtin_type (); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
681 if (btyp0 == btyp_double || btyp0 == btyp_float) |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
682 btyp0 = btyp1; |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
683 if (btyp1 == btyp_double || btyp1 == btyp_float) |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
684 btyp1 = btyp0; |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
685 |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
686 if (btyp0 == btyp1) |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
687 { |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
688 switch (btyp0) |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
689 { |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
690 #define MAKE_INT_BRANCH(X) \ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
691 case btyp_ ## X: \ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
692 { \ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
693 X##NDArray a0 = args(0).X##_array_value (); \ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
694 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
|
695 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
|
696 } \ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
697 break |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
698 MAKE_INT_BRANCH (int8); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
699 MAKE_INT_BRANCH (int16); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
700 MAKE_INT_BRANCH (int32); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
701 MAKE_INT_BRANCH (int64); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
702 MAKE_INT_BRANCH (uint8); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
703 MAKE_INT_BRANCH (uint16); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
704 MAKE_INT_BRANCH (uint32); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
705 MAKE_INT_BRANCH (uint64); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
706 #undef MAKE_INT_BRANCH |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
707 default: |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
708 panic_impossible (); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
709 } |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
710 } |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
711 else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
712 error ("mod: cannot combine %s and %d", |
10436
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
713 args(0).class_name ().c_str (), args(1).class_name ().c_str ()); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
714 } |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
715 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
|
716 { |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
717 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
|
718 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
|
719 else |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
720 { |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
721 FloatNDArray a0 = args(0).float_array_value (); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
722 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
|
723 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
|
724 } |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
725 } |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
726 else |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
727 { |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
728 bool a0_scalar = args(0).is_scalar_type (); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
729 bool a1_scalar = args(1).is_scalar_type (); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
730 if (a0_scalar && a1_scalar) |
11209
94d9d412a2a0
improve Matlab compatibility of rem and mod
John W. Eaton <jwe@octave.org>
parents:
10983
diff
changeset
|
731 retval = xmod (args(0).scalar_value (), args(1).scalar_value ()); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
732 else if ((a0_scalar || args(0).is_sparse_type ()) |
10436
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
733 && (a1_scalar || args(1).is_sparse_type ())) |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
734 { |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
735 SparseMatrix m0 = args(0).sparse_matrix_value (); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
736 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
|
737 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
|
738 } |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
739 else |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
740 { |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
741 NDArray a0 = args(0).array_value (); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
742 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
|
743 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
|
744 } |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
745 } |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
746 } |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
747 else |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
748 print_usage (); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
749 |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
750 return retval; |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
751 } |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
752 |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
753 /* |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
754 ## empty input test |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
755 %!assert (isempty (mod ([], []))) |
10436
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
756 |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
757 ## 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
|
758 %!assert (mod (5, 3), 2) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
759 %!assert (mod (-5, 3), 1) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
760 %!assert (mod (0, 3), 0) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
761 %!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
|
762 %!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
|
763 %!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
|
764 |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
765 ## x mod 0 tests |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
766 %!assert (mod (5, 0), 5) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
767 %!assert (mod (-5, 0), -5) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
768 %!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
|
769 %!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
|
770 %!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
|
771 %!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
|
772 |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
773 ## mixed scalar/matrix tests |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
774 %!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
|
775 %!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
|
776 %!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
|
777 %!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
|
778 %!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
|
779 |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
780 ## integer types |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
781 %!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
|
782 %!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
|
783 %!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
|
784 %!error (mod (uint8 (5), int8 (4))) |
10436
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
785 |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
786 ## mixed integer/real types |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
787 %!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
|
788 %!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
|
789 %!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
|
790 |
903c1a3df301
Add additional tests for mod with non-integer real values.
Rik <octave@nomad.inbox5.com>
parents:
11242
diff
changeset
|
791 ## non-integer real numbers |
903c1a3df301
Add additional tests for mod with non-integer real values.
Rik <octave@nomad.inbox5.com>
parents:
11242
diff
changeset
|
792 %!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
|
793 %!assert (mod (2.1, 0.2), 0.1, eps) |
10436
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
794 */ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
795 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
796 // FIXME: Need to convert the 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
|
797 |
7112 | 798 #define NATIVE_REDUCTION_1(FCN, TYPE, DIM) \ |
799 (arg.is_ ## TYPE ## _type ()) \ | |
800 { \ | |
801 TYPE ## NDArray tmp = arg. TYPE ##_array_value (); \ | |
802 \ | |
803 if (! error_state) \ | |
8780
ea76466605ba
support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents:
8756
diff
changeset
|
804 { \ |
ea76466605ba
support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents:
8756
diff
changeset
|
805 retval = tmp.FCN (DIM); \ |
ea76466605ba
support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents:
8756
diff
changeset
|
806 } \ |
7112 | 807 } |
808 | |
8780
ea76466605ba
support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents:
8756
diff
changeset
|
809 #define NATIVE_REDUCTION(FCN, BOOL_FCN) \ |
7112 | 810 \ |
811 octave_value retval; \ | |
812 \ | |
813 int nargin = args.length (); \ | |
814 \ | |
815 bool isnative = false; \ | |
7815
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
816 bool isdouble = false; \ |
7112 | 817 \ |
818 if (nargin > 1 && args(nargin - 1).is_string ()) \ | |
819 { \ | |
820 std::string str = args(nargin - 1).string_value (); \ | |
821 \ | |
822 if (! error_state) \ | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
823 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
824 if (str == "native") \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
825 isnative = true; \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
826 else if (str == "double") \ |
7815
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
827 isdouble = true; \ |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
828 else \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
829 error ("sum: unrecognized string argument"); \ |
7112 | 830 nargin --; \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
831 } \ |
7112 | 832 } \ |
833 \ | |
834 if (nargin == 1 || nargin == 2) \ | |
835 { \ | |
836 octave_value arg = args(0); \ | |
837 \ | |
838 int dim = (nargin == 1 ? -1 : args(1).int_value (true) - 1); \ | |
839 \ | |
840 if (! error_state) \ | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
841 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
842 if (dim >= -1) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
843 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
844 if (arg.is_sparse_type ()) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
845 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
846 if (arg.is_real_type ()) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
847 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
848 SparseMatrix tmp = arg.sparse_matrix_value (); \ |
7515
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7506
diff
changeset
|
849 \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
850 if (! error_state) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
851 retval = tmp.FCN (dim); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
852 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
853 else \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
854 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
855 SparseComplexMatrix tmp = arg.sparse_complex_matrix_value (); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
856 \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
857 if (! error_state) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
858 retval = tmp.FCN (dim); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
859 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
860 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
861 else \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
862 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
863 if (isnative) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
864 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
865 if NATIVE_REDUCTION_1 (FCN, uint8, dim) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
866 else if NATIVE_REDUCTION_1 (FCN, uint16, dim) \ |
7515
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7506
diff
changeset
|
867 else if NATIVE_REDUCTION_1 (FCN, uint32, dim) \ |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7506
diff
changeset
|
868 else if NATIVE_REDUCTION_1 (FCN, uint64, dim) \ |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7506
diff
changeset
|
869 else if NATIVE_REDUCTION_1 (FCN, int8, dim) \ |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7506
diff
changeset
|
870 else if NATIVE_REDUCTION_1 (FCN, int16, dim) \ |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7506
diff
changeset
|
871 else if NATIVE_REDUCTION_1 (FCN, int32, dim) \ |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7506
diff
changeset
|
872 else if NATIVE_REDUCTION_1 (FCN, int64, dim) \ |
8756
d0755c9db5ed
implement fast logical sum (counting)
Jaroslav Hajek <highegg@gmail.com>
parents:
8734
diff
changeset
|
873 else if (arg.is_bool_type ()) \ |
d0755c9db5ed
implement fast logical sum (counting)
Jaroslav Hajek <highegg@gmail.com>
parents:
8734
diff
changeset
|
874 { \ |
8780
ea76466605ba
support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents:
8756
diff
changeset
|
875 boolNDArray tmp = arg.bool_array_value (); \ |
8756
d0755c9db5ed
implement fast logical sum (counting)
Jaroslav Hajek <highegg@gmail.com>
parents:
8734
diff
changeset
|
876 if (! error_state) \ |
8780
ea76466605ba
support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents:
8756
diff
changeset
|
877 retval = boolNDArray (tmp.BOOL_FCN (dim)); \ |
8756
d0755c9db5ed
implement fast logical sum (counting)
Jaroslav Hajek <highegg@gmail.com>
parents:
8734
diff
changeset
|
878 } \ |
7515
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7506
diff
changeset
|
879 else if (arg.is_char_matrix ()) \ |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7506
diff
changeset
|
880 { \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
881 error (#FCN, ": invalid char type"); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
882 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
883 else if (!isdouble && arg.is_single_type ()) \ |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7743
diff
changeset
|
884 { \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
885 if (arg.is_complex_type ()) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
886 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
887 FloatComplexNDArray tmp = \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
888 arg.float_complex_array_value (); \ |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7743
diff
changeset
|
889 \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
890 if (! error_state) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
891 retval = tmp.FCN (dim); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
892 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
893 else if (arg.is_real_type ()) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
894 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
895 FloatNDArray tmp = arg.float_array_value (); \ |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7743
diff
changeset
|
896 \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
897 if (! error_state) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
898 retval = tmp.FCN (dim); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
899 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
900 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
901 else if (arg.is_complex_type ()) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
902 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
903 ComplexNDArray tmp = arg.complex_array_value (); \ |
7515
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7506
diff
changeset
|
904 \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
905 if (! error_state) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
906 retval = tmp.FCN (dim); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
907 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
908 else if (arg.is_real_type ()) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
909 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
910 NDArray tmp = arg.array_value (); \ |
7515
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7506
diff
changeset
|
911 \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
912 if (! error_state) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
913 retval = tmp.FCN (dim); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
914 } \ |
7515
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7506
diff
changeset
|
915 else \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
916 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
917 gripe_wrong_type_arg (#FCN, arg); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
918 return retval; \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
919 } \ |
7112 | 920 } \ |
8756
d0755c9db5ed
implement fast logical sum (counting)
Jaroslav Hajek <highegg@gmail.com>
parents:
8734
diff
changeset
|
921 else if (arg.is_bool_type ()) \ |
d0755c9db5ed
implement fast logical sum (counting)
Jaroslav Hajek <highegg@gmail.com>
parents:
8734
diff
changeset
|
922 { \ |
d0755c9db5ed
implement fast logical sum (counting)
Jaroslav Hajek <highegg@gmail.com>
parents:
8734
diff
changeset
|
923 boolNDArray tmp = arg.bool_array_value (); \ |
d0755c9db5ed
implement fast logical sum (counting)
Jaroslav Hajek <highegg@gmail.com>
parents:
8734
diff
changeset
|
924 if (! error_state) \ |
d0755c9db5ed
implement fast logical sum (counting)
Jaroslav Hajek <highegg@gmail.com>
parents:
8734
diff
changeset
|
925 retval = tmp.FCN (dim); \ |
d0755c9db5ed
implement fast logical sum (counting)
Jaroslav Hajek <highegg@gmail.com>
parents:
8734
diff
changeset
|
926 } \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
927 else if (!isdouble && arg.is_single_type ()) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
928 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
929 if (arg.is_real_type ()) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
930 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
931 FloatNDArray tmp = arg.float_array_value (); \ |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7743
diff
changeset
|
932 \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
933 if (! error_state) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
934 retval = tmp.FCN (dim); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
935 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
936 else if (arg.is_complex_type ()) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
937 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
938 FloatComplexNDArray tmp = \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
939 arg.float_complex_array_value (); \ |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7743
diff
changeset
|
940 \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
941 if (! error_state) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
942 retval = tmp.FCN (dim); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
943 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
944 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
945 else if (arg.is_real_type ()) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
946 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
947 NDArray tmp = arg.array_value (); \ |
7515
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7506
diff
changeset
|
948 \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
949 if (! error_state) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
950 retval = tmp.FCN (dim); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
951 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
952 else if (arg.is_complex_type ()) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
953 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
954 ComplexNDArray tmp = arg.complex_array_value (); \ |
7112 | 955 \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
956 if (! error_state) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
957 retval = tmp.FCN (dim); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
958 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
959 else \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
960 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
961 gripe_wrong_type_arg (#FCN, arg); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
962 return retval; \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
963 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
964 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
965 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
966 else \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
967 error (#FCN ": invalid dimension argument = %d", dim + 1); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
968 } \ |
7112 | 969 \ |
970 } \ | |
971 else \ | |
972 print_usage (); \ | |
973 \ | |
974 return retval | |
975 | |
3723 | 976 #define DATA_REDUCTION(FCN) \ |
977 \ | |
4233 | 978 octave_value retval; \ |
3723 | 979 \ |
980 int nargin = args.length (); \ | |
981 \ | |
982 if (nargin == 1 || nargin == 2) \ | |
983 { \ | |
984 octave_value arg = args(0); \ | |
985 \ | |
3864 | 986 int dim = (nargin == 1 ? -1 : args(1).int_value (true) - 1); \ |
3723 | 987 \ |
988 if (! error_state) \ | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
989 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
990 if (dim >= -1) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
991 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
992 if (arg.is_real_type ()) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
993 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
994 if (arg.is_sparse_type ()) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
995 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
996 SparseMatrix tmp = arg.sparse_matrix_value (); \ |
3723 | 997 \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
998 if (! error_state) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
999 retval = tmp.FCN (dim); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1000 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1001 else if (arg.is_single_type ()) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1002 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1003 FloatNDArray tmp = arg.float_array_value (); \ |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7743
diff
changeset
|
1004 \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1005 if (! error_state) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1006 retval = tmp.FCN (dim); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1007 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1008 else \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1009 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1010 NDArray tmp = arg.array_value (); \ |
7515
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7506
diff
changeset
|
1011 \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1012 if (! error_state) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1013 retval = tmp.FCN (dim); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1014 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1015 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1016 else if (arg.is_complex_type ()) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1017 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1018 if (arg.is_sparse_type ()) \ |
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 SparseComplexMatrix tmp = arg.sparse_complex_matrix_value (); \ |
3723 | 1021 \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1022 if (! error_state) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1023 retval = tmp.FCN (dim); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1024 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1025 else if (arg.is_single_type ()) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1026 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1027 FloatComplexNDArray tmp = arg.float_complex_array_value (); \ |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7743
diff
changeset
|
1028 \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1029 if (! error_state) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1030 retval = tmp.FCN (dim); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1031 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1032 else \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1033 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1034 ComplexNDArray tmp = arg.complex_array_value (); \ |
7515
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7506
diff
changeset
|
1035 \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1036 if (! error_state) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1037 retval = tmp.FCN (dim); \ |
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 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1040 else \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1041 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1042 gripe_wrong_type_arg (#FCN, arg); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1043 return retval; \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1044 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1045 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1046 else \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1047 error (#FCN ": invalid dimension argument = %d", dim + 1); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1048 } \ |
3723 | 1049 } \ |
1050 else \ | |
5823 | 1051 print_usage (); \ |
3723 | 1052 \ |
1053 return retval | |
1054 | |
1957 | 1055 DEFUN (cumprod, args, , |
3428 | 1056 "-*- texinfo -*-\n\ |
9163
9cb0c21e97f7
Update section 17.4 (Sums and Products) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9155
diff
changeset
|
1057 @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
|
1058 @deftypefnx {Built-in Function} {} cumprod (@var{x}, @var{dim})\n\ |
3723 | 1059 Cumulative product of elements along dimension @var{dim}. If\n\ |
9723
f426899f4b9c
fix reduction functions docstrings
Jaroslav Hajek <highegg@gmail.com>
parents:
9721
diff
changeset
|
1060 @var{dim} is omitted, it defaults to the first non-singleton dimension.\n\ |
5061 | 1061 \n\ |
9163
9cb0c21e97f7
Update section 17.4 (Sums and Products) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9155
diff
changeset
|
1062 @seealso{prod, cumsum}\n\ |
3428 | 1063 @end deftypefn") |
523 | 1064 { |
3723 | 1065 DATA_REDUCTION (cumprod); |
523 | 1066 } |
1067 | |
7815
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1068 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1069 %!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
|
1070 %!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
|
1071 %!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
|
1072 %!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
|
1073 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1074 %!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
|
1075 %!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
|
1076 %!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
|
1077 %!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
|
1078 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1079 %!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
|
1080 %!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
|
1081 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1082 %!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
|
1083 %!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
|
1084 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1085 %!error cumprod () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1086 */ |
7815
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1087 |
1957 | 1088 DEFUN (cumsum, args, , |
3428 | 1089 "-*- texinfo -*-\n\ |
9163
9cb0c21e97f7
Update section 17.4 (Sums and Products) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9155
diff
changeset
|
1090 @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
|
1091 @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
|
1092 @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
|
1093 @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
|
1094 @deftypefnx {Built-in Function} {} cumsum (@dots{}, \"extra\")\n\ |
3723 | 1095 Cumulative sum of elements along dimension @var{dim}. If @var{dim}\n\ |
9723
f426899f4b9c
fix reduction functions docstrings
Jaroslav Hajek <highegg@gmail.com>
parents:
9721
diff
changeset
|
1096 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
|
1097 \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
|
1098 See @code{sum} for an explanation of the optional parameters \"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
|
1099 \"double\", and \"extra\".\n\ |
9163
9cb0c21e97f7
Update section 17.4 (Sums and Products) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9155
diff
changeset
|
1100 @seealso{sum, cumprod}\n\ |
3428 | 1101 @end deftypefn") |
523 | 1102 { |
9721
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1103 octave_value retval; |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1104 |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1105 int nargin = args.length (); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1106 |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1107 bool isnative = false; |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1108 bool isdouble = false; |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1109 |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1110 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
|
1111 { |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1112 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
|
1113 |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1114 if (! error_state) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1115 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1116 if (str == "native") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1117 isnative = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1118 else if (str == "double") |
9721
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1119 isdouble = true; |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1120 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1121 error ("sum: unrecognized string argument"); |
9721
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1122 nargin --; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1123 } |
9721
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1124 } |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1125 |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1126 if (error_state) |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1127 return retval; |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1128 |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1129 if (nargin == 1 || nargin == 2) |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1130 { |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1131 octave_value arg = args(0); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1132 |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1133 int dim = -1; |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1134 if (nargin == 2) |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1135 { |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1136 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
|
1137 if (dim < 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1138 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
|
1139 } |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1140 |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1141 if (! error_state) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1142 { |
9721
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1143 switch (arg.builtin_type ()) |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1144 { |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1145 case btyp_double: |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1146 if (arg.is_sparse_type ()) |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1147 retval = arg.sparse_matrix_value ().cumsum (dim); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1148 else |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1149 retval = arg.array_value ().cumsum (dim); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1150 break; |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1151 case btyp_complex: |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1152 if (arg.is_sparse_type ()) |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1153 retval = arg.sparse_complex_matrix_value ().cumsum (dim); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1154 else |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1155 retval = arg.complex_array_value ().cumsum (dim); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1156 break; |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1157 case btyp_float: |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1158 if (isdouble) |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1159 retval = arg.array_value ().cumsum (dim); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1160 else |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1161 retval = arg.float_array_value ().cumsum (dim); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1162 break; |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1163 case btyp_float_complex: |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1164 if (isdouble) |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1165 retval = arg.complex_array_value ().cumsum (dim); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1166 else |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1167 retval = arg.float_complex_array_value ().cumsum (dim); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1168 break; |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1169 |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1170 #define MAKE_INT_BRANCH(X) \ |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1171 case btyp_ ## X: \ |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1172 if (isnative) \ |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1173 retval = arg.X ## _array_value ().cumsum (dim); \ |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1174 else \ |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1175 retval = arg.array_value ().cumsum (dim); \ |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1176 break |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1177 MAKE_INT_BRANCH (int8); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1178 MAKE_INT_BRANCH (int16); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1179 MAKE_INT_BRANCH (int32); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1180 MAKE_INT_BRANCH (int64); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1181 MAKE_INT_BRANCH (uint8); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1182 MAKE_INT_BRANCH (uint16); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1183 MAKE_INT_BRANCH (uint32); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1184 MAKE_INT_BRANCH (uint64); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1185 #undef MAKE_INT_BRANCH |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1186 |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1187 case btyp_bool: |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1188 if (arg.is_sparse_type ()) |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1189 { |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1190 SparseMatrix cs = arg.sparse_matrix_value ().cumsum (dim); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1191 if (isnative) |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1192 retval = cs != 0.0; |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1193 else |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1194 retval = cs; |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1195 } |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1196 else |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1197 { |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1198 NDArray cs = arg.bool_array_value ().cumsum (dim); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1199 if (isnative) |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1200 retval = cs != 0.0; |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1201 else |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1202 retval = cs; |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1203 } |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1204 break; |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1205 |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1206 default: |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1207 gripe_wrong_type_arg ("cumsum", arg); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1208 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1209 } |
9721
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1210 } |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1211 else |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1212 print_usage (); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1213 |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1214 return retval; |
523 | 1215 } |
1216 | |
7815
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1217 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1218 %!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
|
1219 %!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
|
1220 %!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
|
1221 %!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
|
1222 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1223 %!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
|
1224 %!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
|
1225 %!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
|
1226 %!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
|
1227 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1228 %!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
|
1229 %!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
|
1230 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1231 %!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
|
1232 %!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
|
1233 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1234 %!error cumsum () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1235 */ |
7815
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1236 |
1957 | 1237 DEFUN (diag, args, , |
3369 | 1238 "-*- texinfo -*-\n\ |
12567
cc8ccdfec424
Remove archaic 3-input argument form of diag function.
Rik <octave@nomad.inbox5.com>
parents:
12546
diff
changeset
|
1239 @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
|
1240 @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
|
1241 @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
|
1242 @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
|
1243 @deftypefnx {Built-in Function} {@var{v} =} diag (@var{M}, @var{k})\n\ |
3369 | 1244 Return a diagonal matrix with vector @var{v} on diagonal @var{k}. The\n\ |
1245 second argument is optional. If it is positive, the vector is placed on\n\ | |
1246 the @var{k}-th super-diagonal. If it is negative, it is placed on the\n\ | |
1247 @var{-k}-th sub-diagonal. The default value of @var{k} is 0, and the\n\ | |
10840 | 1248 vector is placed on the main diagonal. For example:\n\ |
3369 | 1249 \n\ |
1250 @example\n\ | |
1251 @group\n\ | |
1252 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
|
1253 @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
|
1254 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
|
1255 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
|
1256 0 0 0 0\n\ |
3369 | 1257 @end group\n\ |
1258 @end example\n\ | |
6772 | 1259 \n\ |
1260 @noindent\n\ | |
12571
bed932910eb9
Add documentation for 3-input form of diag(). Add new tests.
Rik <octave@nomad.inbox5.com>
parents:
12570
diff
changeset
|
1261 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
|
1262 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
|
1263 columns.\n\ |
bed932910eb9
Add documentation for 3-input form of diag(). Add new tests.
Rik <octave@nomad.inbox5.com>
parents:
12570
diff
changeset
|
1264 \n\ |
6772 | 1265 Given a matrix argument, instead of a vector, @code{diag} extracts the\n\ |
6774 | 1266 @var{k}-th diagonal of the matrix.\n\ |
3369 | 1267 @end deftypefn") |
523 | 1268 { |
4233 | 1269 octave_value retval; |
523 | 1270 |
1271 int nargin = args.length (); | |
1272 | |
712 | 1273 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
|
1274 retval = args(0).diag (); |
712 | 1275 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
|
1276 { |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7618
diff
changeset
|
1277 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
|
1278 |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7618
diff
changeset
|
1279 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
|
1280 error ("diag: invalid argument K"); |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7618
diff
changeset
|
1281 else |
14843
7d4f87c75dbb
data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents:
14635
diff
changeset
|
1282 retval = args(0).diag (k); |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7618
diff
changeset
|
1283 } |
12570
1a93988610a3
Reverse changset cc8ccdfec424. Restore 3-input form of diag().
Rik <octave@nomad.inbox5.com>
parents:
12567
diff
changeset
|
1284 else if (nargin == 3) |
1a93988610a3
Reverse changset cc8ccdfec424. Restore 3-input form of diag().
Rik <octave@nomad.inbox5.com>
parents:
12567
diff
changeset
|
1285 { |
1a93988610a3
Reverse changset cc8ccdfec424. Restore 3-input form of diag().
Rik <octave@nomad.inbox5.com>
parents:
12567
diff
changeset
|
1286 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
|
1287 |
e8e86ae3abbc
make diag (x, m, n) return a proper diagonal matrix object (bug #36099)
John W. Eaton <jwe@octave.org>
parents:
14521
diff
changeset
|
1288 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
|
1289 { |
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
|
1290 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
|
1291 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
|
1292 |
12570
1a93988610a3
Reverse changset cc8ccdfec424. Restore 3-input form of diag().
Rik <octave@nomad.inbox5.com>
parents:
12567
diff
changeset
|
1293 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
|
1294 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
|
1295 else |
1a93988610a3
Reverse changset cc8ccdfec424. Restore 3-input form of diag().
Rik <octave@nomad.inbox5.com>
parents:
12567
diff
changeset
|
1296 error ("diag: invalid dimensions"); |
1a93988610a3
Reverse changset cc8ccdfec424. Restore 3-input form of diag().
Rik <octave@nomad.inbox5.com>
parents:
12567
diff
changeset
|
1297 } |
1a93988610a3
Reverse changset cc8ccdfec424. Restore 3-input form of diag().
Rik <octave@nomad.inbox5.com>
parents:
12567
diff
changeset
|
1298 else |
1a93988610a3
Reverse changset cc8ccdfec424. Restore 3-input form of diag().
Rik <octave@nomad.inbox5.com>
parents:
12567
diff
changeset
|
1299 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
|
1300 } |
523 | 1301 else |
5823 | 1302 print_usage (); |
523 | 1303 |
1304 return retval; | |
1305 } | |
1306 | |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1307 /* |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1308 |
14843
7d4f87c75dbb
data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents:
14635
diff
changeset
|
1309 %!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
|
1310 %!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
|
1311 %!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
|
1312 %!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
|
1313 %!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
|
1314 |
7d4f87c75dbb
data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents:
14635
diff
changeset
|
1315 %!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
|
1316 %!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
|
1317 %!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
|
1318 %!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
|
1319 %!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
|
1320 |
7d4f87c75dbb
data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents:
14635
diff
changeset
|
1321 %!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
|
1322 %!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
|
1323 %!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
|
1324 %!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
|
1325 %!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
|
1326 |
7d4f87c75dbb
data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents:
14635
diff
changeset
|
1327 %!assert (diag (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
|
1328 %!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
|
1329 %!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
|
1330 |
7d4f87c75dbb
data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents:
14635
diff
changeset
|
1331 %!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
|
1332 %!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
|
1333 %!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
|
1334 %!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
|
1335 %!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
|
1336 |
7d4f87c75dbb
data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents:
14635
diff
changeset
|
1337 %!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
|
1338 %!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
|
1339 %!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
|
1340 |
15428
fd5c0159b588
Fix diag handling of diagvectors (bug #37411)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14567
diff
changeset
|
1341 ## bug #37411 |
fd5c0159b588
Fix diag handling of diagvectors (bug #37411)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14567
diff
changeset
|
1342 %!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
|
1343 %!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
|
1344 %!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
|
1345 |
14490
3959f3f81e33
Initialise memory in non-square diag call (bug #35946)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14171
diff
changeset
|
1346 ## 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
|
1347 %!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
|
1348 %!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
|
1349 %!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
|
1350 %!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
|
1351 |
12571
bed932910eb9
Add documentation for 3-input form of diag(). Add new tests.
Rik <octave@nomad.inbox5.com>
parents:
12570
diff
changeset
|
1352 %% Test input validation |
14491
5bd9e47e9277
maint: periodic merge of stable to default
Jordi Gutiérrez Hermoso <jordigh@octave.org>
diff
changeset
|
1353 %!error <Invalid call to diag> diag () |
5bd9e47e9277
maint: periodic merge of stable to default
Jordi Gutiérrez Hermoso <jordigh@octave.org>
diff
changeset
|
1354 %!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
|
1355 %!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
|
1356 %!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
|
1357 |
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
|
1358 %!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
|
1359 %!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
|
1360 %!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
|
1361 %!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
|
1362 %!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
|
1363 %!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
|
1364 %!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
|
1365 %!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
|
1366 */ |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1367 |
1957 | 1368 DEFUN (prod, args, , |
3428 | 1369 "-*- texinfo -*-\n\ |
9163
9cb0c21e97f7
Update section 17.4 (Sums and Products) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9155
diff
changeset
|
1370 @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
|
1371 @deftypefnx {Built-in Function} {} prod (@var{x}, @var{dim})\n\ |
3723 | 1372 Product of elements along dimension @var{dim}. If @var{dim} is\n\ |
9723
f426899f4b9c
fix reduction functions docstrings
Jaroslav Hajek <highegg@gmail.com>
parents:
9721
diff
changeset
|
1373 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
|
1374 @seealso{cumprod, sum}\n\ |
3428 | 1375 @end deftypefn") |
523 | 1376 { |
3723 | 1377 DATA_REDUCTION (prod); |
523 | 1378 } |
1379 | |
7815
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1380 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1381 %!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
|
1382 %!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
|
1383 %!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
|
1384 %!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
|
1385 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1386 %!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
|
1387 %!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
|
1388 %!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
|
1389 %!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
|
1390 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1391 %!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
|
1392 %!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
|
1393 %!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
|
1394 %!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
|
1395 %!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
|
1396 %!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
|
1397 %!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
|
1398 %!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
|
1399 %!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
|
1400 %!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
|
1401 %!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
|
1402 %!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
|
1403 %!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
|
1404 %!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
|
1405 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1406 %!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
|
1407 %!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
|
1408 %!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
|
1409 %!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
|
1410 %!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
|
1411 %!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
|
1412 %!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
|
1413 %!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
|
1414 %!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
|
1415 %!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
|
1416 %!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
|
1417 %!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
|
1418 %!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
|
1419 %!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
|
1420 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1421 %!error prod () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1422 */ |
7815
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1423 |
10758
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1424 static bool |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1425 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
|
1426 { |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1427 int n_args = args.length (); |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1428 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
|
1429 if (args(i).numel () != 1) |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1430 return false; |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1431 |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1432 return true; |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1433 } |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1434 |
10533
f094ac9bc93e
reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents:
10498
diff
changeset
|
1435 template <class TYPE, class T> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
1436 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
|
1437 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
|
1438 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
|
1439 int dim) |
f094ac9bc93e
reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents:
10498
diff
changeset
|
1440 { |
f094ac9bc93e
reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents:
10498
diff
changeset
|
1441 int n_args = args.length (); |
10758
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1442 if (! (equal_types<T, char>::value |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1443 || equal_types<T, octave_value>::value) |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1444 && 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
|
1445 { |
10758
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1446 // Optimize all scalars case. |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1447 dim_vector dv (1, 1); |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1448 if (dim == -1 || dim == -2) |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1449 dim = -dim - 1; |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1450 else if (dim >= 2) |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1451 dv.resize (dim+1, 1); |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1452 dv(dim) = n_args; |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1453 |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1454 result.clear (dv); |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1455 |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1456 for (int j = 0; j < n_args && ! error_state; j++) |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1457 { |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1458 octave_quit (); |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1459 |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1460 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
|
1461 } |
10533
f094ac9bc93e
reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents:
10498
diff
changeset
|
1462 } |
10758
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1463 else |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1464 { |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1465 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
|
1466 |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1467 for (int j = 0; j < n_args && ! error_state; j++) |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1468 { |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1469 octave_quit (); |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1470 |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1471 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
|
1472 } |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1473 |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1474 if (! error_state) |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1475 result = Array<T>::cat (dim, n_args, array_list); |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1476 } |
10533
f094ac9bc93e
reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents:
10498
diff
changeset
|
1477 } |
f094ac9bc93e
reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents:
10498
diff
changeset
|
1478 |
f094ac9bc93e
reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents:
10498
diff
changeset
|
1479 template <class TYPE, class T> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
1480 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
|
1481 single_type_concat (Sparse<T>& result, |
10498
8615b55b5caf
fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents:
10436
diff
changeset
|
1482 const octave_value_list& args, |
8615b55b5caf
fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents:
10436
diff
changeset
|
1483 int dim) |
8615b55b5caf
fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents:
10436
diff
changeset
|
1484 { |
10533
f094ac9bc93e
reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents:
10498
diff
changeset
|
1485 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
|
1486 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
|
1487 |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1488 for (int j = 0; j < n_args && ! error_state; j++) |
10498
8615b55b5caf
fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents:
10436
diff
changeset
|
1489 { |
8615b55b5caf
fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents:
10436
diff
changeset
|
1490 octave_quit (); |
8615b55b5caf
fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents:
10436
diff
changeset
|
1491 |
10716
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1492 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
|
1493 } |
10533
f094ac9bc93e
reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents:
10498
diff
changeset
|
1494 |
f094ac9bc93e
reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents:
10498
diff
changeset
|
1495 if (! error_state) |
10716
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1496 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
|
1497 } |
8615b55b5caf
fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents:
10436
diff
changeset
|
1498 |
10533
f094ac9bc93e
reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents:
10498
diff
changeset
|
1499 // Dispatcher. |
10498
8615b55b5caf
fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents:
10436
diff
changeset
|
1500 template<class TYPE> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
1501 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
|
1502 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
|
1503 { |
10533
f094ac9bc93e
reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents:
10498
diff
changeset
|
1504 TYPE result; |
f094ac9bc93e
reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents:
10498
diff
changeset
|
1505 |
f094ac9bc93e
reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents:
10498
diff
changeset
|
1506 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
|
1507 |
8615b55b5caf
fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents:
10436
diff
changeset
|
1508 return result; |
8615b55b5caf
fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents:
10436
diff
changeset
|
1509 } |
8615b55b5caf
fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents:
10436
diff
changeset
|
1510 |
10758
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1511 template<class MAP> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
1512 static void |
10758
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1513 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
|
1514 const octave_value_list& args, |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1515 int dim) |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1516 { |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1517 int n_args = args.length (); |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1518 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
|
1519 |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1520 for (int j = 0; j < n_args && ! error_state; j++) |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1521 { |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1522 octave_quit (); |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1523 |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1524 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
|
1525 } |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1526 |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1527 if (! error_state) |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1528 result = octave_map::cat (dim, n_args, map_list); |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1529 } |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1530 |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1531 static octave_map |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1532 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
|
1533 int dim) |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1534 { |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1535 octave_map result; |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1536 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
|
1537 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
|
1538 else |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1539 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
|
1540 |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1541 return result; |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1542 } |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1543 |
4824 | 1544 static octave_value |
13294
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1545 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
|
1546 { |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1547 octave_value retval; |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1548 |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1549 // 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
|
1550 // 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
|
1551 // type. |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1552 |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1553 std::string cname = ov.class_name (); |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1554 |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1555 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
|
1556 |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1557 if (fcn.is_defined ()) |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1558 { |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1559 octave_value_list result |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1560 = 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
|
1561 |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1562 if (! error_state && result.length () > 0) |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1563 retval = result(0); |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1564 else |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1565 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
|
1566 cname.c_str ()); |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1567 } |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1568 else |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1569 { |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1570 // 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
|
1571 // dispatch type. |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1572 |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1573 fcn = symbol_table::find_method (dtype, dtype); |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1574 |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1575 if (fcn.is_defined ()) |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1576 { |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1577 octave_value_list result |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1578 = 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
|
1579 |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1580 if (! error_state && result.length () > 0) |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1581 retval = result(0); |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1582 else |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1583 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
|
1584 cname.c_str ()); |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1585 } |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1586 else |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1587 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
|
1588 } |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1589 |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1590 return retval; |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1591 } |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1592 |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1593 octave_value |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1594 do_class_concat (const octave_value_list& ovl, std::string cattype, int dim) |
4806 | 1595 { |
1596 octave_value retval; | |
1597 | |
13294
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1598 // Get dominant type for list |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1599 |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1600 std::string dtype = get_dispatch_type (ovl); |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1601 |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1602 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
|
1603 |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1604 if (fcn.is_defined ()) |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1605 { |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1606 // 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
|
1607 // conversions. |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1608 |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1609 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
|
1610 |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1611 if (! error_state) |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1612 { |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1613 if (tmp2.length () > 0) |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1614 retval = tmp2(0); |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1615 else |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1616 { |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1617 error ("%s/%s method did not return a value", |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1618 dtype.c_str (), cattype.c_str ()); |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1619 goto done; |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1620 } |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1621 } |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1622 else |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1623 goto done; |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1624 } |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1625 else |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1626 { |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1627 // 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
|
1628 // 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
|
1629 // default operation for octave_class values. |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1630 |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1631 octave_idx_type j = 0; |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1632 octave_idx_type len = ovl.length (); |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1633 octave_value_list tmp (len, octave_value ()); |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1634 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
|
1635 { |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1636 octave_value elt = ovl(k); |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1637 |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1638 std::string t1_type = elt.class_name (); |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1639 |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1640 if (t1_type == dtype) |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1641 tmp(j++) = elt; |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1642 else if (elt.is_object () || ! elt.is_empty ()) |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1643 { |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1644 tmp(j++) = attempt_type_conversion (elt, dtype); |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1645 |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1646 if (error_state) |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1647 goto done; |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1648 } |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1649 } |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1650 |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1651 tmp.resize (j); |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1652 |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1653 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
|
1654 |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1655 std::string cname = tmp(0).class_name (); |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1656 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
|
1657 |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1658 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
|
1659 } |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1660 |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1661 done: |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1662 return retval; |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1663 } |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1664 |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1665 static octave_value |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1666 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
|
1667 { |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1668 octave_value retval; |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1669 |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1670 // 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
|
1671 // 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
|
1672 // reference counts. |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1673 octave_value_list args = xargs; |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1674 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
1675 int n_args = args.length (); |
4806 | 1676 |
10716
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1677 if (n_args == 0) |
5714 | 1678 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
|
1679 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
|
1680 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
|
1681 else if (n_args > 1) |
4824 | 1682 { |
13294
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1683 std::string result_type; |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1684 |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1685 bool all_sq_strings_p = true; |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1686 bool all_dq_strings_p = true; |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1687 bool all_real_p = true; |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1688 bool all_cmplx_p = true; |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1689 bool any_sparse_p = false; |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1690 bool any_cell_p = false; |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1691 bool any_class_p = false; |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1692 |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1693 bool first_elem_is_struct = false; |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1694 |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1695 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
|
1696 { |
13294
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1697 if (i == 0) |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1698 { |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1699 result_type = args(i).class_name (); |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1700 |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1701 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
|
1702 } |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1703 else |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1704 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
|
1705 |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1706 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
|
1707 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
|
1708 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
|
1709 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
|
1710 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
|
1711 all_real_p = false; |
13294
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1712 if (all_cmplx_p && ! (args(i).is_complex_type () || args(i).is_real_type ())) |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1713 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
|
1714 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
|
1715 any_sparse_p = true; |
13294
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1716 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
|
1717 any_cell_p = true; |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1718 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
|
1719 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
|
1720 } |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1721 |
13294
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1722 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
|
1723 { |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1724 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
|
1725 { |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1726 if (! args(i).is_cell ()) |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1727 args(i) = Cell (args(i)); |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1728 } |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1729 } |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1730 |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1731 if (any_class_p) |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1732 { |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1733 retval = do_class_concat (args, fname, dim); |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1734 } |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1735 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
|
1736 { |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1737 if (any_sparse_p) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
1738 { |
10716
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1739 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
|
1740 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
|
1741 else |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1742 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
|
1743 } |
10716
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1744 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1745 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1746 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
|
1747 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
|
1748 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
|
1749 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
|
1750 } |
10716
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1751 } |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1752 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
|
1753 { |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1754 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
|
1755 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
|
1756 else |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1757 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
|
1758 } |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1759 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
|
1760 { |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1761 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
|
1762 |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1763 maybe_warn_string_concat (all_dq_strings_p, all_sq_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
|
1764 |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1765 charNDArray result = do_single_type_concat<charNDArray> (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
|
1766 |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1767 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
|
1768 } |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1769 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
|
1770 { |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1771 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
|
1772 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
|
1773 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
|
1774 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
|
1775 } |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1776 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
|
1777 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
|
1778 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
|
1779 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
|
1780 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
|
1781 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
|
1782 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
|
1783 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
|
1784 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
|
1785 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
|
1786 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
|
1787 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
|
1788 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
|
1789 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
|
1790 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
|
1791 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
|
1792 else if (result_type == "cell") |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1793 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
|
1794 else if (result_type == "struct") |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1795 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
|
1796 else |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1797 { |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1798 dim_vector dv = args(0).dims (); |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1799 |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1800 // Default concatenation. |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1801 bool (dim_vector::*concat_rule) (const dim_vector&, int) = &dim_vector::concat; |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1802 |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1803 if (dim == -1 || dim == -2) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1804 { |
10716
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1805 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
|
1806 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
|
1807 } |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1808 |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1809 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
|
1810 { |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1811 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
|
1812 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
1813 // 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
|
1814 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
|
1815 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
|
1816 } |
10716
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1817 } |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1818 |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1819 // 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
|
1820 // 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
|
1821 // 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
|
1822 // 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
|
1823 // 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
|
1824 // 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
|
1825 // 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
|
1826 // |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1827 // 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
|
1828 // 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
|
1829 // (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
|
1830 // 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
|
1831 // 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
|
1832 |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1833 octave_value tmp = 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
|
1834 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
|
1835 |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1836 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
|
1837 return retval; |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1838 |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1839 int dv_len = dv.length (); |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1840 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
|
1841 |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1842 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
|
1843 { |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1844 // 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
|
1845 // 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
|
1846 // the right type. |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1847 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
|
1848 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1849 if (error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1850 return retval; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1851 |
10716
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1852 dim_vector dv_tmp = args (j).dims (); |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1853 |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1854 if (dim >= dv_len) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1855 { |
10716
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1856 if (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
|
1857 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
|
1858 break; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1859 } |
10716
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1860 else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
1861 ra_idx (dim) += (dim < dv_tmp.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
|
1862 dv_tmp (dim) : 1); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1863 } |
10716
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1864 retval = tmp; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1865 } |
4806 | 1866 } |
1867 else | |
5823 | 1868 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
|
1869 |
4806 | 1870 return retval; |
1871 } | |
1872 | |
1873 DEFUN (horzcat, args, , | |
4824 | 1874 "-*- texinfo -*-\n\ |
4806 | 1875 @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
|
1876 Return the horizontal concatenation of N-D array objects, @var{array1},\n\ |
4806 | 1877 @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
|
1878 \n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
1879 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
|
1880 new matrices. For example:\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
1881 \n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
1882 @example\n\ |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
1883 @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
|
1884 @end example\n\ |
5642 | 1885 @seealso{cat, vertcat}\n\ |
1886 @end deftypefn") | |
4806 | 1887 { |
10716
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1888 return do_cat (args, -2, "horzcat"); |
4806 | 1889 } |
1890 | |
13294
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
1891 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1892 ## 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
|
1893 %!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
|
1894 %!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
|
1895 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1896 %!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
|
1897 %!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
|
1898 %!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
|
1899 %!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
|
1900 %!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
|
1901 %!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
|
1902 %!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
|
1903 %!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
|
1904 %!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
|
1905 %!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
|
1906 %!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
|
1907 %!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
|
1908 %!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
|
1909 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1910 %!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
|
1911 %!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
|
1912 %!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
|
1913 %!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
|
1914 %!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
|
1915 %!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
|
1916 %!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
|
1917 %!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
|
1918 %!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
|
1919 %!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
|
1920 %!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
|
1921 %!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
|
1922 %!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
|
1923 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1924 %!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
|
1925 %!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
|
1926 %!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
|
1927 %!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
|
1928 %!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
|
1929 %!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
|
1930 %!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
|
1931 %!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
|
1932 %!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
|
1933 %!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
|
1934 %!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
|
1935 %!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
|
1936 %!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
|
1937 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1938 %!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
|
1939 %!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
|
1940 %!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
|
1941 %!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
|
1942 %!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
|
1943 %!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
|
1944 %!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
|
1945 %!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
|
1946 %!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
|
1947 %!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
|
1948 %!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
|
1949 %!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
|
1950 %!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
|
1951 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1952 %!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
|
1953 %!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
|
1954 %!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
|
1955 %!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
|
1956 %!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
|
1957 %!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
|
1958 %!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
|
1959 %!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
|
1960 %!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
|
1961 %!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
|
1962 %!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
|
1963 %!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
|
1964 %!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
|
1965 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1966 %!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
|
1967 %!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
|
1968 %!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
|
1969 %!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
|
1970 %!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
|
1971 %!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
|
1972 %!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
|
1973 %!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
|
1974 %!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
|
1975 %!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
|
1976 %!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
|
1977 %!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
|
1978 %!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
|
1979 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1980 %!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
|
1981 %!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
|
1982 %!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
|
1983 %!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
|
1984 %!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
|
1985 %!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
|
1986 %!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
|
1987 %!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
|
1988 %!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
|
1989 %!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
|
1990 %!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
|
1991 %!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
|
1992 %!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
|
1993 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
1994 %!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
|
1995 %!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
|
1996 %!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
|
1997 %!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
|
1998 %!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
|
1999 %!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
|
2000 %!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
|
2001 %!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
|
2002 %!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
|
2003 %!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
|
2004 %!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
|
2005 %!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
|
2006 %!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
|
2007 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2008 %!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
|
2009 %!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
|
2010 %!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
|
2011 %!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
|
2012 %!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
|
2013 %!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
|
2014 %!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
|
2015 %!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
|
2016 %!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
|
2017 %!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
|
2018 %!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
|
2019 %!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
|
2020 %!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
|
2021 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2022 %!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
|
2023 %!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
|
2024 %!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
|
2025 %!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
|
2026 %!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
|
2027 %!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
|
2028 %!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
|
2029 %!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
|
2030 %!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
|
2031 %!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
|
2032 %!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
|
2033 %!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
|
2034 %!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
|
2035 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2036 %!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
|
2037 %!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
|
2038 %!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
|
2039 %!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
|
2040 %!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
|
2041 %!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
|
2042 %!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
|
2043 %!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
|
2044 %!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
|
2045 %!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
|
2046 %!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
|
2047 %!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
|
2048 %!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
|
2049 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2050 %!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
|
2051 %!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
|
2052 %!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
|
2053 %!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
|
2054 %!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
|
2055 %!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
|
2056 %!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
|
2057 %!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
|
2058 %!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
|
2059 %!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
|
2060 %!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
|
2061 %!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
|
2062 %!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
|
2063 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2064 %!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
|
2065 %!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
|
2066 %!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
|
2067 %!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
|
2068 %!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
|
2069 %!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
|
2070 %!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
|
2071 %!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
|
2072 %!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
|
2073 %!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
|
2074 %!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
|
2075 %!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
|
2076 %!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
|
2077 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2078 %!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
|
2079 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2080 %!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
|
2081 */ |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
2082 |
4806 | 2083 DEFUN (vertcat, args, , |
2084 "-*- texinfo -*-\n\ | |
2085 @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
|
2086 Return the vertical concatenation of N-D array objects, @var{array1},\n\ |
4806 | 2087 @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
|
2088 \n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
2089 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
|
2090 new matrices. For example:\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
2091 \n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
2092 @example\n\ |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
2093 @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
|
2094 @end example\n\ |
5642 | 2095 @seealso{cat, horzcat}\n\ |
2096 @end deftypefn") | |
4806 | 2097 { |
10716
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2098 return do_cat (args, -1, "vertcat"); |
4806 | 2099 } |
2100 | |
13294
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
2101 /* |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
2102 %!test |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2103 %! c = {"foo"; "bar"; "bazoloa"}; |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2104 %! 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
|
2105 */ |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13029
diff
changeset
|
2106 |
4758 | 2107 DEFUN (cat, args, , |
2108 "-*- texinfo -*-\n\ | |
2109 @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
|
2110 Return the concatenation of N-D array objects, @var{array1},\n\ |
4806 | 2111 @var{array2}, @dots{}, @var{arrayN} along dimension @var{dim}.\n\ |
4758 | 2112 \n\ |
2113 @example\n\ | |
2114 @group\n\ | |
2115 A = ones (2, 2);\n\ | |
2116 B = zeros (2, 2);\n\ | |
2117 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
|
2118 @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
|
2119 1 1 0 0\n\ |
4758 | 2120 @end group\n\ |
2121 @end example\n\ | |
2122 \n\ | |
2123 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
|
2124 second dimension in the following way:\n\ |
4758 | 2125 \n\ |
2126 @example\n\ | |
2127 @group\n\ | |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
2128 [A, B]\n\ |
4758 | 2129 @end group\n\ |
2130 @end example\n\ | |
2131 \n\ | |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
2132 @var{dim} can be larger than the dimensions of the N-D array objects\n\ |
4758 | 2133 and the result will thus have @var{dim} dimensions as the\n\ |
2134 following example shows:\n\ | |
10840 | 2135 \n\ |
4758 | 2136 @example\n\ |
2137 @group\n\ | |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
2138 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
|
2139 @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
|
2140 \n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
2141 1 1\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
2142 1 1\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
2143 \n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
2144 ans(:,:,1,2) =\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
2145 \n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
2146 0 0\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
2147 0 0\n\ |
4758 | 2148 @end group\n\ |
2149 @end example\n\ | |
5642 | 2150 @seealso{horzcat, vertcat}\n\ |
2151 @end deftypefn") | |
4758 | 2152 { |
10716
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2153 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
|
2154 |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2155 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
|
2156 { |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2157 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
|
2158 |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2159 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
|
2160 { |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2161 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
|
2162 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
|
2163 else |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11591
diff
changeset
|
2164 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
|
2165 } |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2166 else |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11591
diff
changeset
|
2167 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
|
2168 } |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2169 else |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2170 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
|
2171 |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
2172 return retval; |
4758 | 2173 } |
2174 | |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
2175 /* |
14085
4e8f23ccadce
test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents:
14022
diff
changeset
|
2176 %!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
|
2177 %! assert (cat (1, cast ([], t1), cast ([], t2)), cast ([], tr)); |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2178 %! |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2179 %! 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
|
2180 %! 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
|
2181 %! 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
|
2182 %! 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
|
2183 %! 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
|
2184 %! 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
|
2185 %! 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
|
2186 %! assert (cat (2, 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
|
2187 %! |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2188 %! 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
|
2189 %! 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
|
2190 %! 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
|
2191 %! 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
|
2192 %! 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
|
2193 %! 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
|
2194 %! 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
|
2195 %! 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
|
2196 %! |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2197 %! if (nargin == 3 || cmplx) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2198 %! 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
|
2199 %! 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
|
2200 %! 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
|
2201 %! 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
|
2202 %! 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
|
2203 %! 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
|
2204 %! 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
|
2205 %! assert (cat (2, 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
|
2206 %! |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2207 %! 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
|
2208 %! 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
|
2209 %! 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
|
2210 %! 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
|
2211 %! 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
|
2212 %! 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
|
2213 %! 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
|
2214 %! 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
|
2215 %! |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2216 %! 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
|
2217 %! 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
|
2218 %! 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
|
2219 %! 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
|
2220 %! 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
|
2221 %! 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
|
2222 %! 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
|
2223 %! assert (cat (2, 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
|
2224 %! |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2225 %! 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
|
2226 %! 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
|
2227 %! 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
|
2228 %! 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
|
2229 %! 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
|
2230 %! 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
|
2231 %! 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
|
2232 %! 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
|
2233 %! |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2234 %! 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
|
2235 %! 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
|
2236 %! 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
|
2237 %! 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
|
2238 %! 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
|
2239 %! 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
|
2240 %! 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
|
2241 %! assert (cat (2, 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
|
2242 %! |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2243 %! 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
|
2244 %! 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
|
2245 %! 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
|
2246 %! 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
|
2247 %! 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
|
2248 %! 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
|
2249 %! 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
|
2250 %! 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
|
2251 %! endif |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2252 %! ret = true; |
14085
4e8f23ccadce
test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents:
14022
diff
changeset
|
2253 %!endfunction |
4e8f23ccadce
test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents:
14022
diff
changeset
|
2254 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2255 %!assert (__testcat ("double", "double", "double")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2256 %!assert (__testcat ("single", "double", "single")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2257 %!assert (__testcat ("double", "single", "single")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2258 %!assert (__testcat ("single", "single", "single")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2259 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2260 %!assert (__testcat ("double", "int8", "int8", false)) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2261 %!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
|
2262 %!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
|
2263 %!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
|
2264 %!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
|
2265 %!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
|
2266 %!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
|
2267 %!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
|
2268 %!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
|
2269 %!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
|
2270 %!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
|
2271 %!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
|
2272 %!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
|
2273 %!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
|
2274 %!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
|
2275 %!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
|
2276 %!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
|
2277 %!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
|
2278 %!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
|
2279 %!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
|
2280 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2281 %!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
|
2282 %!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
|
2283 %!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
|
2284 %!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
|
2285 %!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
|
2286 %!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
|
2287 %!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
|
2288 %!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
|
2289 %!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
|
2290 %!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
|
2291 %!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
|
2292 %!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
|
2293 %!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
|
2294 %!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
|
2295 %!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
|
2296 %!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
|
2297 %!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
|
2298 %!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
|
2299 %!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
|
2300 %!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
|
2301 |
4e8f23ccadce
test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents:
14022
diff
changeset
|
2302 %!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
|
2303 %!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
|
2304 %!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
|
2305 %!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
|
2306 |
4e8f23ccadce
test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents:
14022
diff
changeset
|
2307 %!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
|
2308 %!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
|
2309 %!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
|
2310 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2311 %!assert ([zeros(3,2,2); ones(1,2,2)], repmat ([0;0;0;1],[1,2,2]) ) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2312 %!assert ([zeros(3,2,2); ones(1,2,2)], vertcat (zeros (3,2,2), ones (1,2,2)) ) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2313 |
14085
4e8f23ccadce
test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents:
14022
diff
changeset
|
2314 %!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
|
2315 %!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
|
2316 */ |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
2317 |
4593 | 2318 static octave_value |
6959 | 2319 do_permute (const octave_value_list& args, bool inv) |
4593 | 2320 { |
2321 octave_value retval; | |
2322 | |
5148 | 2323 if (args.length () == 2 && args(1).length () >= args(1).ndims ()) |
4593 | 2324 { |
2325 Array<int> vec = args(1).int_vector_value (); | |
2326 | |
5775 | 2327 // FIXME -- maybe we should create an idx_vector object |
5148 | 2328 // here and pass that to permute? |
2329 | |
2330 int n = vec.length (); | |
2331 | |
2332 for (int i = 0; i < n; i++) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2333 vec(i)--; |
5148 | 2334 |
4593 | 2335 octave_value ret = args(0).permute (vec, inv); |
2336 | |
2337 if (! error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2338 retval = ret; |
4593 | 2339 } |
2340 else | |
5823 | 2341 print_usage (); |
4593 | 2342 |
2343 return retval; | |
2344 } | |
2345 | |
2346 DEFUN (permute, args, , | |
2347 "-*- texinfo -*-\n\ | |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
2348 @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
|
2349 Return the generalized transpose for an N-D array object @var{A}.\n\ |
4593 | 2350 The permutation vector @var{perm} must contain the elements\n\ |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14853
diff
changeset
|
2351 @code{1:ndims (A)} (in any order, but each element must appear only once).\n\ |
5642 | 2352 @seealso{ipermute}\n\ |
2353 @end deftypefn") | |
4593 | 2354 { |
6959 | 2355 return do_permute (args, false); |
4593 | 2356 } |
2357 | |
2358 DEFUN (ipermute, args, , | |
2359 "-*- texinfo -*-\n\ | |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
2360 @deftypefn {Built-in Function} {} ipermute (@var{A}, @var{iperm})\n\ |
4593 | 2361 The inverse of the @code{permute} function. The expression\n\ |
2362 \n\ | |
2363 @example\n\ | |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
2364 ipermute (permute (A, perm), perm)\n\ |
4593 | 2365 @end example\n\ |
10840 | 2366 \n\ |
10846
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10840
diff
changeset
|
2367 @noindent\n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
2368 returns the original array @var{A}.\n\ |
5642 | 2369 @seealso{permute}\n\ |
2370 @end deftypefn") | |
4593 | 2371 { |
6959 | 2372 return do_permute (args, true); |
4593 | 2373 } |
2374 | |
3195 | 2375 DEFUN (length, args, , |
3373 | 2376 "-*- texinfo -*-\n\ |
2377 @deftypefn {Built-in Function} {} length (@var{a})\n\ | |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
2378 Return the \"length\" of the object @var{a}. For matrix objects, the\n\ |
3373 | 2379 length is the number of rows or columns, whichever is greater (this\n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
9041
diff
changeset
|
2380 odd definition is used 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
|
2381 @seealso{size}\n\ |
3373 | 2382 @end deftypefn") |
3195 | 2383 { |
2384 octave_value retval; | |
2385 | |
2386 if (args.length () == 1) | |
9706
71160b139b07
simplify length,ndims,size and size_equal
Jaroslav Hajek <highegg@gmail.com>
parents:
9705
diff
changeset
|
2387 retval = args(0).length (); |
3195 | 2388 else |
5823 | 2389 print_usage (); |
3195 | 2390 |
2391 return retval; | |
2392 } | |
2393 | |
4554 | 2394 DEFUN (ndims, args, , |
2395 "-*- texinfo -*-\n\ | |
2396 @deftypefn {Built-in Function} {} ndims (@var{a})\n\ | |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
2397 Return the number of dimensions of @var{a}.\n\ |
4554 | 2398 For any array, the result will always be larger than or equal to 2.\n\ |
2399 Trailing singleton dimensions are not counted.\n\ | |
10840 | 2400 \n\ |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
2401 @example\n\ |
10711
fbd7843974fa
Periodic grammar check of documentation files to ensure common format.
Rik <octave@nomad.inbox5.com>
parents:
10707
diff
changeset
|
2402 @group\n\ |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
2403 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
|
2404 @result{} 3\n\ |
10711
fbd7843974fa
Periodic grammar check of documentation files to ensure common format.
Rik <octave@nomad.inbox5.com>
parents:
10707
diff
changeset
|
2405 @end group\n\ |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
2406 @end example\n\ |
15028
397f0d80bd47
Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents:
15024
diff
changeset
|
2407 @seealso{size}\n\ |
4554 | 2408 @end deftypefn") |
2409 { | |
2410 octave_value retval; | |
2411 | |
2412 if (args.length () == 1) | |
9706
71160b139b07
simplify length,ndims,size and size_equal
Jaroslav Hajek <highegg@gmail.com>
parents:
9705
diff
changeset
|
2413 retval = args(0).ndims (); |
4554 | 2414 else |
5823 | 2415 print_usage (); |
4554 | 2416 |
2417 return retval; | |
2418 } | |
2419 | |
4559 | 2420 DEFUN (numel, args, , |
2421 "-*- texinfo -*-\n\ | |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
2422 @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
|
2423 @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
|
2424 Return the number of elements in the object @var{a}.\n\ |
9705
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
2425 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
|
2426 return the number of elements that would result from the indexing\n\ |
10840 | 2427 \n\ |
9705
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
2428 @example\n\ |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
2429 @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
|
2430 @end example\n\ |
10840 | 2431 \n\ |
13929
9cae456085c2
Grammarcheck of documentation before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
2432 Note that the indices do not have to be numerical. For example,\n\ |
12924
67a5acac8e1b
Clarify what indices can be for numel
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12681
diff
changeset
|
2433 \n\ |
67a5acac8e1b
Clarify what indices can be for numel
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12681
diff
changeset
|
2434 @example\n\ |
13929
9cae456085c2
Grammarcheck of documentation before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
2435 @group\n\ |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
2436 @var{a} = 1;\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
2437 @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
|
2438 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
|
2439 @end group\n\ |
12924
67a5acac8e1b
Clarify what indices can be for numel
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12681
diff
changeset
|
2440 @end example\n\ |
67a5acac8e1b
Clarify what indices can be for numel
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12681
diff
changeset
|
2441 \n\ |
13929
9cae456085c2
Grammarcheck of documentation before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
13915
diff
changeset
|
2442 @noindent\n\ |
12924
67a5acac8e1b
Clarify what indices can be for numel
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12681
diff
changeset
|
2443 will return 6, as this is the number of ways to index with @var{b}.\n\ |
67a5acac8e1b
Clarify what indices can be for numel
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12681
diff
changeset
|
2444 \n\ |
9705
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
2445 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
|
2446 indexing, i.e., @code{object@{@dots{}@}} or @code{object(@dots{}).field}.\n\ |
5724 | 2447 @seealso{size}\n\ |
4559 | 2448 @end deftypefn") |
2449 { | |
2450 octave_value retval; | |
9329
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9319
diff
changeset
|
2451 octave_idx_type nargin = args.length (); |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9319
diff
changeset
|
2452 |
9705
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
2453 if (nargin == 1) |
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
2454 retval = args(0).numel (); |
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
2455 else if (nargin > 1) |
4559 | 2456 { |
9705
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
2457 // 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
|
2458 // an overloaded call, not to builtin! |
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
2459 retval = dims_to_numel (args(0).dims (), args.slice (1, nargin-1)); |
4559 | 2460 } |
2461 else | |
5823 | 2462 print_usage (); |
4559 | 2463 |
2464 return retval; | |
2465 } | |
2466 | |
1957 | 2467 DEFUN (size, args, nargout, |
3373 | 2468 "-*- texinfo -*-\n\ |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
2469 @deftypefn {Built-in Function} {} size (@var{a})\n\ |
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
2470 @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
|
2471 Return the number of rows and columns of @var{a}.\n\ |
3373 | 2472 \n\ |
2473 With one input argument and one output argument, the result is returned\n\ | |
4741 | 2474 in a row vector. If there are multiple output arguments, the number of\n\ |
2475 rows is assigned to the first, and the number of columns to the second,\n\ | |
10840 | 2476 etc. For example:\n\ |
3373 | 2477 \n\ |
2478 @example\n\ | |
2479 @group\n\ | |
2480 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
|
2481 @result{} [ 3, 2 ]\n\ |
1031 | 2482 \n\ |
3373 | 2483 [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
|
2484 @result{} nr = 3\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
2485 @result{} nc = 2\n\ |
3373 | 2486 @end group\n\ |
2487 @end example\n\ | |
2488 \n\ | |
4741 | 2489 If given a second argument, @code{size} will return the size of the\n\ |
10840 | 2490 corresponding dimension. For example,\n\ |
1031 | 2491 \n\ |
3373 | 2492 @example\n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
9041
diff
changeset
|
2493 @group\n\ |
3373 | 2494 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
|
2495 @result{} 2\n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
9041
diff
changeset
|
2496 @end group\n\ |
3373 | 2497 @end example\n\ |
2498 \n\ | |
2499 @noindent\n\ | |
2500 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
|
2501 @seealso{numel, ndims, length, rows, columns}\n\ |
3373 | 2502 @end deftypefn") |
523 | 2503 { |
2086 | 2504 octave_value_list retval; |
523 | 2505 |
2506 int nargin = args.length (); | |
2507 | |
4513 | 2508 if (nargin == 1) |
523 | 2509 { |
9706
71160b139b07
simplify length,ndims,size and size_equal
Jaroslav Hajek <highegg@gmail.com>
parents:
9705
diff
changeset
|
2510 const dim_vector dimensions = args(0).dims (); |
4513 | 2511 |
2512 if (nargout > 1) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2513 { |
9706
71160b139b07
simplify length,ndims,size and size_equal
Jaroslav Hajek <highegg@gmail.com>
parents:
9705
diff
changeset
|
2514 const dim_vector rdims = dimensions.redim (nargout); |
71160b139b07
simplify length,ndims,size and size_equal
Jaroslav Hajek <highegg@gmail.com>
parents:
9705
diff
changeset
|
2515 retval.resize (nargout); |
71160b139b07
simplify length,ndims,size and size_equal
Jaroslav Hajek <highegg@gmail.com>
parents:
9705
diff
changeset
|
2516 for (int i = 0; i < nargout; i++) |
71160b139b07
simplify length,ndims,size and size_equal
Jaroslav Hajek <highegg@gmail.com>
parents:
9705
diff
changeset
|
2517 retval(i) = rdims(i); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2518 } |
4513 | 2519 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2520 { |
9706
71160b139b07
simplify length,ndims,size and size_equal
Jaroslav Hajek <highegg@gmail.com>
parents:
9705
diff
changeset
|
2521 int ndims = dimensions.length (); |
71160b139b07
simplify length,ndims,size and size_equal
Jaroslav Hajek <highegg@gmail.com>
parents:
9705
diff
changeset
|
2522 |
71160b139b07
simplify length,ndims,size and size_equal
Jaroslav Hajek <highegg@gmail.com>
parents:
9705
diff
changeset
|
2523 NoAlias<Matrix> m (1, ndims); |
71160b139b07
simplify length,ndims,size and size_equal
Jaroslav Hajek <highegg@gmail.com>
parents:
9705
diff
changeset
|
2524 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2525 for (int i = 0; i < ndims; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2526 m(i) = dimensions(i); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2527 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2528 retval(0) = m; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2529 } |
1031 | 2530 } |
2531 else if (nargin == 2 && nargout < 2) | |
2532 { | |
5275 | 2533 octave_idx_type nd = args(1).int_value (true); |
1031 | 2534 |
2535 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
|
2536 error ("size: DIM must be a scalar"); |
712 | 2537 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2538 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2539 const dim_vector dv = args(0).dims (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2540 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2541 if (nd > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2542 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2543 if (nd <= dv.length ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2544 retval(0) = dv(nd-1); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
2545 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2546 retval(0) = 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2547 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2548 else |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11591
diff
changeset
|
2549 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
|
2550 } |
523 | 2551 } |
712 | 2552 else |
5823 | 2553 print_usage (); |
523 | 2554 |
2555 return retval; | |
2556 } | |
2557 | |
6156 | 2558 DEFUN (size_equal, args, , |
2559 "-*- texinfo -*-\n\ | |
6561 | 2560 @deftypefn {Built-in Function} {} size_equal (@var{a}, @var{b}, @dots{})\n\ |
2561 Return true if the dimensions of all arguments agree.\n\ | |
6156 | 2562 Trailing singleton dimensions are ignored.\n\ |
10002
e93c9bfff8b8
allow size_equal with 0 arguments
Jaroslav Hajek <highegg@gmail.com>
parents:
9866
diff
changeset
|
2563 Called with a single or no argument, size_equal returns true.\n\ |
15028
397f0d80bd47
Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents:
15024
diff
changeset
|
2564 @seealso{size, numel, ndims}\n\ |
6156 | 2565 @end deftypefn") |
2566 { | |
2567 octave_value retval; | |
2568 | |
6561 | 2569 int nargin = args.length (); |
2570 | |
10002
e93c9bfff8b8
allow size_equal with 0 arguments
Jaroslav Hajek <highegg@gmail.com>
parents:
9866
diff
changeset
|
2571 retval = true; |
e93c9bfff8b8
allow size_equal with 0 arguments
Jaroslav Hajek <highegg@gmail.com>
parents:
9866
diff
changeset
|
2572 |
8947
1e4b3149365a
allow size_equal called with 1 arg
Jaroslav Hajek <highegg@gmail.com>
parents:
8934
diff
changeset
|
2573 if (nargin >= 1) |
6156 | 2574 { |
2575 dim_vector a_dims = args(0).dims (); | |
6561 | 2576 |
2577 for (int i = 1; i < nargin; ++i) | |
2578 { | |
2579 dim_vector b_dims = args(i).dims (); | |
2580 | |
2581 if (a_dims != b_dims) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2582 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2583 retval = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2584 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2585 } |
6561 | 2586 } |
6156 | 2587 } |
2588 | |
2589 return retval; | |
2590 } | |
2591 | |
5602 | 2592 DEFUN (nnz, args, , |
2593 "-*- texinfo -*-\n\ | |
6156 | 2594 @deftypefn {Built-in Function} {@var{scalar} =} nnz (@var{a})\n\ |
11572
7d6d8c1e471f
Grammarcheck Texinfo for files in src directory.
Rik <octave@nomad.inbox5.com>
parents:
11570
diff
changeset
|
2595 Return the number of non zero elements in @var{a}.\n\ |
15028
397f0d80bd47
Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents:
15024
diff
changeset
|
2596 @seealso{sparse, nzmax}\n\ |
5602 | 2597 @end deftypefn") |
2598 { | |
2599 octave_value retval; | |
2600 | |
2601 if (args.length () == 1) | |
2602 retval = args(0).nnz (); | |
2603 else | |
5823 | 2604 print_usage (); |
5602 | 2605 |
2606 return retval; | |
2607 } | |
2608 | |
5604 | 2609 DEFUN (nzmax, args, , |
2610 "-*- texinfo -*-\n\ | |
6156 | 2611 @deftypefn {Built-in Function} {@var{scalar} =} nzmax (@var{SM})\n\ |
5604 | 2612 Return the amount of storage allocated to the sparse matrix @var{SM}.\n\ |
7001 | 2613 Note that Octave tends to crop unused memory at the first opportunity\n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
9041
diff
changeset
|
2614 for sparse objects. There are some cases of user created sparse objects\n\ |
9066
be150a172010
Cleanup documentation for diagperm.texi, sparse.texi
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
2615 where the value returned by @dfn{nzmax} will not be the same as @dfn{nnz},\n\ |
5604 | 2616 but in general they will give the same result.\n\ |
15034
1116864ee270
doc: Fix for bad cross-referencing due to use of aliases in Texinfo.
Rik <rik@octave.org>
parents:
15031
diff
changeset
|
2617 @seealso{nnz, spalloc, sparse}\n\ |
5604 | 2618 @end deftypefn") |
2619 { | |
2620 octave_value retval; | |
2621 | |
14843
7d4f87c75dbb
data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents:
14635
diff
changeset
|
2622 if (args.length () == 1) |
5604 | 2623 retval = args(0).nzmax (); |
2624 else | |
5823 | 2625 print_usage (); |
5604 | 2626 |
2627 return retval; | |
2628 } | |
2629 | |
5677 | 2630 DEFUN (rows, args, , |
2631 "-*- texinfo -*-\n\ | |
2632 @deftypefn {Built-in Function} {} rows (@var{a})\n\ | |
2633 Return the number of rows of @var{a}.\n\ | |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
2634 @seealso{columns, size, length, numel, isscalar, isvector, ismatrix}\n\ |
5677 | 2635 @end deftypefn") |
2636 { | |
2637 octave_value retval; | |
2638 | |
2639 if (args.length () == 1) | |
2640 retval = args(0).rows (); | |
2641 else | |
5823 | 2642 print_usage (); |
5677 | 2643 |
2644 return retval; | |
2645 } | |
2646 | |
2647 DEFUN (columns, args, , | |
2648 "-*- texinfo -*-\n\ | |
2649 @deftypefn {Built-in Function} {} columns (@var{a})\n\ | |
2650 Return the number of columns of @var{a}.\n\ | |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
2651 @seealso{rows, size, length, numel, isscalar, isvector, ismatrix}\n\ |
5677 | 2652 @end deftypefn") |
2653 { | |
2654 octave_value retval; | |
2655 | |
2656 if (args.length () == 1) | |
2657 retval = args(0).columns (); | |
2658 else | |
5823 | 2659 print_usage (); |
5677 | 2660 |
2661 return retval; | |
2662 } | |
2663 | |
1957 | 2664 DEFUN (sum, args, , |
3428 | 2665 "-*- texinfo -*-\n\ |
9163
9cb0c21e97f7
Update section 17.4 (Sums and Products) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9155
diff
changeset
|
2666 @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
|
2667 @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
|
2668 @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
|
2669 @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
|
2670 @deftypefnx {Built-in Function} {} sum (@dots{}, \"extra\")\n\ |
3723 | 2671 Sum of elements along dimension @var{dim}. If @var{dim} is\n\ |
9723
f426899f4b9c
fix reduction functions docstrings
Jaroslav Hajek <highegg@gmail.com>
parents:
9721
diff
changeset
|
2672 omitted, it defaults to the first non-singleton dimension.\n\ |
7112 | 2673 \n\ |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
2674 If the optional argument \"native\" is given, then the sum is performed\n\ |
7112 | 2675 in the same type as the original argument, rather than in the default\n\ |
10840 | 2676 double type. For example:\n\ |
7112 | 2677 \n\ |
2678 @example\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
9041
diff
changeset
|
2679 @group\n\ |
7112 | 2680 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
|
2681 @result{} 2\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
2682 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
|
2683 @result{} true\n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
9041
diff
changeset
|
2684 @end group\n\ |
7112 | 2685 @end example\n\ |
10840 | 2686 \n\ |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
2687 On the contrary, if \"double\" is given, the sum is performed in double\n\ |
10846
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10840
diff
changeset
|
2688 precision even for single precision inputs.\n\ |
9723
f426899f4b9c
fix reduction functions docstrings
Jaroslav Hajek <highegg@gmail.com>
parents:
9721
diff
changeset
|
2689 \n\ |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
2690 For double precision inputs, \"extra\" indicates that a more accurate\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
2691 algorithm than straightforward summation is to be used. For single precision\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
2692 inputs, \"extra\" is the same as \"double\". Otherwise, \"extra\" has no\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
2693 effect.\n\ |
9163
9cb0c21e97f7
Update section 17.4 (Sums and Products) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9155
diff
changeset
|
2694 @seealso{cumsum, sumsq, prod}\n\ |
3428 | 2695 @end deftypefn") |
523 | 2696 { |
9721
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2697 octave_value retval; |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2698 |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2699 int nargin = args.length (); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2700 |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2701 bool isnative = false; |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2702 bool isdouble = false; |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2703 bool isextra = false; |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2704 |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2705 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
|
2706 { |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2707 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
|
2708 |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2709 if (! error_state) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2710 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2711 if (str == "native") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2712 isnative = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2713 else if (str == "double") |
9721
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2714 isdouble = true; |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2715 else if (str == "extra") |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2716 isextra = true; |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2717 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2718 error ("sum: unrecognized string argument"); |
9721
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2719 nargin --; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2720 } |
9721
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2721 } |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2722 |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2723 if (error_state) |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2724 return retval; |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2725 |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2726 if (nargin == 1 || nargin == 2) |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2727 { |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2728 octave_value arg = args(0); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2729 |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2730 int dim = -1; |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2731 if (nargin == 2) |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2732 { |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2733 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
|
2734 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
|
2735 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
|
2736 } |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2737 |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2738 if (! error_state) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2739 { |
9721
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2740 switch (arg.builtin_type ()) |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2741 { |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2742 case btyp_double: |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2743 if (arg.is_sparse_type ()) |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2744 { |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2745 if (isextra) |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2746 warning ("sum: 'extra' not yet implemented for sparse matrices"); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2747 retval = arg.sparse_matrix_value ().sum (dim); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2748 } |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2749 else if (isextra) |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2750 retval = arg.array_value ().xsum (dim); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2751 else |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2752 retval = arg.array_value ().sum (dim); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2753 break; |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2754 case btyp_complex: |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2755 if (arg.is_sparse_type ()) |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2756 { |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2757 if (isextra) |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2758 warning ("sum: 'extra' not yet implemented for sparse matrices"); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2759 retval = arg.sparse_complex_matrix_value ().sum (dim); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2760 } |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2761 else if (isextra) |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2762 retval = arg.complex_array_value ().xsum (dim); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2763 else |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2764 retval = arg.complex_array_value ().sum (dim); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2765 break; |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2766 case btyp_float: |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2767 if (isdouble || isextra) |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2768 retval = arg.float_array_value ().dsum (dim); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2769 else |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2770 retval = arg.float_array_value ().sum (dim); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2771 break; |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2772 case btyp_float_complex: |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2773 if (isdouble || isextra) |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2774 retval = arg.float_complex_array_value ().dsum (dim); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2775 else |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2776 retval = arg.float_complex_array_value ().sum (dim); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2777 break; |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2778 |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2779 #define MAKE_INT_BRANCH(X) \ |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2780 case btyp_ ## X: \ |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2781 if (isnative) \ |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2782 retval = arg.X ## _array_value ().sum (dim); \ |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2783 else \ |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2784 retval = arg.X ## _array_value ().dsum (dim); \ |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2785 break |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2786 MAKE_INT_BRANCH (int8); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2787 MAKE_INT_BRANCH (int16); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2788 MAKE_INT_BRANCH (int32); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2789 MAKE_INT_BRANCH (int64); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2790 MAKE_INT_BRANCH (uint8); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2791 MAKE_INT_BRANCH (uint16); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2792 MAKE_INT_BRANCH (uint32); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2793 MAKE_INT_BRANCH (uint64); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2794 #undef MAKE_INT_BRANCH |
15621
e9d842dcfc91
*data.cc (Fsum): allow string arguments for Matlab compatibility
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15509
diff
changeset
|
2795 // GAGME: Accursed Matlab compatibility... |
e9d842dcfc91
*data.cc (Fsum): allow string arguments for Matlab compatibility
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15509
diff
changeset
|
2796 case btyp_char: |
e9d842dcfc91
*data.cc (Fsum): allow string arguments for Matlab compatibility
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15509
diff
changeset
|
2797 if (isextra) |
e9d842dcfc91
*data.cc (Fsum): allow string arguments for Matlab compatibility
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15509
diff
changeset
|
2798 retval = arg.array_value (true).xsum (dim); |
e9d842dcfc91
*data.cc (Fsum): allow string arguments for Matlab compatibility
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15509
diff
changeset
|
2799 else |
e9d842dcfc91
*data.cc (Fsum): allow string arguments for Matlab compatibility
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15509
diff
changeset
|
2800 retval = arg.array_value (true).sum (dim); |
e9d842dcfc91
*data.cc (Fsum): allow string arguments for Matlab compatibility
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15509
diff
changeset
|
2801 break; |
9721
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2802 case btyp_bool: |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2803 if (arg.is_sparse_type ()) |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2804 { |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2805 if (isnative) |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2806 retval = arg.sparse_bool_matrix_value ().any (dim); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2807 else |
10983
4b51c0a20a98
optimize sum of sparse logical matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10880
diff
changeset
|
2808 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
|
2809 } |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2810 else if (isnative) |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2811 retval = arg.bool_array_value ().any (dim); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2812 else |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2813 retval = arg.bool_array_value ().sum (dim); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2814 break; |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2815 |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2816 default: |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2817 gripe_wrong_type_arg ("sum", arg); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2818 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2819 } |
9721
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2820 } |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2821 else |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2822 print_usage (); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2823 |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2824 return retval; |
523 | 2825 } |
2826 | |
7112 | 2827 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2828 %!assert (sum ([true,true]), 2) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2829 %!assert (sum ([true,true],"native"), true) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2830 %!assert (sum (int8 ([127,10,-20])), 117) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2831 %!assert (sum (int8 ([127,10,-20]),'native'), int8 (107)) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2832 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2833 %!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
|
2834 %!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
|
2835 %!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
|
2836 %!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
|
2837 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2838 %!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
|
2839 %!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
|
2840 %!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
|
2841 %!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
|
2842 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2843 %!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
|
2844 %!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
|
2845 %!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
|
2846 %!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
|
2847 %!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
|
2848 %!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
|
2849 %!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
|
2850 %!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
|
2851 %!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
|
2852 %!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
|
2853 %!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
|
2854 %!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
|
2855 %!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
|
2856 %!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
|
2857 %!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
|
2858 %!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
|
2859 %!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
|
2860 %!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
|
2861 %!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
|
2862 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2863 %!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
|
2864 %!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
|
2865 %!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
|
2866 %!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
|
2867 %!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
|
2868 %!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
|
2869 %!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
|
2870 %!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
|
2871 %!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
|
2872 %!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
|
2873 %!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
|
2874 %!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
|
2875 %!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
|
2876 %!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
|
2877 %!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
|
2878 %!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
|
2879 %!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
|
2880 %!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
|
2881 %!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
|
2882 |
15623
d928ad126b66
maint: add a new test for Fsum corresponding to cset e9d842dcfc91
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15621
diff
changeset
|
2883 ;-) |
d928ad126b66
maint: add a new test for Fsum corresponding to cset e9d842dcfc91
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
15621
diff
changeset
|
2884 %!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
|
2885 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2886 %!error sum () |
7112 | 2887 */ |
2888 | |
1957 | 2889 DEFUN (sumsq, args, , |
3428 | 2890 "-*- texinfo -*-\n\ |
9163
9cb0c21e97f7
Update section 17.4 (Sums and Products) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9155
diff
changeset
|
2891 @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
|
2892 @deftypefnx {Built-in Function} {} sumsq (@var{x}, @var{dim})\n\ |
3723 | 2893 Sum of squares of elements along dimension @var{dim}. If @var{dim}\n\ |
9723
f426899f4b9c
fix reduction functions docstrings
Jaroslav Hajek <highegg@gmail.com>
parents:
9721
diff
changeset
|
2894 is omitted, it defaults to the first non-singleton dimension.\n\ |
5061 | 2895 \n\ |
2896 This function is conceptually equivalent to computing\n\ | |
10840 | 2897 \n\ |
3723 | 2898 @example\n\ |
2899 sum (x .* conj (x), dim)\n\ | |
2900 @end example\n\ | |
10840 | 2901 \n\ |
10846
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10840
diff
changeset
|
2902 @noindent\n\ |
9163
9cb0c21e97f7
Update section 17.4 (Sums and Products) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9155
diff
changeset
|
2903 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
|
2904 @seealso{sum, prod}\n\ |
3428 | 2905 @end deftypefn") |
523 | 2906 { |
3723 | 2907 DATA_REDUCTION (sumsq); |
523 | 2908 } |
2909 | |
7815
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2910 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2911 %!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
|
2912 %!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
|
2913 %!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
|
2914 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2915 %!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
|
2916 %!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
|
2917 %!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
|
2918 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2919 %!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
|
2920 %!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
|
2921 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2922 %!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
|
2923 %!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
|
2924 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2925 %!error sumsq () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2926 */ |
7815
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2927 |
6688 | 2928 DEFUN (islogical, args, , |
3428 | 2929 "-*- texinfo -*-\n\ |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11422
diff
changeset
|
2930 @deftypefn {Built-in Function} {} islogical (@var{x})\n\ |
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11422
diff
changeset
|
2931 @deftypefnx {Built-in Function} {} isbool (@var{x})\n\ |
6688 | 2932 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
|
2933 @seealso{isfloat, isinteger, ischar, isnumeric, isa}\n\ |
3439 | 2934 @end deftypefn") |
3209 | 2935 { |
2936 octave_value retval; | |
2937 | |
2938 if (args.length () == 1) | |
3258 | 2939 retval = args(0).is_bool_type (); |
3209 | 2940 else |
5823 | 2941 print_usage (); |
3209 | 2942 |
2943 return retval; | |
2944 } | |
2945 | |
6688 | 2946 DEFALIAS (isbool, islogical); |
3209 | 2947 |
7815
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2948 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2949 %!assert (islogical (true), true) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2950 %!assert (islogical (false), true) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2951 %!assert (islogical ([true, false]), true) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2952 %!assert (islogical (1), false) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2953 %!assert (islogical (1i), false) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2954 %!assert (islogical ([1,1]), false) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2955 %!assert (islogical (single (1)), false) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2956 %!assert (islogical (single (1i)), false) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
2957 %!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
|
2958 %!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
|
2959 %!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
|
2960 */ |
7815
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2961 |
6223 | 2962 DEFUN (isinteger, args, , |
2963 "-*- texinfo -*-\n\ | |
6230 | 2964 @deftypefn {Built-in Function} {} isinteger (@var{x})\n\ |
6223 | 2965 Return true if @var{x} is an integer object (int8, uint8, int16, etc.).\n\ |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11422
diff
changeset
|
2966 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
|
2967 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
|
2968 @seealso{isfloat, ischar, islogical, isnumeric, isa}\n\ |
6223 | 2969 @end deftypefn") |
2970 { | |
2971 octave_value retval; | |
2972 | |
2973 if (args.length () == 1) | |
2974 retval = args(0).is_integer_type (); | |
2975 else | |
2976 print_usage (); | |
2977 | |
2978 return retval; | |
2979 } | |
2980 | |
4028 | 2981 DEFUN (iscomplex, args, , |
3428 | 2982 "-*- texinfo -*-\n\ |
4028 | 2983 @deftypefn {Built-in Function} {} iscomplex (@var{x})\n\ |
3428 | 2984 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
|
2985 @seealso{isreal, isnumeric, islogical, ischar, isfloat, isa}\n\ |
3428 | 2986 @end deftypefn") |
3186 | 2987 { |
2988 octave_value retval; | |
2989 | |
2990 if (args.length () == 1) | |
3258 | 2991 retval = args(0).is_complex_type (); |
3186 | 2992 else |
5823 | 2993 print_usage (); |
3186 | 2994 |
2995 return retval; | |
2996 } | |
2997 | |
7576 | 2998 DEFUN (isfloat, args, , |
2999 "-*- texinfo -*-\n\ | |
3000 @deftypefn {Built-in Function} {} isfloat (@var{x})\n\ | |
3001 Return true if @var{x} is a floating-point numeric object.\n\ | |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11422
diff
changeset
|
3002 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
|
3003 @seealso{isinteger, ischar, islogical, isnumeric, isa}\n\ |
7576 | 3004 @end deftypefn") |
3005 { | |
3006 octave_value retval; | |
3007 | |
3008 if (args.length () == 1) | |
3009 retval = args(0).is_float_type (); | |
3010 else | |
3011 print_usage (); | |
3012 | |
3013 return retval; | |
3014 } | |
3015 | |
5775 | 3016 // FIXME -- perhaps this should be implemented with an |
5476 | 3017 // octave_value member function? |
3018 | |
3019 DEFUN (complex, args, , | |
3020 "-*- texinfo -*-\n\ | |
9309
fb8b8589dd46
Expand documentation for 'complex' function
Rik <rdrider0-list@yahoo.com>
parents:
9308
diff
changeset
|
3021 @deftypefn {Built-in Function} {} complex (@var{x})\n\ |
5476 | 3022 @deftypefnx {Built-in Function} {} complex (@var{re}, @var{im})\n\ |
9309
fb8b8589dd46
Expand documentation for 'complex' function
Rik <rdrider0-list@yahoo.com>
parents:
9308
diff
changeset
|
3023 Return a complex result from real arguments. With 1 real argument @var{x},\n\ |
fb8b8589dd46
Expand documentation for 'complex' function
Rik <rdrider0-list@yahoo.com>
parents:
9308
diff
changeset
|
3024 return the complex result @code{@var{x} + 0i}. With 2 real arguments,\n\ |
fb8b8589dd46
Expand documentation for 'complex' function
Rik <rdrider0-list@yahoo.com>
parents:
9308
diff
changeset
|
3025 return the complex result @code{@var{re} + @var{im}}. @code{complex} can\n\ |
fb8b8589dd46
Expand documentation for 'complex' function
Rik <rdrider0-list@yahoo.com>
parents:
9308
diff
changeset
|
3026 often be more convenient than expressions such as @code{a + i*b}.\n\ |
fb8b8589dd46
Expand documentation for 'complex' function
Rik <rdrider0-list@yahoo.com>
parents:
9308
diff
changeset
|
3027 For example:\n\ |
fb8b8589dd46
Expand documentation for 'complex' function
Rik <rdrider0-list@yahoo.com>
parents:
9308
diff
changeset
|
3028 \n\ |
fb8b8589dd46
Expand documentation for 'complex' function
Rik <rdrider0-list@yahoo.com>
parents:
9308
diff
changeset
|
3029 @example\n\ |
9758
09da0bd91412
Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents:
9736
diff
changeset
|
3030 @group\n\ |
9309
fb8b8589dd46
Expand documentation for 'complex' function
Rik <rdrider0-list@yahoo.com>
parents:
9308
diff
changeset
|
3031 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
|
3032 @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
|
3033 @end group\n\ |
9309
fb8b8589dd46
Expand documentation for 'complex' function
Rik <rdrider0-list@yahoo.com>
parents:
9308
diff
changeset
|
3034 @end example\n\ |
15028
397f0d80bd47
Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents:
15024
diff
changeset
|
3035 @seealso{real, imag, iscomplex, abs, arg}\n\ |
5476 | 3036 @end deftypefn") |
3037 { | |
3038 octave_value retval; | |
3039 | |
3040 int nargin = args.length (); | |
3041 | |
3042 if (nargin == 1) | |
3043 { | |
3044 octave_value arg = args(0); | |
3045 | |
3046 if (arg.is_complex_type ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3047 retval = arg; |
5476 | 3048 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3049 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3050 if (arg.is_sparse_type ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3051 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3052 SparseComplexMatrix val = arg.sparse_complex_matrix_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3053 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3054 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3055 retval = octave_value (new octave_sparse_complex_matrix (val)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3056 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3057 else if (arg.is_single_type ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3058 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3059 if (arg.numel () == 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3060 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3061 FloatComplex val = arg.float_complex_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3062 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3063 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3064 retval = octave_value (new octave_float_complex (val)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3065 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3066 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3067 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3068 FloatComplexNDArray val = arg.float_complex_array_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3069 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3070 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3071 retval = octave_value (new octave_float_complex_matrix (val)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3072 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3073 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3074 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3075 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3076 if (arg.numel () == 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3077 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3078 Complex val = arg.complex_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3079 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3080 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3081 retval = octave_value (new octave_complex (val)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3082 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3083 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3084 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3085 ComplexNDArray val = arg.complex_array_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3086 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3087 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3088 retval = octave_value (new octave_complex_matrix (val)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3089 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3090 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3091 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3092 if (error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3093 error ("complex: invalid conversion"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3094 } |
5476 | 3095 } |
3096 else if (nargin == 2) | |
3097 { | |
3098 octave_value re = args(0); | |
3099 octave_value im = args(1); | |
3100 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7743
diff
changeset
|
3101 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
|
3102 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3103 const SparseMatrix re_val = re.sparse_matrix_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3104 const SparseMatrix im_val = im.sparse_matrix_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3105 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3106 if (!error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3107 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3108 if (re.numel () == 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3109 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3110 SparseComplexMatrix result; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3111 if (re_val.nnz () == 0) |
14843
7d4f87c75dbb
data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents:
14635
diff
changeset
|
3112 result = Complex (0, 1) * SparseComplexMatrix (im_val); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3113 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3114 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3115 result = SparseComplexMatrix (im_val.dims (), re_val (0)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3116 octave_idx_type nr = im_val.rows (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3117 octave_idx_type nc = im_val.cols (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3118 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3119 for (octave_idx_type j = 0; j < nc; j++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3120 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3121 octave_idx_type off = j * nr; |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14853
diff
changeset
|
3122 for (octave_idx_type i = im_val.cidx (j); |
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14853
diff
changeset
|
3123 i < im_val.cidx (j + 1); i++) |
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14853
diff
changeset
|
3124 result.data (im_val.ridx (i) + off) = |
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14853
diff
changeset
|
3125 result.data (im_val.ridx (i) + off) + |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3126 Complex (0, im_val.data (i)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3127 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3128 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3129 retval = octave_value (new octave_sparse_complex_matrix (result)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3130 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3131 else if (im.numel () == 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3132 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3133 SparseComplexMatrix result; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3134 if (im_val.nnz () == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3135 result = SparseComplexMatrix (re_val); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3136 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3137 { |
14843
7d4f87c75dbb
data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents:
14635
diff
changeset
|
3138 result = SparseComplexMatrix (re_val.rows (), re_val.cols (), Complex (0, im_val (0))); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3139 octave_idx_type nr = re_val.rows (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3140 octave_idx_type nc = re_val.cols (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3141 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3142 for (octave_idx_type j = 0; j < nc; j++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3143 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3144 octave_idx_type off = j * nr; |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14853
diff
changeset
|
3145 for (octave_idx_type i = re_val.cidx (j); |
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14853
diff
changeset
|
3146 i < re_val.cidx (j + 1); i++) |
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14853
diff
changeset
|
3147 result.data (re_val.ridx (i) + off) = |
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14853
diff
changeset
|
3148 result.data (re_val.ridx (i) + off) + |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3149 re_val.data (i); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3150 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3151 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3152 retval = octave_value (new octave_sparse_complex_matrix (result)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3153 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3154 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3155 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3156 if (re_val.dims () == im_val.dims ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3157 { |
14843
7d4f87c75dbb
data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents:
14635
diff
changeset
|
3158 SparseComplexMatrix result = SparseComplexMatrix (re_val) |
7d4f87c75dbb
data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents:
14635
diff
changeset
|
3159 + Complex (0, 1) * SparseComplexMatrix (im_val); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3160 retval = octave_value (new octave_sparse_complex_matrix (result)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3161 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3162 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3163 error ("complex: dimension mismatch"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3164 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3165 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3166 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7743
diff
changeset
|
3167 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
|
3168 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3169 if (re.numel () == 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3170 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3171 float re_val = re.float_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3172 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3173 if (im.numel () == 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3174 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3175 float im_val = im.double_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3176 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3177 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3178 retval = octave_value (new octave_float_complex (FloatComplex (re_val, im_val))); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3179 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3180 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3181 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3182 const FloatNDArray im_val = im.float_array_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3183 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3184 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3185 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3186 FloatComplexNDArray result (im_val.dims (), FloatComplex ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3187 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3188 for (octave_idx_type i = 0; i < im_val.numel (); i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3189 result.xelem (i) = FloatComplex (re_val, im_val(i)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3190 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3191 retval = octave_value (new octave_float_complex_matrix (result)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3192 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3193 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3194 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3195 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3196 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3197 const FloatNDArray re_val = re.float_array_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3198 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3199 if (im.numel () == 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3200 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3201 float im_val = im.float_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3202 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3203 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3204 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3205 FloatComplexNDArray result (re_val.dims (), FloatComplex ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3206 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3207 for (octave_idx_type i = 0; i < re_val.numel (); i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3208 result.xelem (i) = FloatComplex (re_val(i), im_val); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3209 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3210 retval = octave_value (new octave_float_complex_matrix (result)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3211 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3212 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3213 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3214 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3215 const FloatNDArray im_val = im.float_array_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3216 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3217 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3218 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3219 if (re_val.dims () == im_val.dims ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3220 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3221 FloatComplexNDArray result (re_val.dims (), FloatComplex ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3222 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3223 for (octave_idx_type i = 0; i < re_val.numel (); i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3224 result.xelem (i) = FloatComplex (re_val(i), im_val(i)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3225 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3226 retval = octave_value (new octave_float_complex_matrix (result)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3227 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3228 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3229 error ("complex: dimension mismatch"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3230 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3231 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3232 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3233 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7743
diff
changeset
|
3234 else if (re.numel () == 1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3235 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3236 double re_val = re.double_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3237 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3238 if (im.numel () == 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3239 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3240 double im_val = im.double_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3241 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3242 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3243 retval = octave_value (new octave_complex (Complex (re_val, im_val))); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3244 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3245 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3246 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3247 const NDArray im_val = im.array_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3248 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3249 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3250 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3251 ComplexNDArray result (im_val.dims (), Complex ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3252 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3253 for (octave_idx_type i = 0; i < im_val.numel (); i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3254 result.xelem (i) = Complex (re_val, im_val(i)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3255 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3256 retval = octave_value (new octave_complex_matrix (result)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3257 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3258 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3259 } |
5476 | 3260 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3261 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3262 const NDArray re_val = re.array_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3263 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3264 if (im.numel () == 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3265 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3266 double im_val = im.double_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3267 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3268 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3269 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3270 ComplexNDArray result (re_val.dims (), Complex ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3271 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3272 for (octave_idx_type i = 0; i < re_val.numel (); i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3273 result.xelem (i) = Complex (re_val(i), im_val); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3274 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3275 retval = octave_value (new octave_complex_matrix (result)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3276 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3277 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3278 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3279 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3280 const NDArray im_val = im.array_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3281 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3282 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3283 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3284 if (re_val.dims () == im_val.dims ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3285 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3286 ComplexNDArray result (re_val.dims (), Complex ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3287 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3288 for (octave_idx_type i = 0; i < re_val.numel (); i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3289 result.xelem (i) = Complex (re_val(i), im_val(i)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3290 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3291 retval = octave_value (new octave_complex_matrix (result)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3292 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3293 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3294 error ("complex: dimension mismatch"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3295 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3296 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3297 } |
5476 | 3298 |
3299 if (error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3300 error ("complex: invalid conversion"); |
5476 | 3301 } |
3302 else | |
5823 | 3303 print_usage (); |
5476 | 3304 |
3305 return retval; | |
3306 } | |
3307 | |
3258 | 3308 DEFUN (isreal, args, , |
3428 | 3309 "-*- texinfo -*-\n\ |
3310 @deftypefn {Built-in Function} {} isreal (@var{x})\n\ | |
10291
fc879f361bda
make isreal matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10290
diff
changeset
|
3311 Return true if @var{x} is a non-complex matrix or scalar.\n\ |
10711
fbd7843974fa
Periodic grammar check of documentation files to ensure common format.
Rik <octave@nomad.inbox5.com>
parents:
10707
diff
changeset
|
3312 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
|
3313 matrices.\n\ |
15028
397f0d80bd47
Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents:
15024
diff
changeset
|
3314 @seealso{iscomplex, isnumeric, isa}\n\ |
3428 | 3315 @end deftypefn") |
3258 | 3316 { |
3317 octave_value retval; | |
3318 | |
3319 if (args.length () == 1) | |
3320 retval = args(0).is_real_type (); | |
3321 else | |
5823 | 3322 print_usage (); |
3258 | 3323 |
3324 return retval; | |
3325 } | |
3326 | |
3202 | 3327 DEFUN (isempty, args, , |
3373 | 3328 "-*- texinfo -*-\n\ |
3329 @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
|
3330 Return true if @var{a} is an empty matrix (any one of its dimensions is\n\ |
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11422
diff
changeset
|
3331 zero). Otherwise, return false.\n\ |
15028
397f0d80bd47
Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents:
15024
diff
changeset
|
3332 @seealso{isnull, isa}\n\ |
3373 | 3333 @end deftypefn") |
3202 | 3334 { |
4233 | 3335 octave_value retval = false; |
3202 | 3336 |
3337 if (args.length () == 1) | |
4559 | 3338 retval = args(0).is_empty (); |
3202 | 3339 else |
5823 | 3340 print_usage (); |
3202 | 3341 |
3342 return retval; | |
3343 } | |
3344 | |
16779
8fce0ed4894a
Specialize is_empty and numel methods for sparse matrices (debian bug #706376)
David Bateman <dbateman@free.fr>
parents:
16077
diff
changeset
|
3345 /* |
8fce0ed4894a
Specialize is_empty and numel methods for sparse matrices (debian bug #706376)
David Bateman <dbateman@free.fr>
parents:
16077
diff
changeset
|
3346 %% 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
|
3347 %!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
|
3348 */ |
8fce0ed4894a
Specialize is_empty and numel methods for sparse matrices (debian bug #706376)
David Bateman <dbateman@free.fr>
parents:
16077
diff
changeset
|
3349 |
3206 | 3350 DEFUN (isnumeric, args, , |
3428 | 3351 "-*- texinfo -*-\n\ |
3352 @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
|
3353 Return true if @var{x} is a numeric object, i.e., an integer, real, or\n\ |
10846
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10840
diff
changeset
|
3354 complex array. Logical and character arrays are not considered to be\n\ |
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10840
diff
changeset
|
3355 numeric.\n\ |
15028
397f0d80bd47
Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents:
15024
diff
changeset
|
3356 @seealso{isinteger, isfloat, isreal, iscomplex, islogical, ischar, iscell, isstruct, isa}\n\ |
3428 | 3357 @end deftypefn") |
3206 | 3358 { |
3359 octave_value retval; | |
3360 | |
3361 if (args.length () == 1) | |
3258 | 3362 retval = args(0).is_numeric_type (); |
3206 | 3363 else |
5823 | 3364 print_usage (); |
3206 | 3365 |
3366 return retval; | |
3367 } | |
3368 | |
11435
20f53b3a558f
Add tests for sparse forms of logical matrices to islogical, isnumeric.
Rik <octave@nomad.inbox5.com>
parents:
11431
diff
changeset
|
3369 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3370 %!assert (isnumeric (1), true) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3371 %!assert (isnumeric (1i), true) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3372 %!assert (isnumeric ([1,1]), true) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3373 %!assert (isnumeric (single (1)), true) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3374 %!assert (isnumeric (single (1i)), true) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3375 %!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
|
3376 %!assert (isnumeric (int8 (1)), true) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3377 %!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
|
3378 %!assert (isnumeric ("Hello World"), false) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3379 %!assert (isnumeric (true), false) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3380 %!assert (isnumeric (false), false) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3381 %!assert (isnumeric ([true, false]), false) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3382 %!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
|
3383 */ |
20f53b3a558f
Add tests for sparse forms of logical matrices to islogical, isnumeric.
Rik <octave@nomad.inbox5.com>
parents:
11431
diff
changeset
|
3384 |
4028 | 3385 DEFUN (ismatrix, args, , |
3321 | 3386 "-*- texinfo -*-\n\ |
4028 | 3387 @deftypefn {Built-in Function} {} ismatrix (@var{a})\n\ |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11422
diff
changeset
|
3388 Return true if @var{a} is a numeric, logical, or character matrix.\n\ |
11591
1d13679b587e
Use @nospell macro on certain words in docstrings.
Rik <octave@nomad.inbox5.com>
parents:
11590
diff
changeset
|
3389 Scalars (1x1 matrices) and vectors (@nospell{1xN} or @nospell{Nx1} matrices)\n\ |
1d13679b587e
Use @nospell macro on certain words in docstrings.
Rik <octave@nomad.inbox5.com>
parents:
11590
diff
changeset
|
3390 are subsets of the more general N-dimensional matrix and @code{ismatrix}\n\ |
1d13679b587e
Use @nospell macro on certain words in docstrings.
Rik <octave@nomad.inbox5.com>
parents:
11590
diff
changeset
|
3391 will return true for these objects as well.\n\ |
15028
397f0d80bd47
Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents:
15024
diff
changeset
|
3392 @seealso{isscalar, isvector, iscell, isstruct, issparse, isa}\n\ |
3333 | 3393 @end deftypefn") |
3202 | 3394 { |
4233 | 3395 octave_value retval = false; |
3202 | 3396 |
3397 if (args.length () == 1) | |
3398 { | |
3399 octave_value arg = args(0); | |
3400 | |
9866
b5aa5d9ee6b9
make ismatrix consistent for empty matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
9858
diff
changeset
|
3401 retval = arg.is_matrix_type () || arg.is_scalar_type () || arg.is_range (); |
3202 | 3402 } |
3403 else | |
5823 | 3404 print_usage (); |
3202 | 3405 |
3406 return retval; | |
3407 } | |
3408 | |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3409 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3410 %!assert (ismatrix ([])) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3411 %!assert (ismatrix (1)) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3412 %!assert (ismatrix ([1, 2, 3])) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3413 %!assert (ismatrix ([1, 2; 3, 4])) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3414 %!assert (ismatrix (zeros (3, 2, 4))) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3415 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3416 %!assert (ismatrix (single ([]))) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3417 %!assert (ismatrix (single (1))) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3418 %!assert (ismatrix (single ([1, 2, 3]))) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3419 %!assert (ismatrix (single ([1, 2; 3, 4]))) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3420 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3421 %!assert (ismatrix ("t")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3422 %!assert (ismatrix ("test")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3423 %!assert (ismatrix (["test"; "ing"])) |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3424 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3425 %!test |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3426 %! s.a = 1; |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3427 %! assert (ismatrix (s), false); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3428 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3429 %!error ismatrix () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3430 %!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
|
3431 */ |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3432 |
3354 | 3433 static octave_value |
5747 | 3434 fill_matrix (const octave_value_list& args, int val, const char *fcn) |
523 | 3435 { |
3354 | 3436 octave_value retval; |
523 | 3437 |
3438 int nargin = args.length (); | |
3439 | |
4946 | 3440 oct_data_conv::data_type dt = oct_data_conv::dt_double; |
4481 | 3441 |
4946 | 3442 dim_vector dims (1, 1); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
3443 |
4481 | 3444 if (nargin > 0 && args(nargin-1).is_string ()) |
3445 { | |
4946 | 3446 std::string nm = args(nargin-1).string_value (); |
4481 | 3447 nargin--; |
3448 | |
4946 | 3449 dt = oct_data_conv::string_to_data_type (nm); |
3450 | |
3451 if (error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3452 return retval; |
4481 | 3453 } |
3454 | |
523 | 3455 switch (nargin) |
3456 { | |
712 | 3457 case 0: |
3458 break; | |
777 | 3459 |
610 | 3460 case 1: |
4481 | 3461 get_dimensions (args(0), fcn, dims); |
610 | 3462 break; |
777 | 3463 |
4563 | 3464 default: |
3465 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3466 dims.resize (nargin); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3467 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3468 for (int i = 0; i < nargin; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3469 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3470 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
|
3471 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3472 if (error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3473 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3474 error ("%s: expecting scalar integer arguments", fcn); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3475 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3476 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3477 } |
4563 | 3478 } |
3479 break; | |
4481 | 3480 } |
3481 | |
3482 if (! error_state) | |
3483 { | |
4946 | 3484 dims.chop_trailing_singletons (); |
4565 | 3485 |
4481 | 3486 check_dimensions (dims, fcn); |
3354 | 3487 |
5775 | 3488 // FIXME -- perhaps this should be made extensible by |
4946 | 3489 // using the class name to lookup a function to call to create |
3490 // the new value. | |
3491 | |
3492 // Note that automatic narrowing will handle conversion from | |
3493 // NDArray to scalar. | |
3494 | |
4481 | 3495 if (! error_state) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3496 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3497 switch (dt) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3498 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3499 case oct_data_conv::dt_int8: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3500 retval = int8NDArray (dims, val); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3501 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3502 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3503 case oct_data_conv::dt_uint8: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3504 retval = uint8NDArray (dims, val); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3505 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3506 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3507 case oct_data_conv::dt_int16: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3508 retval = int16NDArray (dims, val); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3509 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3510 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3511 case oct_data_conv::dt_uint16: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3512 retval = uint16NDArray (dims, val); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3513 break; |
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 case oct_data_conv::dt_int32: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3516 retval = int32NDArray (dims, val); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3517 break; |
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 case oct_data_conv::dt_uint32: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3520 retval = uint32NDArray (dims, val); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3521 break; |
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 case oct_data_conv::dt_int64: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3524 retval = int64NDArray (dims, val); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3525 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3526 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3527 case oct_data_conv::dt_uint64: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3528 retval = uint64NDArray (dims, val); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3529 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3530 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3531 case oct_data_conv::dt_single: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3532 retval = FloatNDArray (dims, val); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3533 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3534 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3535 case oct_data_conv::dt_double: |
8972
5fa53d1b6247
more indexing optimizations
Jaroslav Hajek <highegg@gmail.com>
parents:
8947
diff
changeset
|
3536 { |
5fa53d1b6247
more indexing optimizations
Jaroslav Hajek <highegg@gmail.com>
parents:
8947
diff
changeset
|
3537 if (val == 1 && dims.length () == 2 && dims (0) == 1) |
5fa53d1b6247
more indexing optimizations
Jaroslav Hajek <highegg@gmail.com>
parents:
8947
diff
changeset
|
3538 retval = Range (1.0, 0.0, dims (1)); // packed form |
5fa53d1b6247
more indexing optimizations
Jaroslav Hajek <highegg@gmail.com>
parents:
8947
diff
changeset
|
3539 else |
5fa53d1b6247
more indexing optimizations
Jaroslav Hajek <highegg@gmail.com>
parents:
8947
diff
changeset
|
3540 retval = NDArray (dims, val); |
5fa53d1b6247
more indexing optimizations
Jaroslav Hajek <highegg@gmail.com>
parents:
8947
diff
changeset
|
3541 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3542 break; |
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 case oct_data_conv::dt_logical: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3545 retval = boolNDArray (dims, val); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3546 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3547 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3548 default: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3549 error ("%s: invalid class name", fcn); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3550 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3551 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3552 } |
523 | 3553 } |
3554 | |
3555 return retval; | |
3556 } | |
3557 | |
5747 | 3558 static octave_value |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
3559 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
|
3560 const char *fcn) |
7795
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3561 { |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3562 octave_value retval; |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3563 |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3564 int nargin = args.length (); |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3565 |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3566 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
|
3567 |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3568 dim_vector dims (1, 1); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
3569 |
7795
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3570 if (nargin > 0 && args(nargin-1).is_string ()) |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3571 { |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3572 std::string nm = args(nargin-1).string_value (); |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3573 nargin--; |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3574 |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3575 dt = oct_data_conv::string_to_data_type (nm); |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3576 |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3577 if (error_state) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3578 return retval; |
7795
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3579 } |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3580 |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3581 switch (nargin) |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3582 { |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3583 case 0: |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3584 break; |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3585 |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3586 case 1: |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3587 get_dimensions (args(0), fcn, dims); |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3588 break; |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3589 |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3590 default: |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3591 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3592 dims.resize (nargin); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3593 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3594 for (int i = 0; i < nargin; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3595 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3596 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
|
3597 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3598 if (error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3599 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3600 error ("%s: expecting scalar integer arguments", fcn); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3601 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3602 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3603 } |
7795
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3604 } |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3605 break; |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3606 } |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3607 |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3608 if (! error_state) |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3609 { |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3610 dims.chop_trailing_singletons (); |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3611 |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3612 check_dimensions (dims, fcn); |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3613 |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3614 // Note that automatic narrowing will handle conversion from |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3615 // NDArray to scalar. |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3616 |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3617 if (! error_state) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3618 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3619 switch (dt) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3620 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3621 case oct_data_conv::dt_single: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3622 retval = FloatNDArray (dims, fval); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3623 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3624 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3625 case oct_data_conv::dt_double: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3626 retval = NDArray (dims, val); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3627 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3628 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3629 default: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3630 error ("%s: invalid class name", fcn); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3631 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3632 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3633 } |
7795
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3634 } |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3635 |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3636 return retval; |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3637 } |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3638 |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3639 static octave_value |
5747 | 3640 fill_matrix (const octave_value_list& args, double val, const char *fcn) |
3641 { | |
3642 octave_value retval; | |
3643 | |
3644 int nargin = args.length (); | |
3645 | |
3646 oct_data_conv::data_type dt = oct_data_conv::dt_double; | |
3647 | |
3648 dim_vector dims (1, 1); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
3649 |
5747 | 3650 if (nargin > 0 && args(nargin-1).is_string ()) |
3651 { | |
3652 std::string nm = args(nargin-1).string_value (); | |
3653 nargin--; | |
3654 | |
3655 dt = oct_data_conv::string_to_data_type (nm); | |
3656 | |
3657 if (error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3658 return retval; |
5747 | 3659 } |
3660 | |
3661 switch (nargin) | |
3662 { | |
3663 case 0: | |
3664 break; | |
3665 | |
3666 case 1: | |
3667 get_dimensions (args(0), fcn, dims); | |
3668 break; | |
3669 | |
3670 default: | |
3671 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3672 dims.resize (nargin); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3673 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3674 for (int i = 0; i < nargin; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3675 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3676 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
|
3677 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3678 if (error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3679 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3680 error ("%s: expecting scalar integer arguments", fcn); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3681 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3682 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3683 } |
5747 | 3684 } |
3685 break; | |
3686 } | |
3687 | |
3688 if (! error_state) | |
3689 { | |
3690 dims.chop_trailing_singletons (); | |
3691 | |
3692 check_dimensions (dims, fcn); | |
3693 | |
3694 // Note that automatic narrowing will handle conversion from | |
3695 // NDArray to scalar. | |
3696 | |
3697 if (! error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3698 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3699 switch (dt) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3700 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3701 case oct_data_conv::dt_single: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3702 retval = FloatNDArray (dims, static_cast <float> (val)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3703 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3704 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3705 case oct_data_conv::dt_double: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3706 retval = NDArray (dims, val); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3707 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3708 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3709 default: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3710 error ("%s: invalid class name", fcn); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3711 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3712 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3713 } |
5747 | 3714 } |
3715 | |
3716 return retval; | |
3717 } | |
3718 | |
3719 static octave_value | |
3720 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
|
3721 const char *fcn) |
5747 | 3722 { |
3723 octave_value retval; | |
3724 | |
3725 int nargin = args.length (); | |
3726 | |
3727 oct_data_conv::data_type dt = oct_data_conv::dt_double; | |
3728 | |
3729 dim_vector dims (1, 1); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
3730 |
5747 | 3731 if (nargin > 0 && args(nargin-1).is_string ()) |
3732 { | |
3733 std::string nm = args(nargin-1).string_value (); | |
3734 nargin--; | |
3735 | |
3736 dt = oct_data_conv::string_to_data_type (nm); | |
3737 | |
3738 if (error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3739 return retval; |
5747 | 3740 } |
3741 | |
3742 switch (nargin) | |
3743 { | |
3744 case 0: | |
3745 break; | |
3746 | |
3747 case 1: | |
3748 get_dimensions (args(0), fcn, dims); | |
3749 break; | |
3750 | |
3751 default: | |
3752 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3753 dims.resize (nargin); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3754 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3755 for (int i = 0; i < nargin; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3756 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3757 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
|
3758 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3759 if (error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3760 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3761 error ("%s: expecting scalar integer arguments", fcn); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3762 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3763 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3764 } |
5747 | 3765 } |
3766 break; | |
3767 } | |
3768 | |
3769 if (! error_state) | |
3770 { | |
3771 dims.chop_trailing_singletons (); | |
3772 | |
3773 check_dimensions (dims, fcn); | |
3774 | |
3775 // Note that automatic narrowing will handle conversion from | |
3776 // NDArray to scalar. | |
3777 | |
3778 if (! error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3779 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3780 switch (dt) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3781 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3782 case oct_data_conv::dt_single: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3783 retval = FloatComplexNDArray (dims, static_cast<FloatComplex> (val)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3784 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3785 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3786 case oct_data_conv::dt_double: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3787 retval = ComplexNDArray (dims, val); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3788 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3789 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3790 default: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3791 error ("%s: invalid class name", fcn); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3792 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3793 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3794 } |
5747 | 3795 } |
3796 | |
3797 return retval; | |
3798 } | |
3799 | |
3800 static octave_value | |
3801 fill_matrix (const octave_value_list& args, bool val, const char *fcn) | |
3802 { | |
3803 octave_value retval; | |
3804 | |
3805 int nargin = args.length (); | |
3806 | |
3807 dim_vector dims (1, 1); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
3808 |
5747 | 3809 switch (nargin) |
3810 { | |
3811 case 0: | |
3812 break; | |
3813 | |
3814 case 1: | |
3815 get_dimensions (args(0), fcn, dims); | |
3816 break; | |
3817 | |
3818 default: | |
3819 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3820 dims.resize (nargin); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3821 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3822 for (int i = 0; i < nargin; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3823 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3824 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
|
3825 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3826 if (error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3827 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3828 error ("%s: expecting scalar integer arguments", fcn); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3829 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3830 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3831 } |
5747 | 3832 } |
3833 break; | |
3834 } | |
3835 | |
3836 if (! error_state) | |
3837 { | |
3838 dims.chop_trailing_singletons (); | |
3839 | |
3840 check_dimensions (dims, fcn); | |
3841 | |
3842 // Note that automatic narrowing will handle conversion from | |
3843 // NDArray to scalar. | |
3844 | |
3845 if (! error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3846 retval = boolNDArray (dims, val); |
5747 | 3847 } |
3848 | |
3849 return retval; | |
3850 } | |
3851 | |
3354 | 3852 DEFUN (ones, args, , |
3369 | 3853 "-*- texinfo -*-\n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
3854 @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
|
3855 @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
|
3856 @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
|
3857 @deftypefnx {Built-in Function} {} ones ([@var{m} @var{n} @dots{}])\n\ |
4948 | 3858 @deftypefnx {Built-in Function} {} ones (@dots{}, @var{class})\n\ |
4481 | 3859 Return a matrix or N-dimensional array whose elements are all 1.\n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
3860 If invoked with a single scalar integer argument @var{n}, return a square\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
3861 @nospell{NxN} matrix. If invoked with two or more scalar\n\ |
9428
b317debeb828
data.cc (Fones, Fzeros, Ftrue, Ffalse): update docstring
John W. Eaton <jwe@octave.org>
parents:
9351
diff
changeset
|
3862 integer arguments, or a vector of integer values, return an array with\n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
3863 the given dimensions.\n\ |
3369 | 3864 \n\ |
3865 If you need to create a matrix whose values are all the same, you should\n\ | |
3866 use an expression like\n\ | |
3867 \n\ | |
3868 @example\n\ | |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
3869 val_matrix = val * ones (m, n)\n\ |
3369 | 3870 @end example\n\ |
4945 | 3871 \n\ |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
3872 The optional argument @var{class} specifies the class of the return array\n\ |
10840 | 3873 and defaults to double. For example:\n\ |
4945 | 3874 \n\ |
3875 @example\n\ | |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
3876 val = ones (m,n, \"uint8\")\n\ |
4945 | 3877 @end example\n\ |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
3878 @seealso{zeros}\n\ |
3369 | 3879 @end deftypefn") |
523 | 3880 { |
5747 | 3881 return fill_matrix (args, 1, "ones"); |
523 | 3882 } |
3883 | |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3884 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3885 %!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
|
3886 %!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
|
3887 %!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
|
3888 %!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
|
3889 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3890 %!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
|
3891 %!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
|
3892 %!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
|
3893 %!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
|
3894 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3895 %!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
|
3896 %!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
|
3897 %!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
|
3898 %!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
|
3899 */ |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3900 |
3354 | 3901 DEFUN (zeros, args, , |
3369 | 3902 "-*- texinfo -*-\n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
3903 @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
|
3904 @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
|
3905 @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
|
3906 @deftypefnx {Built-in Function} {} zeros ([@var{m} @var{n} @dots{}])\n\ |
4948 | 3907 @deftypefnx {Built-in Function} {} zeros (@dots{}, @var{class})\n\ |
4481 | 3908 Return a matrix or N-dimensional array whose elements are all 0.\n\ |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
3909 If invoked with a single scalar integer argument, return a square\n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
3910 @nospell{NxN} matrix. If invoked with two or more scalar\n\ |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
3911 integer arguments, or a vector of integer values, return an array with\n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
3912 the given dimensions.\n\ |
4945 | 3913 \n\ |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
3914 The optional argument @var{class} specifies the class of the return array\n\ |
10840 | 3915 and defaults to double. For example:\n\ |
4945 | 3916 \n\ |
3917 @example\n\ | |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
3918 val = zeros (m,n, \"uint8\")\n\ |
4945 | 3919 @end example\n\ |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
3920 @seealso{ones}\n\ |
3369 | 3921 @end deftypefn") |
523 | 3922 { |
5747 | 3923 return fill_matrix (args, 0, "zeros"); |
3924 } | |
3925 | |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3926 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3927 %!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
|
3928 %!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
|
3929 %!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
|
3930 %!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
|
3931 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3932 %!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
|
3933 %!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
|
3934 %!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
|
3935 %!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
|
3936 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3937 %!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
|
3938 %!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
|
3939 %!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
|
3940 %!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
|
3941 */ |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3942 |
5747 | 3943 DEFUN (Inf, args, , |
3944 "-*- texinfo -*-\n\ | |
14171
2ced2f59f523
doc: miscellaneous documentation improvements
Rik <octave@nomad.inbox5.com>
parents:
14169
diff
changeset
|
3945 @c List other form of function in documentation index\n\ |
2ced2f59f523
doc: miscellaneous documentation improvements
Rik <octave@nomad.inbox5.com>
parents:
14169
diff
changeset
|
3946 @findex inf\n\ |
2ced2f59f523
doc: miscellaneous documentation improvements
Rik <octave@nomad.inbox5.com>
parents:
14169
diff
changeset
|
3947 \n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
3948 @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
|
3949 @deftypefnx {Built-in Function} {} Inf (@var{n})\n\ |
5747 | 3950 @deftypefnx {Built-in Function} {} Inf (@var{n}, @var{m})\n\ |
3951 @deftypefnx {Built-in Function} {} Inf (@var{n}, @var{m}, @var{k}, @dots{})\n\ | |
3952 @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
|
3953 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
|
3954 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
|
3955 \n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
3956 Infinity is produced when results are too large to be represented using the\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
3957 the IEEE floating point format for numbers. Two common examples which\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
3958 produce infinity are division by zero and overflow.\n\ |
10840 | 3959 \n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
3960 @example\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
3961 @group\n\ |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
3962 [ 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
|
3963 @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
|
3964 @end group\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
3965 @end example\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
3966 \n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
3967 When called with no arguments, return a scalar with the value @samp{Inf}.\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
3968 When called with a single argument, return a square matrix with the dimension\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
3969 specified. When called with more than one scalar argument the first two\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
3970 arguments are taken as the number of rows and columns and any further\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
3971 arguments specify additional matrix dimensions.\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
3972 The optional argument @var{class} specifies the return type and may be\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
3973 either \"double\" or \"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
|
3974 @seealso{isinf, NaN}\n\ |
5747 | 3975 @end deftypefn") |
3976 { | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
3977 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
|
3978 lo_ieee_float_inf_value (), "Inf"); |
5747 | 3979 } |
3980 | |
3981 DEFALIAS (inf, Inf); | |
3982 | |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3983 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3984 %!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
|
3985 %!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
|
3986 %!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
|
3987 %!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
|
3988 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3989 %!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
|
3990 %!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
|
3991 %!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
|
3992 %!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
|
3993 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3994 %!error (inf (3, "int8")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3995 %!error (inf (2, 3, "int8")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3996 %!error (inf (3, 2, "int8")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
3997 %!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
|
3998 */ |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3999 |
5747 | 4000 DEFUN (NaN, args, , |
4001 "-*- texinfo -*-\n\ | |
14171
2ced2f59f523
doc: miscellaneous documentation improvements
Rik <octave@nomad.inbox5.com>
parents:
14169
diff
changeset
|
4002 @c List other form of function in documentation index\n\ |
2ced2f59f523
doc: miscellaneous documentation improvements
Rik <octave@nomad.inbox5.com>
parents:
14169
diff
changeset
|
4003 @findex nan\n\ |
2ced2f59f523
doc: miscellaneous documentation improvements
Rik <octave@nomad.inbox5.com>
parents:
14169
diff
changeset
|
4004 \n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4005 @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
|
4006 @deftypefnx {Built-in Function} {} NaN (@var{n})\n\ |
5747 | 4007 @deftypefnx {Built-in Function} {} NaN (@var{n}, @var{m})\n\ |
4008 @deftypefnx {Built-in Function} {} NaN (@var{n}, @var{m}, @var{k}, @dots{})\n\ | |
4009 @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
|
4010 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
|
4011 to the IEEE symbol NaN (Not a Number).\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4012 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
|
4013 result. Common operations which produce a NaN are arithmetic with infinity\n\ |
5747 | 4014 @tex\n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4015 ($\\infty - \\infty$), zero divided by zero ($0/0$),\n\ |
5747 | 4016 @end tex\n\ |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
8487
diff
changeset
|
4017 @ifnottex\n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4018 (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
|
4019 @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
|
4020 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
|
4021 \n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4022 Note that NaN always compares not equal to NaN (NaN != NaN). This behavior\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4023 is specified by the IEEE standard for floating point arithmetic. To\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4024 find NaN values, use the @code{isnan} function.\n\ |
5747 | 4025 \n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4026 When called with no arguments, return a scalar with the value @samp{NaN}.\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4027 When called with a single argument, return a square matrix with the dimension\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4028 specified. When called with more than one scalar argument the first two\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4029 arguments are taken as the number of rows and columns and any further\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4030 arguments specify additional matrix dimensions.\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4031 The optional argument @var{class} specifies the return type and may be\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4032 either \"double\" or \"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
|
4033 @seealso{isnan, Inf}\n\ |
5747 | 4034 @end deftypefn") |
4035 { | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
4036 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
|
4037 lo_ieee_float_nan_value (), "NaN"); |
5747 | 4038 } |
4039 | |
4040 DEFALIAS (nan, NaN); | |
4041 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
4042 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4043 %!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
|
4044 %!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
|
4045 %!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
|
4046 %!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
|
4047 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4048 %!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
|
4049 %!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
|
4050 %!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
|
4051 %!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
|
4052 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4053 %!error (NaN (3, "int8")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4054 %!error (NaN (2, 3, "int8")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4055 %!error (NaN (3, 2, "int8")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4056 %!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
|
4057 */ |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4058 |
5747 | 4059 DEFUN (e, args, , |
4060 "-*- texinfo -*-\n\ | |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4061 @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
|
4062 @deftypefnx {Built-in Function} {} e (@var{n})\n\ |
5747 | 4063 @deftypefnx {Built-in Function} {} e (@var{n}, @var{m})\n\ |
4064 @deftypefnx {Built-in Function} {} e (@var{n}, @var{m}, @var{k}, @dots{})\n\ | |
4065 @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
|
4066 Return a scalar, matrix, or N-dimensional array whose elements are all equal\n\ |
5747 | 4067 to the base of natural logarithms. The constant\n\ |
4068 @tex\n\ | |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4069 $e$ satisfies the equation $\\log (e) = 1$.\n\ |
5747 | 4070 @end tex\n\ |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
8487
diff
changeset
|
4071 @ifnottex\n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4072 @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
|
4073 @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
|
4074 \n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4075 When called with no arguments, return a scalar with the value @math{e}. When\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4076 called with a single argument, return a square matrix with the dimension\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4077 specified. When called with more than one scalar argument the first two\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4078 arguments are taken as the number of rows and columns and any further\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4079 arguments specify additional matrix dimensions.\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4080 The optional argument @var{class} specifies the return type and may be\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4081 either \"double\" or \"single\".\n\ |
15175
5984aa619cd9
doc: Remove multiple seealso links to I (bug #37046).
Rik <rik@octave.org>
parents:
15111
diff
changeset
|
4082 @seealso{log, exp, pi, I}\n\ |
5747 | 4083 @end deftypefn") |
4084 { | |
4085 #if defined (M_E) | |
4086 double e_val = M_E; | |
4087 #else | |
4088 double e_val = exp (1.0); | |
4089 #endif | |
4090 | |
4091 return fill_matrix (args, e_val, "e"); | |
4092 } | |
4093 | |
4094 DEFUN (eps, args, , | |
4095 "-*- texinfo -*-\n\ | |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4096 @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
|
4097 @deftypefnx {Built-in Function} {} eps (@var{x})\n\ |
5747 | 4098 @deftypefnx {Built-in Function} {} eps (@var{n}, @var{m})\n\ |
4099 @deftypefnx {Built-in Function} {} eps (@var{n}, @var{m}, @var{k}, @dots{})\n\ | |
4100 @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
|
4101 Return a scalar, matrix or N-dimensional array whose elements are all eps,\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4102 the machine precision. More precisely, @code{eps} is the relative spacing\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4103 between any two adjacent numbers in the machine's floating point system.\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4104 This number is obviously system dependent. On machines that support IEEE\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4105 floating point arithmetic, @code{eps} is approximately\n\ |
5747 | 4106 @tex\n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4107 $2.2204\\times10^{-16}$ for double precision and $1.1921\\times10^{-7}$\n\ |
5747 | 4108 @end tex\n\ |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
8487
diff
changeset
|
4109 @ifnottex\n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4110 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
|
4111 @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
|
4112 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
|
4113 \n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4114 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
|
4115 @code{eps (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
|
4116 Given a single argument @var{x}, return the distance between @var{x} and\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4117 the next largest value.\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4118 When called with more than one argument the first two arguments are taken as\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4119 the number of rows and columns and any further\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4120 arguments specify additional matrix dimensions.\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4121 The optional argument @var{class} specifies the return type and may be\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4122 either \"double\" or \"single\".\n\ |
15028
397f0d80bd47
Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents:
15024
diff
changeset
|
4123 @seealso{realmax, realmin, intmax, bitmax}\n\ |
5747 | 4124 @end deftypefn") |
4125 { | |
7795
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4126 int nargin = args.length (); |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4127 octave_value retval; |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4128 |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4129 if (nargin == 1 && ! args(0).is_string ()) |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4130 { |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4131 if (args(0).is_single_type ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4132 { |
15509
f0dfdc7faa71
Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15467
diff
changeset
|
4133 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
|
4134 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4135 if (! error_state) |
15509
f0dfdc7faa71
Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15467
diff
changeset
|
4136 { |
f0dfdc7faa71
Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15467
diff
changeset
|
4137 Array<float> epsval (x.dims ()); |
f0dfdc7faa71
Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15467
diff
changeset
|
4138 |
f0dfdc7faa71
Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15467
diff
changeset
|
4139 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
|
4140 { |
15509
f0dfdc7faa71
Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15467
diff
changeset
|
4141 float val = ::fabsf (x(i)); |
f0dfdc7faa71
Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15467
diff
changeset
|
4142 if (xisnan (val) || xisinf (val)) |
f0dfdc7faa71
Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15467
diff
changeset
|
4143 epsval(i) = lo_ieee_nan_value (); |
f0dfdc7faa71
Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15467
diff
changeset
|
4144 else if (val < std::numeric_limits<float>::min ()) |
f0dfdc7faa71
Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15467
diff
changeset
|
4145 epsval(i) = powf (2.0, -149e0); |
f0dfdc7faa71
Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15467
diff
changeset
|
4146 else |
f0dfdc7faa71
Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15467
diff
changeset
|
4147 { |
f0dfdc7faa71
Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15467
diff
changeset
|
4148 int expon; |
f0dfdc7faa71
Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15467
diff
changeset
|
4149 frexpf (val, &expon); |
f0dfdc7faa71
Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15467
diff
changeset
|
4150 epsval(i) = std::pow (static_cast <float> (2.0), |
f0dfdc7faa71
Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15467
diff
changeset
|
4151 static_cast <float> (expon - 24)); |
f0dfdc7faa71
Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15467
diff
changeset
|
4152 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4153 } |
15509
f0dfdc7faa71
Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15467
diff
changeset
|
4154 retval = epsval; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4155 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4156 } |
7795
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4157 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4158 { |
15509
f0dfdc7faa71
Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15467
diff
changeset
|
4159 Array<double> x = args(0).array_value (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4160 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4161 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4162 { |
15509
f0dfdc7faa71
Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15467
diff
changeset
|
4163 Array<double> epsval (x.dims ()); |
f0dfdc7faa71
Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15467
diff
changeset
|
4164 |
f0dfdc7faa71
Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15467
diff
changeset
|
4165 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
|
4166 { |
15509
f0dfdc7faa71
Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15467
diff
changeset
|
4167 double val = ::fabs (x(i)); |
f0dfdc7faa71
Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15467
diff
changeset
|
4168 if (xisnan (val) || xisinf (val)) |
f0dfdc7faa71
Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15467
diff
changeset
|
4169 epsval(i) = lo_ieee_nan_value (); |
f0dfdc7faa71
Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15467
diff
changeset
|
4170 else if (val < std::numeric_limits<double>::min ()) |
f0dfdc7faa71
Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15467
diff
changeset
|
4171 epsval(i) = pow (2.0, -1074e0); |
f0dfdc7faa71
Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15467
diff
changeset
|
4172 else |
f0dfdc7faa71
Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15467
diff
changeset
|
4173 { |
f0dfdc7faa71
Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15467
diff
changeset
|
4174 int expon; |
f0dfdc7faa71
Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15467
diff
changeset
|
4175 frexp (val, &expon); |
f0dfdc7faa71
Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15467
diff
changeset
|
4176 epsval(i) = std::pow (static_cast <double> (2.0), |
f0dfdc7faa71
Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15467
diff
changeset
|
4177 static_cast <double> (expon - 53)); |
f0dfdc7faa71
Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15467
diff
changeset
|
4178 } |
f0dfdc7faa71
Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15467
diff
changeset
|
4179 retval = epsval; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4180 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4181 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4182 } |
7795
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4183 } |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4184 else |
15213
336f42406671
use numeric_limits functions instead of DBL_MIN, DBL_MAX, etc.
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
4185 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
|
4186 std::numeric_limits<float>::epsilon (), "eps"); |
7795
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4187 |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4188 return retval; |
5747 | 4189 } |
4190 | |
7795
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4191 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4192 %!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
|
4193 %!assert (eps (1), 2^(-52)) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4194 %!assert (eps (2), 2^(-51)) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4195 %!assert (eps (realmax), 2^971) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4196 %!assert (eps (0), 2^(-1074)) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4197 %!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
|
4198 %!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
|
4199 %!assert (eps (Inf), NaN) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4200 %!assert (eps (NaN), NaN) |
15509
f0dfdc7faa71
Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15467
diff
changeset
|
4201 %!assert (eps ([1/2 1 2 realmax 0 realmin/2 realmin/16 Inf NaN]), |
f0dfdc7faa71
Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15467
diff
changeset
|
4202 %! [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
|
4203 %!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
|
4204 %!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
|
4205 %!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
|
4206 %!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
|
4207 %!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
|
4208 %!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
|
4209 %!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
|
4210 %!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
|
4211 %!assert (eps (single (NaN)), single (NaN)) |
15509
f0dfdc7faa71
Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15467
diff
changeset
|
4212 %!assert (eps (single ([1/2 1 2 realmax("single") 0 realmin("single")/2 realmin("single")/16 Inf NaN])), |
f0dfdc7faa71
Fix incorrect behaviour of eps () for matrix input (bug #37539).
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15467
diff
changeset
|
4213 %! 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
|
4214 |
7795
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4215 */ |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
4216 |
5747 | 4217 DEFUN (pi, args, , |
4218 "-*- texinfo -*-\n\ | |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4219 @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
|
4220 @deftypefnx {Built-in Function} {} pi (@var{n})\n\ |
5747 | 4221 @deftypefnx {Built-in Function} {} pi (@var{n}, @var{m})\n\ |
4222 @deftypefnx {Built-in Function} {} pi (@var{n}, @var{m}, @var{k}, @dots{})\n\ | |
4223 @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
|
4224 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
|
4225 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
|
4226 @tex\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4227 diameter($\\pi$).\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4228 @end tex\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4229 @ifnottex\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4230 diameter.\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4231 @end ifnottex\n\ |
5747 | 4232 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
|
4233 \n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4234 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
|
4235 @tex\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4236 $\\pi$.\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4237 @end tex\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4238 @ifnottex\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4239 pi.\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4240 @end ifnottex\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4241 When called with a single argument, return a square matrix with the dimension\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4242 specified. When called with more than one scalar argument the first two\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4243 arguments are taken as the number of rows and columns and any further\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4244 arguments specify additional matrix dimensions.\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4245 The optional argument @var{class} specifies the return type and may be\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4246 either \"double\" or \"single\".\n\ |
15175
5984aa619cd9
doc: Remove multiple seealso links to I (bug #37046).
Rik <rik@octave.org>
parents:
15111
diff
changeset
|
4247 @seealso{e, I}\n\ |
5747 | 4248 @end deftypefn") |
4249 { | |
4250 #if defined (M_PI) | |
4251 double pi_val = M_PI; | |
4252 #else | |
4253 double pi_val = 4.0 * atan (1.0); | |
4254 #endif | |
4255 | |
4256 return fill_matrix (args, pi_val, "pi"); | |
4257 } | |
4258 | |
4259 DEFUN (realmax, args, , | |
4260 "-*- texinfo -*-\n\ | |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4261 @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
|
4262 @deftypefnx {Built-in Function} {} realmax (@var{n})\n\ |
5747 | 4263 @deftypefnx {Built-in Function} {} realmax (@var{n}, @var{m})\n\ |
4264 @deftypefnx {Built-in Function} {} realmax (@var{n}, @var{m}, @var{k}, @dots{})\n\ | |
4265 @deftypefnx {Built-in Function} {} realmax (@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
|
4266 Return a scalar, matrix or N-dimensional array whose elements are all equal\n\ |
5747 | 4267 to the largest floating point number that is representable. The actual\n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4268 value is system dependent. On machines that support IEEE\n\ |
5747 | 4269 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
|
4270 @tex\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4271 $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
|
4272 @end tex\n\ |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
8487
diff
changeset
|
4273 @ifnottex\n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4274 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
|
4275 @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
|
4276 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
|
4277 \n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4278 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
|
4279 @code{realmax (\"double\")}.\n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4280 When called with a single argument, return a square matrix with the dimension\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4281 specified. When called with more than one scalar argument the first two\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4282 arguments are taken as the number of rows and columns and any further\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4283 arguments specify additional matrix dimensions.\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4284 The optional argument @var{class} specifies the return type and may be\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4285 either \"double\" or \"single\".\n\ |
15028
397f0d80bd47
Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents:
15024
diff
changeset
|
4286 @seealso{realmin, intmax, bitmax, eps}\n\ |
5747 | 4287 @end deftypefn") |
4288 { | |
15213
336f42406671
use numeric_limits functions instead of DBL_MIN, DBL_MAX, etc.
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
4289 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
|
4290 std::numeric_limits<float>::max (), "realmax"); |
5747 | 4291 } |
4292 | |
4293 DEFUN (realmin, args, , | |
4294 "-*- texinfo -*-\n\ | |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4295 @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
|
4296 @deftypefnx {Built-in Function} {} realmin (@var{n})\n\ |
5747 | 4297 @deftypefnx {Built-in Function} {} realmin (@var{n}, @var{m})\n\ |
4298 @deftypefnx {Built-in Function} {} realmin (@var{n}, @var{m}, @var{k}, @dots{})\n\ | |
4299 @deftypefnx {Built-in Function} {} realmin (@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
|
4300 Return a scalar, matrix or N-dimensional array whose elements are all equal\n\ |
5747 | 4301 to the smallest normalized floating point number that is representable.\n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4302 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
|
4303 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
|
4304 @tex\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4305 $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
|
4306 @end tex\n\ |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
8487
diff
changeset
|
4307 @ifnottex\n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4308 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
|
4309 @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
|
4310 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
|
4311 \n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4312 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
|
4313 @code{realmin (\"double\")}.\n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4314 When called with a single argument, return a square matrix with the dimension\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4315 specified. When called with more than one scalar argument the first two\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4316 arguments are taken as the number of rows and columns and any further\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4317 arguments specify additional matrix dimensions.\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4318 The optional argument @var{class} specifies the return type and may be\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4319 either \"double\" or \"single\".\n\ |
15028
397f0d80bd47
Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents:
15024
diff
changeset
|
4320 @seealso{realmax, intmin, eps}\n\ |
5747 | 4321 @end deftypefn") |
4322 { | |
15213
336f42406671
use numeric_limits functions instead of DBL_MIN, DBL_MAX, etc.
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
4323 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
|
4324 std::numeric_limits<float>::min (), "realmin"); |
5747 | 4325 } |
4326 | |
4327 DEFUN (I, args, , | |
4328 "-*- texinfo -*-\n\ | |
14100
8a2dc08886ea
Fix Info referencing for i, I, j, J (Bug #35157)
Rik <octave@nomad.inbox5.com>
parents:
14085
diff
changeset
|
4329 @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
|
4330 @findex i\n\ |
8a2dc08886ea
Fix Info referencing for i, I, j, J (Bug #35157)
Rik <octave@nomad.inbox5.com>
parents:
14085
diff
changeset
|
4331 @findex j\n\ |
8a2dc08886ea
Fix Info referencing for i, I, j, J (Bug #35157)
Rik <octave@nomad.inbox5.com>
parents:
14085
diff
changeset
|
4332 @findex J\n\ |
8a2dc08886ea
Fix Info referencing for i, I, j, J (Bug #35157)
Rik <octave@nomad.inbox5.com>
parents:
14085
diff
changeset
|
4333 \n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4334 @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
|
4335 @deftypefnx {Built-in Function} {} I (@var{n})\n\ |
5747 | 4336 @deftypefnx {Built-in Function} {} I (@var{n}, @var{m})\n\ |
4337 @deftypefnx {Built-in Function} {} I (@var{n}, @var{m}, @var{k}, @dots{})\n\ | |
4338 @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
|
4339 Return a scalar, matrix, or N-dimensional array whose elements are all equal\n\ |
5747 | 4340 to the pure imaginary unit, defined as\n\ |
4341 @tex\n\ | |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4342 $\\sqrt{-1}$.\n\ |
5747 | 4343 @end tex\n\ |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
8487
diff
changeset
|
4344 @ifnottex\n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4345 @code{sqrt (-1)}.\n\ |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
8487
diff
changeset
|
4346 @end ifnottex\n\ |
15028
397f0d80bd47
Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents:
15024
diff
changeset
|
4347 \n\ |
15034
1116864ee270
doc: Fix for bad cross-referencing due to use of aliases in Texinfo.
Rik <rik@octave.org>
parents:
15031
diff
changeset
|
4348 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
|
4349 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
|
4350 \n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4351 When called with no arguments, return a scalar with the value @math{i}. When\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4352 called with a single argument, return a square matrix with the dimension\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4353 specified. When called with more than one scalar argument the first two\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4354 arguments are taken as the number of rows and columns and any further\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4355 arguments specify additional matrix dimensions.\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4356 The optional argument @var{class} specifies the return type and may be\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
4357 either \"double\" or \"single\".\n\ |
15175
5984aa619cd9
doc: Remove multiple seealso links to I (bug #37046).
Rik <rik@octave.org>
parents:
15111
diff
changeset
|
4358 @seealso{e, pi, log, exp}\n\ |
5747 | 4359 @end deftypefn") |
4360 { | |
4361 return fill_matrix (args, Complex (0.0, 1.0), "I"); | |
4362 } | |
4363 | |
4364 DEFALIAS (i, I); | |
4365 DEFALIAS (J, I); | |
4366 DEFALIAS (j, I); | |
4367 | |
4368 DEFUN (NA, args, , | |
4369 "-*- texinfo -*-\n\ | |
9308
f2bf62f62286
Update documentation for NA and isna functions
Rik <rdrider0-list@yahoo.com>
parents:
9198
diff
changeset
|
4370 @deftypefn {Built-in Function} {} NA\n\ |
f2bf62f62286
Update documentation for NA and isna functions
Rik <rdrider0-list@yahoo.com>
parents:
9198
diff
changeset
|
4371 @deftypefnx {Built-in Function} {} NA (@var{n})\n\ |
5747 | 4372 @deftypefnx {Built-in Function} {} NA (@var{n}, @var{m})\n\ |
4373 @deftypefnx {Built-in Function} {} NA (@var{n}, @var{m}, @var{k}, @dots{})\n\ | |
4374 @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
|
4375 Return a scalar, matrix, or N-dimensional array whose elements are all equal\n\ |
5747 | 4376 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
|
4377 \n\ |
f2bf62f62286
Update documentation for NA and isna functions
Rik <rdrider0-list@yahoo.com>
parents:
9198
diff
changeset
|
4378 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
|
4379 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
|
4380 \n\ |
f2bf62f62286
Update documentation for NA and isna functions
Rik <rdrider0-list@yahoo.com>
parents:
9198
diff
changeset
|
4381 When called with no arguments, return a scalar with the value @samp{NA}.\n\ |
f2bf62f62286
Update documentation for NA and isna functions
Rik <rdrider0-list@yahoo.com>
parents:
9198
diff
changeset
|
4382 When called with a single argument, return a square matrix with the dimension\n\ |
f2bf62f62286
Update documentation for NA and isna functions
Rik <rdrider0-list@yahoo.com>
parents:
9198
diff
changeset
|
4383 specified. When called with more than one scalar argument the first two\n\ |
f2bf62f62286
Update documentation for NA and isna functions
Rik <rdrider0-list@yahoo.com>
parents:
9198
diff
changeset
|
4384 arguments are taken as the number of rows and columns and any further\n\ |
f2bf62f62286
Update documentation for NA and isna functions
Rik <rdrider0-list@yahoo.com>
parents:
9198
diff
changeset
|
4385 arguments specify additional matrix dimensions.\n\ |
f2bf62f62286
Update documentation for NA and isna functions
Rik <rdrider0-list@yahoo.com>
parents:
9198
diff
changeset
|
4386 The optional argument @var{class} specifies the return type and may be\n\ |
f2bf62f62286
Update documentation for NA and isna functions
Rik <rdrider0-list@yahoo.com>
parents:
9198
diff
changeset
|
4387 either \"double\" or \"single\".\n\ |
f2bf62f62286
Update documentation for NA and isna functions
Rik <rdrider0-list@yahoo.com>
parents:
9198
diff
changeset
|
4388 @seealso{isna}\n\ |
5747 | 4389 @end deftypefn") |
4390 { | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
4391 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
|
4392 lo_ieee_float_na_value (), "NA"); |
5747 | 4393 } |
4394 | |
7991
139f47cf17ab
Change NA value to support single to double precision conversion
David Bateman <dbateman@free.fr>
parents:
7919
diff
changeset
|
4395 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4396 %!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
|
4397 %!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
|
4398 */ |
7991
139f47cf17ab
Change NA value to support single to double precision conversion
David Bateman <dbateman@free.fr>
parents:
7919
diff
changeset
|
4399 |
5747 | 4400 DEFUN (false, args, , |
4401 "-*- texinfo -*-\n\ | |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
4402 @deftypefn {Built-in Function} {} false (@var{x})\n\ |
5747 | 4403 @deftypefnx {Built-in Function} {} false (@var{n}, @var{m})\n\ |
4404 @deftypefnx {Built-in Function} {} false (@var{n}, @var{m}, @var{k}, @dots{})\n\ | |
4405 Return a matrix or N-dimensional array whose elements are all logical 0.\n\ | |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
4406 If invoked with a single scalar integer argument, return a square\n\ |
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
4407 matrix of the specified size. If invoked with two or more scalar\n\ |
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
4408 integer arguments, or a vector of integer values, return an array with\n\ |
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
4409 given dimensions.\n\ |
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
4410 @seealso{true}\n\ |
5747 | 4411 @end deftypefn") |
4412 { | |
4413 return fill_matrix (args, false, "false"); | |
4414 } | |
4415 | |
4416 DEFUN (true, args, , | |
4417 "-*- texinfo -*-\n\ | |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
4418 @deftypefn {Built-in Function} {} true (@var{x})\n\ |
5747 | 4419 @deftypefnx {Built-in Function} {} true (@var{n}, @var{m})\n\ |
4420 @deftypefnx {Built-in Function} {} true (@var{n}, @var{m}, @var{k}, @dots{})\n\ | |
4421 Return a matrix or N-dimensional array whose elements are all logical 1.\n\ | |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
4422 If invoked with a single scalar integer argument, return a square\n\ |
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
4423 matrix of the specified size. If invoked with two or more scalar\n\ |
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
4424 integer arguments, or a vector of integer values, return an array with\n\ |
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
4425 given dimensions.\n\ |
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
4426 @seealso{false}\n\ |
5747 | 4427 @end deftypefn") |
4428 { | |
4429 return fill_matrix (args, true, "true"); | |
3354 | 4430 } |
523 | 4431 |
4946 | 4432 template <class MT> |
4433 octave_value | |
4434 identity_matrix (int nr, int nc) | |
4435 { | |
4436 octave_value retval; | |
4437 | |
9685 | 4438 typename MT::element_type one (1); |
4946 | 4439 |
4440 if (nr == 1 && nc == 1) | |
4441 retval = one; | |
4442 else | |
4443 { | |
4444 dim_vector dims (nr, nc); | |
4445 | |
9685 | 4446 typename MT::element_type zero (0); |
4946 | 4447 |
4448 MT m (dims, zero); | |
4449 | |
4450 if (nr > 0 && nc > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4451 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4452 int n = std::min (nr, nc); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4453 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4454 for (int i = 0; i < n; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4455 m(i,i) = one; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4456 } |
4946 | 4457 |
4458 retval = m; | |
4459 } | |
4460 | |
4461 return retval; | |
4462 } | |
4463 | |
5058 | 4464 #define INSTANTIATE_EYE(T) \ |
4465 template octave_value identity_matrix<T> (int, int) | |
4466 | |
4467 INSTANTIATE_EYE (int8NDArray); | |
4468 INSTANTIATE_EYE (uint8NDArray); | |
4469 INSTANTIATE_EYE (int16NDArray); | |
4470 INSTANTIATE_EYE (uint16NDArray); | |
4471 INSTANTIATE_EYE (int32NDArray); | |
4472 INSTANTIATE_EYE (uint32NDArray); | |
4473 INSTANTIATE_EYE (int64NDArray); | |
4474 INSTANTIATE_EYE (uint64NDArray); | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7743
diff
changeset
|
4475 INSTANTIATE_EYE (FloatNDArray); |
5058 | 4476 INSTANTIATE_EYE (NDArray); |
4477 INSTANTIATE_EYE (boolNDArray); | |
4478 | |
4945 | 4479 static octave_value |
4948 | 4480 identity_matrix (int nr, int nc, oct_data_conv::data_type dt) |
4945 | 4481 { |
4482 octave_value retval; | |
4483 | |
5775 | 4484 // FIXME -- perhaps this should be made extensible by using |
4946 | 4485 // the class name to lookup a function to call to create the new |
4486 // value. | |
4487 | |
4488 if (! error_state) | |
4489 { | |
4490 switch (dt) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4491 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4492 case oct_data_conv::dt_int8: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4493 retval = identity_matrix<int8NDArray> (nr, nc); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4494 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4495 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4496 case oct_data_conv::dt_uint8: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4497 retval = identity_matrix<uint8NDArray> (nr, nc); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4498 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4499 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4500 case oct_data_conv::dt_int16: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4501 retval = identity_matrix<int16NDArray> (nr, nc); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4502 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4503 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4504 case oct_data_conv::dt_uint16: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4505 retval = identity_matrix<uint16NDArray> (nr, nc); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4506 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4507 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4508 case oct_data_conv::dt_int32: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4509 retval = identity_matrix<int32NDArray> (nr, nc); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4510 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4511 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4512 case oct_data_conv::dt_uint32: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4513 retval = identity_matrix<uint32NDArray> (nr, nc); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4514 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4515 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4516 case oct_data_conv::dt_int64: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4517 retval = identity_matrix<int64NDArray> (nr, nc); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4518 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4519 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4520 case oct_data_conv::dt_uint64: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4521 retval = identity_matrix<uint64NDArray> (nr, nc); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4522 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4523 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4524 case oct_data_conv::dt_single: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4525 retval = FloatDiagMatrix (nr, nc, 1.0f); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4526 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4527 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4528 case oct_data_conv::dt_double: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4529 retval = DiagMatrix (nr, nc, 1.0); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4530 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4531 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4532 case oct_data_conv::dt_logical: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4533 retval = identity_matrix<boolNDArray> (nr, nc); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4534 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4535 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4536 default: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4537 error ("eye: invalid class name"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4538 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4539 } |
4945 | 4540 } |
4541 | |
4542 return retval; | |
4543 } | |
4544 | |
4946 | 4545 #undef INT_EYE_MATRIX |
4546 | |
1957 | 4547 DEFUN (eye, args, , |
3369 | 4548 "-*- texinfo -*-\n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
4549 @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
|
4550 @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
|
4551 @deftypefnx {Built-in Function} {} eye ([@var{m} @var{n}])\n\ |
4948 | 4552 @deftypefnx {Built-in Function} {} eye (@dots{}, @var{class})\n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
4553 Return an identity matrix. If invoked with a single scalar argument @var{n},\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
4554 return a square @nospell{NxN} identity matrix. If\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
4555 supplied two scalar arguments (@var{m}, @var{n}), @code{eye} takes them to be\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
4556 the number of rows and columns. If given a vector with two elements,\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
4557 @code{eye} uses the values of the elements as the number of rows and columns,\n\ |
10840 | 4558 respectively. For example:\n\ |
3369 | 4559 \n\ |
4560 @example\n\ | |
4561 @group\n\ | |
4562 eye (3)\n\ | |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
4563 @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
|
4564 0 1 0\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
4565 0 0 1\n\ |
3369 | 4566 @end group\n\ |
4567 @end example\n\ | |
4568 \n\ | |
4569 The following expressions all produce the same result:\n\ | |
4570 \n\ | |
4571 @example\n\ | |
4572 @group\n\ | |
4573 eye (2)\n\ | |
4574 @equiv{}\n\ | |
4575 eye (2, 2)\n\ | |
4576 @equiv{}\n\ | |
4577 eye (size ([1, 2; 3, 4])\n\ | |
4578 @end group\n\ | |
4579 @end example\n\ | |
4580 \n\ | |
4945 | 4581 The optional argument @var{class}, allows @code{eye} to return an array of\n\ |
4582 the specified type, like\n\ | |
4583 \n\ | |
4584 @example\n\ | |
4585 val = zeros (n,m, \"uint8\")\n\ | |
4586 @end example\n\ | |
4587 \n\ | |
6556 | 4588 Calling @code{eye} with no arguments is equivalent to calling it\n\ |
12905
f7a8d1dafda3
Let rand accept negative dimensions (bug #33301)
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12886
diff
changeset
|
4589 with an argument of 1. Any negative dimensions are treated as zero. \n\ |
f7a8d1dafda3
Let rand accept negative dimensions (bug #33301)
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12886
diff
changeset
|
4590 These odd 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
|
4591 @seealso{speye, ones, zeros}\n\ |
3369 | 4592 @end deftypefn") |
523 | 4593 { |
3354 | 4594 octave_value retval; |
523 | 4595 |
4948 | 4596 int nargin = args.length (); |
4945 | 4597 |
4948 | 4598 oct_data_conv::data_type dt = oct_data_conv::dt_double; |
523 | 4599 |
4945 | 4600 // Check for type information. |
4601 | |
4602 if (nargin > 0 && args(nargin-1).is_string ()) | |
4603 { | |
4948 | 4604 std::string nm = args(nargin-1).string_value (); |
4945 | 4605 nargin--; |
4948 | 4606 |
4607 dt = oct_data_conv::string_to_data_type (nm); | |
4608 | |
4609 if (error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4610 return retval; |
4945 | 4611 } |
4612 | |
523 | 4613 switch (nargin) |
4614 { | |
712 | 4615 case 0: |
4948 | 4616 retval = identity_matrix (1, 1, dt); |
712 | 4617 break; |
777 | 4618 |
610 | 4619 case 1: |
3354 | 4620 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4621 octave_idx_type nr, nc; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4622 get_dimensions (args(0), "eye", nr, nc); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4623 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4624 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4625 retval = identity_matrix (nr, nc, dt); |
3354 | 4626 } |
610 | 4627 break; |
777 | 4628 |
523 | 4629 case 2: |
3354 | 4630 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4631 octave_idx_type nr, nc; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4632 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
|
4633 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4634 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4635 retval = identity_matrix (nr, nc, dt); |
3354 | 4636 } |
523 | 4637 break; |
777 | 4638 |
523 | 4639 default: |
5823 | 4640 print_usage (); |
523 | 4641 break; |
4642 } | |
4643 | |
4644 return retval; | |
4645 } | |
4646 | |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4647 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4648 %!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
|
4649 %!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
|
4650 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4651 %!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
|
4652 %!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
|
4653 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4654 %!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
|
4655 %!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
|
4656 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4657 %!error eye (1, 2, 3) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4658 */ |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4659 |
9658
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4660 template <class MT> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
4661 static octave_value |
9658
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4662 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
|
4663 octave_idx_type n) |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4664 { |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4665 typedef typename MT::column_vector_type CVT; |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4666 typedef typename MT::element_type T; |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4667 |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4668 octave_value retval; |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4669 |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4670 if (base.is_scalar_type ()) |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4671 { |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4672 T bs = octave_value_extract<T> (base); |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4673 if (limit.is_scalar_type ()) |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4674 { |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4675 T ls = octave_value_extract<T> (limit); |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4676 retval = linspace (bs, ls, n); |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4677 } |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4678 else |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4679 { |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4680 CVT lv = octave_value_extract<CVT> (limit); |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4681 CVT bv (lv.length (), bs); |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4682 retval = linspace (bv, lv, n); |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4683 } |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4684 } |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4685 else |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4686 { |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4687 CVT bv = octave_value_extract<CVT> (base); |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4688 if (limit.is_scalar_type ()) |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4689 { |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4690 T ls = octave_value_extract<T> (limit); |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4691 CVT lv (bv.length (), ls); |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4692 retval = linspace (bv, lv, n); |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4693 } |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4694 else |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4695 { |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4696 CVT lv = octave_value_extract<CVT> (limit); |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4697 retval = linspace (bv, lv, n); |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4698 } |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4699 } |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4700 |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4701 return retval; |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4702 } |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4703 |
1957 | 4704 DEFUN (linspace, args, , |
3369 | 4705 "-*- texinfo -*-\n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
4706 @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
|
4707 @deftypefnx {Built-in Function} {} linspace (@var{base}, @var{limit}, @var{n})\n\ |
3369 | 4708 Return a row vector with @var{n} linearly spaced elements between\n\ |
6630 | 4709 @var{base} and @var{limit}. If the number of elements is greater than one,\n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
4710 then the endpoints @var{base} and @var{limit} are always included in\n\ |
3369 | 4711 the range. If @var{base} is greater than @var{limit}, the elements are\n\ |
4712 stored in decreasing order. If the number of points is not specified, a\n\ | |
4713 value of 100 is used.\n\ | |
1100 | 4714 \n\ |
9658
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4715 The @code{linspace} function always returns a row vector if both\n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
4716 @var{base} and @var{limit} are scalars. If one, or both, of them are column\n\ |
9658
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4717 vectors, @code{linspace} returns a matrix.\n\ |
6630 | 4718 \n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
4719 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
|
4720 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
|
4721 @seealso{logspace}\n\ |
3369 | 4722 @end deftypefn") |
1100 | 4723 { |
3418 | 4724 octave_value retval; |
1100 | 4725 |
4726 int nargin = args.length (); | |
4727 | |
6133 | 4728 octave_idx_type npoints = 100; |
1100 | 4729 |
1940 | 4730 if (nargin != 2 && nargin != 3) |
4731 { | |
5823 | 4732 print_usage (); |
1940 | 4733 return retval; |
4734 } | |
4735 | |
1100 | 4736 if (nargin == 3) |
16077
39129305b914
provide some undocumented matlab behavior for linspace (bug #38151)
John W. Eaton <jwe@octave.org>
parents:
15623
diff
changeset
|
4737 { |
39129305b914
provide some undocumented matlab behavior for linspace (bug #38151)
John W. Eaton <jwe@octave.org>
parents:
15623
diff
changeset
|
4738 // 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
|
4739 // 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
|
4740 |
39129305b914
provide some undocumented matlab behavior for linspace (bug #38151)
John W. Eaton <jwe@octave.org>
parents:
15623
diff
changeset
|
4741 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
|
4742 |
39129305b914
provide some undocumented matlab behavior for linspace (bug #38151)
John W. Eaton <jwe@octave.org>
parents:
15623
diff
changeset
|
4743 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
|
4744 npoints = 1; |
39129305b914
provide some undocumented matlab behavior for linspace (bug #38151)
John W. Eaton <jwe@octave.org>
parents:
15623
diff
changeset
|
4745 else |
39129305b914
provide some undocumented matlab behavior for linspace (bug #38151)
John W. Eaton <jwe@octave.org>
parents:
15623
diff
changeset
|
4746 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
|
4747 } |
1100 | 4748 |
4749 if (! error_state) | |
4750 { | |
3322 | 4751 octave_value arg_1 = args(0); |
4752 octave_value arg_2 = args(1); | |
1100 | 4753 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7743
diff
changeset
|
4754 if (arg_1.is_single_type () || arg_2.is_single_type ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4755 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4756 if (arg_1.is_complex_type () || arg_2.is_complex_type ()) |
9658
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4757 retval = do_linspace<FloatComplexMatrix> (arg_1, arg_2, npoints); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4758 else |
9658
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4759 retval = do_linspace<FloatMatrix> (arg_1, arg_2, npoints); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
4760 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4761 } |
1100 | 4762 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4763 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4764 if (arg_1.is_complex_type () || arg_2.is_complex_type ()) |
9658
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4765 retval = do_linspace<ComplexMatrix> (arg_1, arg_2, npoints); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4766 else |
9658
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4767 retval = do_linspace<Matrix> (arg_1, arg_2, npoints); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4768 } |
1100 | 4769 } |
4732 | 4770 else |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11591
diff
changeset
|
4771 error ("linspace: N must be an integer"); |
1100 | 4772 |
4773 return retval; | |
4774 } | |
4775 | |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4776 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4777 /* |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4778 %!test |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4779 %! 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
|
4780 %! 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
|
4781 %! 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
|
4782 %! 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
|
4783 %! 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
|
4784 %! 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
|
4785 |
14521
3b19a952ab54
test: remove obsolete warning test for linspace.
Rik <octave@nomad.inbox5.com>
parents:
14520
diff
changeset
|
4786 %assert (linspace ([1, 2; 3, 4], 5, 6), linspace (1, 5, 6)) |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4787 |
16077
39129305b914
provide some undocumented matlab behavior for linspace (bug #38151)
John W. Eaton <jwe@octave.org>
parents:
15623
diff
changeset
|
4788 %assert (linspace (0, 1, []), 1) |
39129305b914
provide some undocumented matlab behavior for linspace (bug #38151)
John W. Eaton <jwe@octave.org>
parents:
15623
diff
changeset
|
4789 |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4790 %!error linspace () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
4791 %!error linspace (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
|
4792 */ |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4793 |
5775 | 4794 // FIXME -- should accept dimensions as separate args for N-d |
5734 | 4795 // arrays as well as 1-d and 2-d arrays. |
4796 | |
5731 | 4797 DEFUN (resize, args, , |
4798 "-*- texinfo -*-\n\ | |
10840 | 4799 @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
|
4800 @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
|
4801 @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
|
4802 Resize @var{x} cutting off elements as necessary.\n\ |
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
4803 \n\ |
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
4804 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
|
4805 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
|
4806 otherwise, the element is set to zero.\n\ |
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
4807 \n\ |
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
4808 In other words, the statement\n\ |
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
4809 \n\ |
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
4810 @example\n\ |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
4811 y = resize (x, dv)\n\ |
8799
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
4812 @end example\n\ |
6174 | 4813 \n\ |
8799
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
4814 @noindent\n\ |
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
4815 is equivalent to the following code:\n\ |
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
4816 \n\ |
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
4817 @example\n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
9041
diff
changeset
|
4818 @group\n\ |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
4819 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
|
4820 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
|
4821 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
|
4822 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
|
4823 endfor\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
4824 y(idx@{:@}) = x(idx@{:@});\n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
9041
diff
changeset
|
4825 @end group\n\ |
8799
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
4826 @end example\n\ |
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
4827 \n\ |
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
4828 @noindent\n\ |
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
4829 but is performed more efficiently.\n\ |
6174 | 4830 \n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
4831 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
|
4832 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
|
4833 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
|
4834 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
|
4835 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
|
4836 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
|
4837 \n\ |
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
4838 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
|
4839 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
|
4840 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
|
4841 @seealso{reshape, postpad, prepad, cat}\n\ |
5731 | 4842 @end deftypefn") |
4843 { | |
4844 octave_value retval; | |
4845 int nargin = args.length (); | |
4846 | |
4847 if (nargin == 2) | |
4848 { | |
4849 Array<double> vec = args(1).vector_value (); | |
4850 int ndim = vec.length (); | |
4851 if (ndim == 1) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4852 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4853 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
|
4854 retval = args(0); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4855 retval = retval.resize (dim_vector (m, m), true); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4856 } |
5731 | 4857 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4858 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4859 dim_vector dv; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4860 dv.resize (ndim); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4861 for (int i = 0; i < ndim; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4862 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
|
4863 retval = args(0); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4864 retval = retval.resize (dv, true); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4865 } |
5731 | 4866 } |
8799
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
4867 else if (nargin > 2) |
5731 | 4868 { |
8799
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
4869 dim_vector dv; |
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
4870 dv.resize (nargin - 1); |
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
4871 for (octave_idx_type i = 1; i < nargin; i++) |
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
4872 dv(i-1) = static_cast<octave_idx_type> (args(i).scalar_value ()); |
5731 | 4873 if (!error_state) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4874 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4875 retval = args(0); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4876 retval = retval.resize (dv, true); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4877 } |
8799
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
4878 |
5731 | 4879 } |
4880 else | |
5823 | 4881 print_usage (); |
5731 | 4882 return retval; |
4883 } | |
4884 | |
5775 | 4885 // FIXME -- should use octave_idx_type for dimensions. |
5734 | 4886 |
4567 | 4887 DEFUN (reshape, args, , |
4888 "-*- texinfo -*-\n\ | |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
4889 @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
|
4890 @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
|
4891 @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
|
4892 @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
|
4893 Return a matrix with the specified dimensions (@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
|
4894 whose elements are taken from the matrix @var{A}. The elements of the\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
4895 matrix are accessed in column-major order (like Fortran arrays are stored).\n\ |
4567 | 4896 \n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
4897 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
|
4898 matrix.\n\ |
4567 | 4899 \n\ |
4900 @example\n\ | |
4901 @group\n\ | |
4902 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
|
4903 @result{} 1 3\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
4904 2 4\n\ |
4567 | 4905 @end group\n\ |
4906 @end example\n\ | |
4907 \n\ | |
4908 @noindent\n\ | |
4909 Note that the total number of elements in the original\n\ | |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
4910 matrix (@code{prod (size (@var{A}))}) must match the total number of elements\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
4911 in the new matrix (@code{prod ([@var{m} @var{n} @dots{}])}).\n\ |
5013 | 4912 \n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
4913 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
|
4914 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
|
4915 the unspecified dimension.\n\ |
15028
397f0d80bd47
Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents:
15024
diff
changeset
|
4916 @seealso{resize, vec, postpad, cat, squeeze}\n\ |
4567 | 4917 @end deftypefn") |
4918 { | |
4919 octave_value retval; | |
4920 | |
4921 int nargin = args.length (); | |
4922 | |
10693 | 4923 dim_vector new_dims; |
4567 | 4924 |
4925 if (nargin == 2) | |
10693 | 4926 { |
4927 Array<octave_idx_type> new_size = args(1).octave_idx_type_vector_value (); | |
4928 | |
4929 new_dims = dim_vector::alloc (new_size.length ()); | |
4930 | |
4931 for (octave_idx_type i = 0; i < new_size.length (); i++) | |
4932 { | |
4933 if (new_size(i) < 0) | |
4934 { | |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11591
diff
changeset
|
4935 error ("reshape: SIZE must be non-negative"); |
10693 | 4936 break; |
4937 } | |
4938 else | |
4939 new_dims(i) = new_size(i); | |
4940 } | |
4941 } | |
4567 | 4942 else if (nargin > 2) |
4943 { | |
10693 | 4944 new_dims = dim_vector::alloc (nargin-1); |
5013 | 4945 int empty_dim = -1; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
4946 |
4567 | 4947 for (int i = 1; i < nargin; i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4948 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4949 if (args(i).is_empty ()) |
10693 | 4950 { |
4951 if (empty_dim > 0) | |
4952 { | |
4953 error ("reshape: only a single dimension can be unknown"); | |
4954 break; | |
4955 } | |
4956 else | |
4957 { | |
4958 empty_dim = i; | |
4959 new_dims(i-1) = 1; | |
4960 } | |
4961 } | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4962 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4963 { |
10693 | 4964 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
|
4965 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4966 if (error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4967 break; |
10693 | 4968 else if (new_dims(i-1) < 0) |
4969 { | |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11591
diff
changeset
|
4970 error ("reshape: SIZE must be non-negative"); |
10693 | 4971 break; |
4972 } | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4973 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4974 } |
5013 | 4975 |
4976 if (! error_state && (empty_dim > 0)) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4977 { |
10693 | 4978 octave_idx_type nel = new_dims.numel (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4979 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4980 if (nel == 0) |
10693 | 4981 new_dims(empty_dim-1) = 0; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4982 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4983 { |
10693 | 4984 octave_idx_type a_nel = args(0).numel (); |
4985 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
|
4986 |
10693 | 4987 if (a_nel != size_empty_dim * nel) |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11591
diff
changeset
|
4988 error ("reshape: SIZE is not divisible by the product of known dimensions (= %d)", nel); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4989 else |
10693 | 4990 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
|
4991 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4992 } |
4567 | 4993 } |
4994 else | |
4995 { | |
5823 | 4996 print_usage (); |
4567 | 4997 return retval; |
4998 } | |
4999 | |
10352 | 5000 if (! error_state) |
5001 retval = args(0).reshape (new_dims); | |
4567 | 5002 |
5003 return retval; | |
5004 } | |
5005 | |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5006 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5007 %!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
|
5008 %!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
|
5009 %!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
|
5010 %!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
|
5011 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5012 %!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
|
5013 %!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
|
5014 %!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
|
5015 %!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
|
5016 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5017 %!test |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5018 %! s.a = 1; |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5019 %! fail ("reshape (s, 2, 3)"); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5020 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5021 %!error reshape () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5022 %!error reshape (1, 2, 3, 4) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5023 */ |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5024 |
10694
d97165928d05
implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents:
10693
diff
changeset
|
5025 DEFUN (vec, args, , |
d97165928d05
implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents:
10693
diff
changeset
|
5026 "-*- texinfo -*-\n\ |
12578
f5a780d675a1
Clean up operator and function indices in documentation.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
5027 @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
|
5028 @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
|
5029 Return the vector obtained by stacking the columns of the matrix @var{x}\n\ |
11402
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
5030 one above the other. Without @var{dim} this is equivalent to\n\ |
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
5031 @code{@var{x}(:)}. If @var{dim} is supplied, the dimensions of @var{v}\n\ |
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
5032 are set to @var{dim} with all elements along the last dimension.\n\ |
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
5033 This is equivalent to @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
|
5034 @seealso{vech, resize, cat}\n\ |
10694
d97165928d05
implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents:
10693
diff
changeset
|
5035 @end deftypefn") |
d97165928d05
implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents:
10693
diff
changeset
|
5036 { |
d97165928d05
implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents:
10693
diff
changeset
|
5037 octave_value retval; |
11402
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
5038 int dim = 1; |
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
5039 |
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
5040 int nargin = args.length (); |
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
5041 |
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
5042 if (nargin < 1 || nargin > 2) |
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
5043 print_usage () ; |
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
5044 |
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
5045 if (! error_state && nargin == 2) |
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
5046 { |
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
5047 dim = args(1).idx_type_value (); |
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
5048 |
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
5049 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
|
5050 error ("vec: DIM must be greater than zero"); |
11402
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
5051 } |
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
5052 |
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
5053 if (! error_state) |
10694
d97165928d05
implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents:
10693
diff
changeset
|
5054 { |
d97165928d05
implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents:
10693
diff
changeset
|
5055 octave_value colon (octave_value::magic_colon_t); |
d97165928d05
implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents:
10693
diff
changeset
|
5056 octave_value arg = args(0); |
d97165928d05
implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents:
10693
diff
changeset
|
5057 retval = arg.single_subsref ("(", colon); |
11402
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
5058 |
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
5059 |
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
5060 if (! error_state && dim > 1) |
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
5061 { |
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
5062 dim_vector new_dims = dim_vector::alloc (dim); |
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
5063 |
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
5064 for (int i = 0; i < dim-1; i++) |
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
5065 new_dims(i) = 1; |
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
5066 |
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
5067 new_dims(dim-1) = retval.numel (); |
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
5068 |
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
5069 retval = retval.reshape (new_dims); |
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
5070 } |
10694
d97165928d05
implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents:
10693
diff
changeset
|
5071 } |
d97165928d05
implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents:
10693
diff
changeset
|
5072 |
d97165928d05
implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents:
10693
diff
changeset
|
5073 return retval; |
d97165928d05
implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents:
10693
diff
changeset
|
5074 } |
d97165928d05
implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents:
10693
diff
changeset
|
5075 |
d97165928d05
implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents:
10693
diff
changeset
|
5076 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5077 %!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
|
5078 %!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
|
5079 %!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
|
5080 %!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
|
5081 %!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
|
5082 %!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
|
5083 %!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
|
5084 %!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
|
5085 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5086 %!error vec () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5087 %!error vec (1, 2, 3) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5088 %!error vec ([1, 2; 3, 4], 0) |
10694
d97165928d05
implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents:
10693
diff
changeset
|
5089 */ |
d97165928d05
implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents:
10693
diff
changeset
|
5090 |
4532 | 5091 DEFUN (squeeze, args, , |
5092 "-*- texinfo -*-\n\ | |
5093 @deftypefn {Built-in Function} {} squeeze (@var{x})\n\ | |
5094 Remove singleton dimensions from @var{x} and return the result.\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
9041
diff
changeset
|
5095 Note that for compatibility with @sc{matlab}, all objects have\n\ |
7007 | 5096 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
|
5097 @seealso{reshape}\n\ |
4532 | 5098 @end deftypefn") |
5099 { | |
5100 octave_value retval; | |
5101 | |
5102 if (args.length () == 1) | |
4545 | 5103 retval = args(0).squeeze (); |
4532 | 5104 else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
5105 print_usage (); |
4532 | 5106 |
5107 return retval; | |
5108 } | |
5109 | |
8458
d254a21e0120
reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents:
8433
diff
changeset
|
5110 DEFUN (full, args, , |
d254a21e0120
reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents:
8433
diff
changeset
|
5111 "-*- 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
|
5112 @deftypefn {Built-in Function} {@var{FM} =} full (@var{SM})\n\ |
12575
d0b799dafede
Grammarcheck files for 3.4.1 release.
Rik <octave@nomad.inbox5.com>
parents:
12571
diff
changeset
|
5113 Return a full storage matrix from a sparse, diagonal, permutation matrix\n\ |
10846
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10840
diff
changeset
|
5114 or a range.\n\ |
8458
d254a21e0120
reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents:
8433
diff
changeset
|
5115 @seealso{sparse}\n\ |
d254a21e0120
reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents:
8433
diff
changeset
|
5116 @end deftypefn") |
d254a21e0120
reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents:
8433
diff
changeset
|
5117 { |
d254a21e0120
reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents:
8433
diff
changeset
|
5118 octave_value retval; |
d254a21e0120
reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents:
8433
diff
changeset
|
5119 |
d254a21e0120
reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents:
8433
diff
changeset
|
5120 if (args.length () == 1) |
d254a21e0120
reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents:
8433
diff
changeset
|
5121 retval = args(0).full_value (); |
d254a21e0120
reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents:
8433
diff
changeset
|
5122 else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
5123 print_usage (); |
8458
d254a21e0120
reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents:
8433
diff
changeset
|
5124 |
d254a21e0120
reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents:
8433
diff
changeset
|
5125 return retval; |
d254a21e0120
reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents:
8433
diff
changeset
|
5126 } |
d254a21e0120
reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents:
8433
diff
changeset
|
5127 |
6945 | 5128 // Compute various norms of the vector X. |
5129 | |
6953 | 5130 DEFUN (norm, args, , |
6508 | 5131 "-*- texinfo -*-\n\ |
12584
7ef7e20057fa
Improve documentation strings in Linear Algebra chapter.
Rik <octave@nomad.inbox5.com>
parents:
12578
diff
changeset
|
5132 @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
|
5133 @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
|
5134 @deftypefnx {Built-in Function} {} norm (@var{A}, @var{p}, @var{opt})\n\ |
7ef7e20057fa
Improve documentation strings in Linear Algebra chapter.
Rik <octave@nomad.inbox5.com>
parents:
12578
diff
changeset
|
5135 Compute the p-norm of the matrix @var{A}. If the second argument is\n\ |
6953 | 5136 missing, @code{p = 2} is assumed.\n\ |
5137 \n\ | |
12584
7ef7e20057fa
Improve documentation strings in Linear Algebra chapter.
Rik <octave@nomad.inbox5.com>
parents:
12578
diff
changeset
|
5138 If @var{A} is a matrix (or sparse matrix):\n\ |
6953 | 5139 \n\ |
5140 @table @asis\n\ | |
5141 @item @var{p} = @code{1}\n\ | |
12584
7ef7e20057fa
Improve documentation strings in Linear Algebra chapter.
Rik <octave@nomad.inbox5.com>
parents:
12578
diff
changeset
|
5142 1-norm, the largest column sum of the absolute values of @var{A}.\n\ |
6953 | 5143 \n\ |
5144 @item @var{p} = @code{2}\n\ | |
12584
7ef7e20057fa
Improve documentation strings in Linear Algebra chapter.
Rik <octave@nomad.inbox5.com>
parents:
12578
diff
changeset
|
5145 Largest singular value of @var{A}.\n\ |
6953 | 5146 \n\ |
7189 | 5147 @item @var{p} = @code{Inf} or @code{\"inf\"}\n\ |
6953 | 5148 @cindex infinity norm\n\ |
12584
7ef7e20057fa
Improve documentation strings in Linear Algebra chapter.
Rik <octave@nomad.inbox5.com>
parents:
12578
diff
changeset
|
5149 Infinity norm, the largest row sum of the absolute values of @var{A}.\n\ |
6953 | 5150 \n\ |
5151 @item @var{p} = @code{\"fro\"}\n\ | |
5152 @cindex Frobenius norm\n\ | |
12584
7ef7e20057fa
Improve documentation strings in Linear Algebra chapter.
Rik <octave@nomad.inbox5.com>
parents:
12578
diff
changeset
|
5153 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
|
5154 \n\ |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
5155 @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
|
5156 @cindex general p-norm\n\ |
8303
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
5157 maximum @code{norm (A*x, p)} such that @code{norm (x, p) == 1}\n\ |
6953 | 5158 @end table\n\ |
5159 \n\ | |
12584
7ef7e20057fa
Improve documentation strings in Linear Algebra chapter.
Rik <octave@nomad.inbox5.com>
parents:
12578
diff
changeset
|
5160 If @var{A} is a vector or a scalar:\n\ |
6953 | 5161 \n\ |
5162 @table @asis\n\ | |
7189 | 5163 @item @var{p} = @code{Inf} or @code{\"inf\"}\n\ |
12584
7ef7e20057fa
Improve documentation strings in Linear Algebra chapter.
Rik <octave@nomad.inbox5.com>
parents:
12578
diff
changeset
|
5164 @code{max (abs (@var{A}))}.\n\ |
6953 | 5165 \n\ |
5166 @item @var{p} = @code{-Inf}\n\ | |
12584
7ef7e20057fa
Improve documentation strings in Linear Algebra chapter.
Rik <octave@nomad.inbox5.com>
parents:
12578
diff
changeset
|
5167 @code{min (abs (@var{A}))}.\n\ |
6953 | 5168 \n\ |
7189 | 5169 @item @var{p} = @code{\"fro\"}\n\ |
12584
7ef7e20057fa
Improve documentation strings in Linear Algebra chapter.
Rik <octave@nomad.inbox5.com>
parents:
12578
diff
changeset
|
5170 Frobenius norm of @var{A}, @code{sqrt (sumsq (abs (A)))}.\n\ |
7189 | 5171 \n\ |
8303
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
5172 @item @var{p} = 0\n\ |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
5173 Hamming norm - the number of nonzero elements.\n\ |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
5174 \n\ |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
5175 @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
|
5176 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
|
5177 \n\ |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
5178 @item other @var{p} @code{@var{p} < 1}\n\ |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
5179 the p-pseudonorm defined as above.\n\ |
6953 | 5180 @end table\n\ |
8303
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
5181 \n\ |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
5182 If @var{opt} is the value @code{\"rows\"}, treat each row as a vector and\n\ |
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
5183 compute its norm. The result is returned as a column vector.\n\ |
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
5184 Similarly, if @var{opt} is @code{\"columns\"} or @code{\"cols\"} then compute\n\ |
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
5185 the norms of each column and return a row vector.\n\ |
6953 | 5186 @seealso{cond, svd}\n\ |
6508 | 5187 @end deftypefn") |
5188 { | |
6953 | 5189 octave_value_list retval; |
6508 | 5190 |
5191 int nargin = args.length (); | |
5192 | |
8303
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
5193 if (nargin >= 1 && nargin <= 3) |
6508 | 5194 { |
6953 | 5195 octave_value x_arg = args(0); |
5196 | |
10185
455759a5fcbe
fix norm and svd on empty matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10182
diff
changeset
|
5197 if (x_arg.ndims () == 2) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5198 { |
8303
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
5199 enum { sfmatrix, sfcols, sfrows, sffrob, sfinf } strflag = sfmatrix; |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
5200 if (nargin > 1 && args(nargin-1).is_string ()) |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
5201 { |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
5202 std::string str = args(nargin-1).string_value (); |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
5203 if (str == "cols" || str == "columns") |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
5204 strflag = sfcols; |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
5205 else if (str == "rows") |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
5206 strflag = sfrows; |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
5207 else if (str == "fro") |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
5208 strflag = sffrob; |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
5209 else if (str == "inf") |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
5210 strflag = sfinf; |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
5211 else |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
5212 error ("norm: unrecognized option: %s", str.c_str ()); |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
5213 // 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
|
5214 nargin --; |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
5215 } |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
5216 |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
5217 if (! error_state) |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
5218 { |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
5219 octave_value p_arg = (nargin > 1) ? args(1) : octave_value (2); |
17115
00985134145e
norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents:
16892
diff
changeset
|
5220 |
00985134145e
norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents:
16892
diff
changeset
|
5221 if (p_arg.is_empty ()) |
00985134145e
norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents:
16892
diff
changeset
|
5222 p_arg = octave_value (2); |
00985134145e
norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents:
16892
diff
changeset
|
5223 else if (p_arg.is_string ()) |
8303
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
5224 { |
17115
00985134145e
norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents:
16892
diff
changeset
|
5225 std::string str = p_arg.string_value (); |
00985134145e
norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents:
16892
diff
changeset
|
5226 if ((strflag == sfcols || strflag == sfrows)) |
00985134145e
norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents:
16892
diff
changeset
|
5227 { |
00985134145e
norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents:
16892
diff
changeset
|
5228 if (str == "cols" || str == "columns" || str == "rows") |
00985134145e
norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents:
16892
diff
changeset
|
5229 error ("norm: invalid combination of options"); |
00985134145e
norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents:
16892
diff
changeset
|
5230 else if (str == "fro") |
00985134145e
norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents:
16892
diff
changeset
|
5231 p_arg = octave_value (2); |
00985134145e
norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents:
16892
diff
changeset
|
5232 else if (str == "inf") |
00985134145e
norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents:
16892
diff
changeset
|
5233 p_arg = octave_Inf; |
00985134145e
norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents:
16892
diff
changeset
|
5234 else |
00985134145e
norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents:
16892
diff
changeset
|
5235 error ("norm: unrecognized option: %s", str.c_str ()); |
00985134145e
norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents:
16892
diff
changeset
|
5236 } |
00985134145e
norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents:
16892
diff
changeset
|
5237 else |
00985134145e
norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents:
16892
diff
changeset
|
5238 error ("norm: invalid combination of options"); |
00985134145e
norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents:
16892
diff
changeset
|
5239 } |
00985134145e
norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents:
16892
diff
changeset
|
5240 else if (! p_arg.is_scalar_type ()) |
00985134145e
norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents:
16892
diff
changeset
|
5241 gripe_wrong_type_arg ("norm", p_arg, true); |
00985134145e
norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents:
16892
diff
changeset
|
5242 |
00985134145e
norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents:
16892
diff
changeset
|
5243 if (! error_state) |
00985134145e
norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents:
16892
diff
changeset
|
5244 { |
00985134145e
norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents:
16892
diff
changeset
|
5245 switch (strflag) |
00985134145e
norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents:
16892
diff
changeset
|
5246 { |
00985134145e
norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents:
16892
diff
changeset
|
5247 case sfmatrix: |
00985134145e
norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents:
16892
diff
changeset
|
5248 retval(0) = xnorm (x_arg, p_arg); |
00985134145e
norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents:
16892
diff
changeset
|
5249 break; |
00985134145e
norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents:
16892
diff
changeset
|
5250 case sfcols: |
00985134145e
norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents:
16892
diff
changeset
|
5251 retval(0) = xcolnorms (x_arg, p_arg); |
00985134145e
norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents:
16892
diff
changeset
|
5252 break; |
00985134145e
norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents:
16892
diff
changeset
|
5253 case sfrows: |
00985134145e
norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents:
16892
diff
changeset
|
5254 retval(0) = xrownorms (x_arg, p_arg); |
00985134145e
norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents:
16892
diff
changeset
|
5255 break; |
00985134145e
norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents:
16892
diff
changeset
|
5256 case sffrob: |
00985134145e
norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents:
16892
diff
changeset
|
5257 retval(0) = xfrobnorm (x_arg); |
00985134145e
norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents:
16892
diff
changeset
|
5258 break; |
00985134145e
norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents:
16892
diff
changeset
|
5259 case sfinf: |
00985134145e
norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents:
16892
diff
changeset
|
5260 retval(0) = xnorm (x_arg, octave_Inf); |
00985134145e
norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents:
16892
diff
changeset
|
5261 break; |
00985134145e
norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents:
16892
diff
changeset
|
5262 } |
8303
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
5263 } |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
5264 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5265 } |
6508 | 5266 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5267 error ("norm: only valid for 2-D objects"); |
6508 | 5268 } |
5269 else | |
5270 print_usage (); | |
5271 | |
5272 return retval; | |
5273 } | |
5274 | |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5275 /* |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5276 %!shared x |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5277 %! 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
|
5278 %!assert (norm (x,1), 20) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5279 %!assert (norm (x,2), 10) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5280 %!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
|
5281 %!assert (norm (x,Inf), 7) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5282 %!assert (norm (x,-Inf), 1) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5283 %!assert (norm (x,"inf"), 7) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5284 %!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
|
5285 %!assert (norm (x), 10) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5286 %!assert (norm ([1e200, 1]), 1e200) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5287 %!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
|
5288 %!shared m |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5289 %! m = magic (4); |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5290 %!assert (norm (m,1), 34) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5291 %!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
|
5292 %!assert (norm (m,Inf), 34) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5293 %!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
|
5294 %!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
|
5295 %! 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
|
5296 %! 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
|
5297 %! fhi = 1e+300; |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5298 %!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
|
5299 %!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
|
5300 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5301 %!shared x |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5302 %! 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
|
5303 %!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
|
5304 %!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
|
5305 %!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
|
5306 %!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
|
5307 %!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
|
5308 %!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
|
5309 %!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
|
5310 %!assert (norm (x), single (10)) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5311 %!assert (norm (single ([1e200, 1])), single (1e200)) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5312 %!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
|
5313 %!shared m |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5314 %! m = single (magic (4)); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5315 %!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
|
5316 %!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
|
5317 %!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
|
5318 %!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
|
5319 %!shared m2, flo, fhi |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5320 %! 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
|
5321 %! flo = single (1e-300); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5322 %! fhi = single (1e+300); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5323 %!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
|
5324 %!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
|
5325 |
17115
00985134145e
norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents:
16892
diff
changeset
|
5326 %!shared q |
00985134145e
norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents:
16892
diff
changeset
|
5327 %! q = rand (1e3, 3); |
00985134145e
norm: fix argument handling to match the docstring (bug #34778)
Mike Miller <mtmiller@ieee.org>
parents:
16892
diff
changeset
|
5328 %!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
|
5329 %!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
|
5330 %!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
|
5331 %!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
|
5332 %!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
|
5333 %!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
|
5334 %!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
|
5335 %!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
|
5336 %!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
|
5337 |
14520
c4ed0fdf2b62
Fix initialization in Higham's method for norm estimate (bug #36031).
Marco Caliari <marco.caliari@univr.it>
parents:
14491
diff
changeset
|
5338 %!test |
c4ed0fdf2b62
Fix initialization in Higham's method for norm estimate (bug #36031).
Marco Caliari <marco.caliari@univr.it>
parents:
14491
diff
changeset
|
5339 %! ## Test for norm returning NaN on sparse matrix (bug #30631) |
c4ed0fdf2b62
Fix initialization in Higham's method for norm estimate (bug #36031).
Marco Caliari <marco.caliari@univr.it>
parents:
14491
diff
changeset
|
5340 %! A = sparse (2,2); |
c4ed0fdf2b62
Fix initialization in Higham's method for norm estimate (bug #36031).
Marco Caliari <marco.caliari@univr.it>
parents:
14491
diff
changeset
|
5341 %! 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
|
5342 %! 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
|
5343 */ |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5344 |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5345 static octave_value |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5346 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
|
5347 const octave_value_list& args) |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5348 { |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5349 octave_value retval; |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5350 if (args.length () == 1) |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5351 retval = do_unary_op (op, args(0)); |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5352 else |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5353 print_usage (); |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5354 |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5355 return retval; |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5356 } |
6518 | 5357 |
5358 DEFUN (not, args, , | |
5359 "-*- texinfo -*-\n\ | |
5360 @deftypefn {Built-in Function} {} not (@var{x})\n\ | |
11422
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
5361 Return the logical NOT of @var{x}. This function is equivalent to\n\ |
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
5362 @code{! x}.\n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
5363 @seealso{and, or, xor}\n\ |
6518 | 5364 @end deftypefn") |
5365 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5366 return unary_op_defun_body (octave_value::op_not, args); |
6518 | 5367 } |
5368 | |
5369 DEFUN (uplus, args, , | |
5370 "-*- texinfo -*-\n\ | |
5371 @deftypefn {Built-in Function} {} uplus (@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
|
5372 This function and @w{@xcode{+ x}} are equivalent.\n\ |
15028
397f0d80bd47
Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents:
15024
diff
changeset
|
5373 @seealso{uminus, plus, minus}\n\ |
6518 | 5374 @end deftypefn") |
5375 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5376 return unary_op_defun_body (octave_value::op_uplus, args); |
6518 | 5377 } |
5378 | |
5379 DEFUN (uminus, args, , | |
5380 "-*- texinfo -*-\n\ | |
5381 @deftypefn {Built-in Function} {} uminus (@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
|
5382 This function and @w{@xcode{- x}} are equivalent.\n\ |
15028
397f0d80bd47
Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents:
15024
diff
changeset
|
5383 @seealso{uplus, minus}\n\ |
6518 | 5384 @end deftypefn") |
5385 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5386 return unary_op_defun_body (octave_value::op_uminus, args); |
6518 | 5387 } |
5388 | |
5389 DEFUN (transpose, args, , | |
5390 "-*- texinfo -*-\n\ | |
5391 @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
|
5392 Return the transpose of @var{x}.\n\ |
990762e784fe
Fix confusing interaction between @code macro and transpose operator (') in documentation (Bug #34661).
Rik <octave@nomad.inbox5.com>
parents:
13760
diff
changeset
|
5393 This function and @xcode{x.'} are equivalent.\n\ |
11422
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
5394 @seealso{ctranspose}\n\ |
6518 | 5395 @end deftypefn") |
5396 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5397 return unary_op_defun_body (octave_value::op_transpose, args); |
6518 | 5398 } |
5399 | |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5400 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5401 %!assert (2.', 2) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5402 %!assert (2i.', 2i) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5403 %!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
|
5404 %!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
|
5405 %!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
|
5406 %!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
|
5407 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5408 %!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
|
5409 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5410 %!assert (single (2).', single (2)) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5411 %!assert (single (2i).', single (2i)) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5412 %!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
|
5413 %!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
|
5414 %!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
|
5415 %!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
|
5416 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5417 %!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
|
5418 */ |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5419 |
6518 | 5420 DEFUN (ctranspose, args, , |
5421 "-*- texinfo -*-\n\ | |
5422 @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
|
5423 Return the complex conjugate transpose of @var{x}.\n\ |
990762e784fe
Fix confusing interaction between @code macro and transpose operator (') in documentation (Bug #34661).
Rik <octave@nomad.inbox5.com>
parents:
13760
diff
changeset
|
5424 This function and @xcode{x'} are equivalent.\n\ |
11422
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
5425 @seealso{transpose}\n\ |
6518 | 5426 @end deftypefn") |
5427 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5428 return unary_op_defun_body (octave_value::op_hermitian, args); |
6518 | 5429 } |
5430 | |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5431 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5432 %!assert (2', 2) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5433 %!assert (2i', -2i) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5434 %!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
|
5435 %!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
|
5436 %!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
|
5437 %!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
|
5438 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5439 %!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
|
5440 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5441 %!assert (single (2)', single (2)) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5442 %!assert (single (2i)', single (-2i)) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5443 %!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
|
5444 %!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
|
5445 %!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
|
5446 %!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
|
5447 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
5448 %!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
|
5449 */ |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5450 |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5451 static octave_value |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5452 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
|
5453 const octave_value_list& args) |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5454 { |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5455 octave_value retval; |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5456 |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5457 if (args.length () == 2) |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5458 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
|
5459 else |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5460 print_usage (); |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5461 |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5462 return retval; |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5463 } |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5464 |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5465 static octave_value |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5466 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
|
5467 octave_value::assign_op aop, |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5468 const octave_value_list& args) |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5469 { |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5470 octave_value retval; |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5471 int nargin = args.length (); |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5472 |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5473 switch (nargin) |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5474 { |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5475 case 0: |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5476 print_usage (); |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5477 break; |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5478 case 1: |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5479 retval = args(0); |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5480 break; |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5481 case 2: |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5482 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
|
5483 break; |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5484 default: |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5485 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
|
5486 for (int i = 2; i < nargin; i++) |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5487 retval.assign (aop, args(i)); |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5488 break; |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5489 } |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5490 |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5491 return retval; |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5492 } |
9339
c0b104835d0d
allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
5493 |
6518 | 5494 DEFUN (plus, args, , |
5495 "-*- texinfo -*-\n\ | |
10840 | 5496 @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
|
5497 @deftypefnx {Built-in Function} {} plus (@var{x1}, @var{x2}, @dots{})\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
|
5498 This function and @w{@xcode{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
|
5499 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
|
5500 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
|
5501 \n\ |
c0b104835d0d
allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
5502 @example\n\ |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
5503 (@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
|
5504 @end example\n\ |
c0b104835d0d
allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
5505 \n\ |
11422
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
5506 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
|
5507 @seealso{minus, uplus}\n\ |
6518 | 5508 @end deftypefn") |
5509 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5510 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
|
5511 octave_value::op_add_eq, args); |
6518 | 5512 } |
5513 | |
5514 DEFUN (minus, args, , | |
5515 "-*- texinfo -*-\n\ | |
5516 @deftypefn {Built-in Function} {} minus (@var{x}, @var{y})\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
|
5517 This function and @w{@xcode{x - y}} are equivalent.\n\ |
15028
397f0d80bd47
Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents:
15024
diff
changeset
|
5518 @seealso{plus, uminus}\n\ |
6518 | 5519 @end deftypefn") |
5520 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5521 return binary_op_defun_body (octave_value::op_sub, args); |
6518 | 5522 } |
5523 | |
5524 DEFUN (mtimes, args, , | |
5525 "-*- texinfo -*-\n\ | |
10840 | 5526 @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
|
5527 @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
|
5528 Return the matrix multiplication product of inputs.\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
|
5529 This function and @w{@xcode{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
|
5530 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
|
5531 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
|
5532 \n\ |
c0b104835d0d
allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
5533 @example\n\ |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
5534 (@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
|
5535 @end example\n\ |
c0b104835d0d
allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
5536 \n\ |
11575
d6619410e79c
Spellcheck documentation before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents:
11572
diff
changeset
|
5537 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
|
5538 @seealso{times, plus, minus, rdivide, mrdivide, mldivide, mpower}\n\ |
6518 | 5539 @end deftypefn") |
5540 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5541 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
|
5542 octave_value::op_mul_eq, args); |
6518 | 5543 } |
5544 | |
5545 DEFUN (mrdivide, args, , | |
5546 "-*- texinfo -*-\n\ | |
5547 @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
|
5548 Return the matrix right division of @var{x} and @var{y}.\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
|
5549 This function and @w{@xcode{x / y}} are equivalent.\n\ |
15028
397f0d80bd47
Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents:
15024
diff
changeset
|
5550 @seealso{mldivide, rdivide, plus, minus}\n\ |
6518 | 5551 @end deftypefn") |
5552 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5553 return binary_op_defun_body (octave_value::op_div, args); |
6518 | 5554 } |
5555 | |
5556 DEFUN (mpower, args, , | |
5557 "-*- texinfo -*-\n\ | |
5558 @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
|
5559 Return the matrix power operation of @var{x} raised to the @var{y} power.\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
|
5560 This function and @w{@xcode{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
|
5561 @seealso{power, mtimes, plus, minus}\n\ |
6518 | 5562 @end deftypefn") |
5563 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5564 return binary_op_defun_body (octave_value::op_pow, args); |
6518 | 5565 } |
5566 | |
5567 DEFUN (mldivide, args, , | |
5568 "-*- texinfo -*-\n\ | |
5569 @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
|
5570 Return the matrix left division of @var{x} and @var{y}.\n\ |
14615
88e67d58b06b
avoid makeinfo problem with backslash in macro argument
John W. Eaton <jwe@octave.org>
parents:
14569
diff
changeset
|
5571 This function and @w{@xcode{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
|
5572 @seealso{mrdivide, ldivide, rdivide}\n\ |
6518 | 5573 @end deftypefn") |
5574 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5575 return binary_op_defun_body (octave_value::op_ldiv, args); |
6518 | 5576 } |
5577 | |
5578 DEFUN (lt, args, , | |
5579 "-*- texinfo -*-\n\ | |
5580 @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
|
5581 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
|
5582 @seealso{le, eq, ge, gt, ne}\n\ |
6518 | 5583 @end deftypefn") |
5584 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5585 return binary_op_defun_body (octave_value::op_lt, args); |
6518 | 5586 } |
5587 | |
5588 DEFUN (le, args, , | |
5589 "-*- texinfo -*-\n\ | |
5590 @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
|
5591 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
|
5592 @seealso{eq, ge, gt, ne, lt}\n\ |
6518 | 5593 @end deftypefn") |
5594 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5595 return binary_op_defun_body (octave_value::op_le, args); |
6518 | 5596 } |
5597 | |
5598 DEFUN (eq, args, , | |
5599 "-*- texinfo -*-\n\ | |
5600 @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
|
5601 Return true if the two inputs are equal.\n\ |
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
5602 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
|
5603 @seealso{ne, isequal, le, ge, gt, ne, lt}\n\ |
6518 | 5604 @end deftypefn") |
5605 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5606 return binary_op_defun_body (octave_value::op_eq, args); |
6518 | 5607 } |
5608 | |
5609 DEFUN (ge, args, , | |
5610 "-*- texinfo -*-\n\ | |
5611 @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
|
5612 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
|
5613 @seealso{le, eq, gt, ne, lt}\n\ |
6518 | 5614 @end deftypefn") |
5615 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5616 return binary_op_defun_body (octave_value::op_ge, args); |
6518 | 5617 } |
5618 | |
5619 DEFUN (gt, args, , | |
5620 "-*- texinfo -*-\n\ | |
5621 @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
|
5622 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
|
5623 @seealso{le, eq, ge, ne, lt}\n\ |
6518 | 5624 @end deftypefn") |
5625 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5626 return binary_op_defun_body (octave_value::op_gt, args); |
6518 | 5627 } |
5628 | |
5629 DEFUN (ne, args, , | |
5630 "-*- texinfo -*-\n\ | |
5631 @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
|
5632 Return true if the two inputs are not equal.\n\ |
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
5633 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
|
5634 @seealso{eq, isequal, le, ge, lt}\n\ |
6518 | 5635 @end deftypefn") |
5636 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5637 return binary_op_defun_body (octave_value::op_ne, args); |
6518 | 5638 } |
5639 | |
5640 DEFUN (times, args, , | |
5641 "-*- texinfo -*-\n\ | |
10840 | 5642 @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
|
5643 @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
|
5644 Return the element-by-element multiplication product of inputs.\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
|
5645 This function and @w{@xcode{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
|
5646 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
|
5647 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
|
5648 \n\ |
c0b104835d0d
allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
5649 @example\n\ |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
5650 (@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
|
5651 @end example\n\ |
c0b104835d0d
allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
5652 \n\ |
11422
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
5653 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
|
5654 @seealso{mtimes, rdivide}\n\ |
6518 | 5655 @end deftypefn") |
5656 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5657 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
|
5658 octave_value::op_el_mul_eq, args); |
6518 | 5659 } |
5660 | |
5661 DEFUN (rdivide, args, , | |
5662 "-*- texinfo -*-\n\ | |
5663 @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
|
5664 Return the element-by-element right division of @var{x} and @var{y}.\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
|
5665 This function and @w{@xcode{x ./ y}} are equivalent.\n\ |
15028
397f0d80bd47
Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents:
15024
diff
changeset
|
5666 @seealso{ldivide, mrdivide, times, plus}\n\ |
6518 | 5667 @end deftypefn") |
5668 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5669 return binary_op_defun_body (octave_value::op_el_div, args); |
6518 | 5670 } |
5671 | |
5672 DEFUN (power, args, , | |
5673 "-*- texinfo -*-\n\ | |
5674 @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
|
5675 Return the element-by-element operation of @var{x} raised to the\n\ |
14171
2ced2f59f523
doc: miscellaneous documentation improvements
Rik <octave@nomad.inbox5.com>
parents:
14169
diff
changeset
|
5676 @var{y} power. If several complex results are possible,\n\ |
2ced2f59f523
doc: miscellaneous documentation improvements
Rik <octave@nomad.inbox5.com>
parents:
14169
diff
changeset
|
5677 returns the one with smallest non-negative argument (angle). Use\n\ |
14169
c0ca47ab7641
doc: Better explain which complex result is chosen by .^
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
5678 @code{realpow}, @code{realsqrt}, @code{cbrt}, or @code{nthroot} if a\n\ |
c0ca47ab7641
doc: Better explain which complex result is chosen by .^
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
5679 real result is preferred.\n\ |
c0ca47ab7641
doc: Better explain which complex result is chosen by .^
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
5680 \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
|
5681 This function and @w{@xcode{x .^ y}} are equivalent.\n\ |
14169
c0ca47ab7641
doc: Better explain which complex result is chosen by .^
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
5682 @seealso{mpower, realpow, realsqrt, cbrt, nthroot}\n\ |
6518 | 5683 @end deftypefn") |
5684 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5685 return binary_op_defun_body (octave_value::op_el_pow, args); |
6518 | 5686 } |
5687 | |
5688 DEFUN (ldivide, args, , | |
5689 "-*- texinfo -*-\n\ | |
5690 @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
|
5691 Return the element-by-element left division of @var{x} and @var{y}.\n\ |
14615
88e67d58b06b
avoid makeinfo problem with backslash in macro argument
John W. Eaton <jwe@octave.org>
parents:
14569
diff
changeset
|
5692 This function and @w{@xcode{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
|
5693 @seealso{rdivide, mldivide, times, plus}\n\ |
6518 | 5694 @end deftypefn") |
5695 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5696 return binary_op_defun_body (octave_value::op_el_ldiv, args); |
6518 | 5697 } |
5698 | |
5699 DEFUN (and, args, , | |
5700 "-*- texinfo -*-\n\ | |
10840 | 5701 @deftypefn {Built-in Function} {} and (@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
|
5702 @deftypefnx {Built-in Function} {} 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
|
5703 Return the logical AND of @var{x} and @var{y}.\n\ |
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
5704 This function is equivalent to @w{@code{x & y}}.\n\ |
9339
c0b104835d0d
allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
5705 If more arguments are given, the logical and is applied\n\ |
c0b104835d0d
allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
5706 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
|
5707 \n\ |
c0b104835d0d
allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
5708 @example\n\ |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
5709 (@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
|
5710 @end example\n\ |
c0b104835d0d
allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
5711 \n\ |
11422
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
5712 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
|
5713 @seealso{or, not, xor}\n\ |
6518 | 5714 @end deftypefn") |
5715 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5716 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
|
5717 octave_value::op_el_and_eq, args); |
6518 | 5718 } |
5719 | |
5720 DEFUN (or, args, , | |
5721 "-*- texinfo -*-\n\ | |
10840 | 5722 @deftypefn {Built-in Function} {} or (@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
|
5723 @deftypefnx {Built-in Function} {} 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
|
5724 Return the logical OR of @var{x} and @var{y}.\n\ |
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
5725 This function is equivalent to @w{@code{x | y}}.\n\ |
9339
c0b104835d0d
allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
5726 If more arguments are given, the logical or is applied\n\ |
c0b104835d0d
allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
5727 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
|
5728 \n\ |
c0b104835d0d
allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
5729 @example\n\ |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
5730 (@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
|
5731 @end example\n\ |
c0b104835d0d
allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
5732 \n\ |
11422
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
5733 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
|
5734 @seealso{and, not, xor}\n\ |
6518 | 5735 @end deftypefn") |
5736 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5737 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
|
5738 octave_value::op_el_or_eq, args); |
6518 | 5739 } |
5740 | |
7065 | 5741 static double tic_toc_timestamp = -1.0; |
7045 | 5742 |
5743 DEFUN (tic, args, nargout, | |
5744 "-*- texinfo -*-\n\ | |
10840 | 5745 @deftypefn {Built-in Function} {} tic ()\n\ |
14853
72b8b39e12be
doc: Periodic grammarcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents:
14849
diff
changeset
|
5746 @deftypefnx {Built-in Function} {@var{id} =} tic ()\n\ |
7045 | 5747 @deftypefnx {Built-in Function} {} toc ()\n\ |
14635
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
5748 @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
|
5749 @deftypefnx {Built-in Function} {@var{val} =} toc (@dots{})\n\ |
7045 | 5750 Set or check a wall-clock timer. Calling @code{tic} without an\n\ |
14635
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
5751 output argument sets the internal timer state. Subsequent calls\n\ |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
5752 to @code{toc} return the number of seconds since the timer was set.\n\ |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
5753 For example,\n\ |
7045 | 5754 \n\ |
5755 @example\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
9041
diff
changeset
|
5756 @group\n\ |
7045 | 5757 tic ();\n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
9041
diff
changeset
|
5758 # many computations later@dots{}\n\ |
7045 | 5759 elapsed_time = toc ();\n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
9041
diff
changeset
|
5760 @end group\n\ |
7045 | 5761 @end example\n\ |
5762 \n\ | |
5763 @noindent\n\ | |
5764 will set the variable @code{elapsed_time} to the number of seconds since\n\ | |
5765 the most recent call to the function @code{tic}.\n\ | |
5766 \n\ | |
14635
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
5767 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
|
5768 of type @code{uint64} that may be later passed to @code{toc}.\n\ |
7045 | 5769 \n\ |
5770 @example\n\ | |
5771 @group\n\ | |
14635
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
5772 id = tic; sleep (5); toc (id)\n\ |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
5773 @result{} 5.0010\n\ |
7045 | 5774 @end group\n\ |
5775 @end example\n\ | |
5776 \n\ | |
14635
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
5777 Calling @code{tic} and @code{toc} this way allows nested timing calls.\n\ |
7045 | 5778 \n\ |
5779 If you are more interested in the CPU time that your process used, you\n\ | |
5780 should use the @code{cputime} function instead. The @code{tic} and\n\ | |
5781 @code{toc} functions report the actual wall clock time that elapsed\n\ | |
5782 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
|
5783 doing nothing at all.\n\ |
15028
397f0d80bd47
Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents:
15024
diff
changeset
|
5784 @seealso{toc, cputime}\n\ |
7045 | 5785 @end deftypefn") |
5786 { | |
5787 octave_value retval; | |
7065 | 5788 |
7045 | 5789 int nargin = args.length (); |
5790 | |
5791 if (nargin != 0) | |
5792 warning ("tic: ignoring extra arguments"); | |
5793 | |
7065 | 5794 octave_time now; |
5795 | |
5796 double tmp = now.double_value (); | |
5797 | |
7045 | 5798 if (nargout > 0) |
14635
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
5799 { |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
5800 double ip = 0.0; |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
5801 double frac = modf (tmp, &ip); |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
5802 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
|
5803 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
|
5804 retval = octave_uint64 (microsecs); |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
5805 } |
7045 | 5806 else |
7065 | 5807 tic_toc_timestamp = tmp; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
5808 |
7045 | 5809 return retval; |
5810 } | |
5811 | |
5812 DEFUN (toc, args, nargout, | |
5813 "-*- texinfo -*-\n\ | |
14853
72b8b39e12be
doc: Periodic grammarcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents:
14849
diff
changeset
|
5814 @deftypefn {Built-in Function} {} toc ()\n\ |
14635
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
5815 @deftypefnx {Built-in Function} {} toc (@var{id})\n\ |
14853
72b8b39e12be
doc: Periodic grammarcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents:
14849
diff
changeset
|
5816 @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
|
5817 @seealso{tic, cputime}\n\ |
7045 | 5818 @end deftypefn") |
5819 { | |
5820 octave_value retval; | |
7065 | 5821 |
7045 | 5822 int nargin = args.length (); |
5823 | |
14635
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
5824 double start_time = tic_toc_timestamp; |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
5825 |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
5826 if (nargin > 1) |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
5827 print_usage (); |
7045 | 5828 else |
7065 | 5829 { |
14635
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
5830 if (nargin == 1) |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
5831 { |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
5832 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
|
5833 |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
5834 if (! error_state) |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
5835 { |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
5836 uint64_t val = id.value (); |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
5837 |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
5838 start_time |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
5839 = (static_cast<double> (val / CLOCKS_PER_SEC) |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
5840 + static_cast<double> (val % CLOCKS_PER_SEC) / CLOCKS_PER_SEC); |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
5841 |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
5842 // FIXME -- should we also check to see whether the start |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
5843 // 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
|
5844 } |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
5845 else |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
5846 error ("toc: invalid ID"); |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
5847 } |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
5848 |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
5849 if (! error_state) |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
5850 { |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
5851 if (start_time < 0) |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
5852 error ("toc called before timer set"); |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
5853 else |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
5854 { |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
5855 octave_time now; |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
5856 |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
5857 double tmp = now.double_value () - start_time; |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
5858 |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
5859 if (nargout > 0) |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
5860 retval = tmp; |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
5861 else |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
5862 octave_stdout << "Elapsed time is " << tmp << " seconds.\n"; |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
5863 } |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
5864 } |
7065 | 5865 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
5866 |
7045 | 5867 return retval; |
5868 } | |
5869 | |
14635
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
5870 /* |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
5871 %!shared id |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
5872 %! id = tic (); |
14849
f6d3d5b0bd42
test: Use Octave coding conventions for tests for line() and toc().
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
5873 %!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
|
5874 %!assert (isa (toc (id), "double")) |
14635
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
5875 */ |
f8d5095fa90d
improve compatibility of tic and toc
John W. Eaton <jwe@octave.org>
parents:
14615
diff
changeset
|
5876 |
7045 | 5877 DEFUN (cputime, args, , |
5878 "-*- texinfo -*-\n\ | |
5879 @deftypefn {Built-in Function} {[@var{total}, @var{user}, @var{system}] =} cputime ();\n\ | |
5880 Return the CPU time used by your Octave session. The first output is\n\ | |
5881 the total time spent executing your process and is equal to the sum of\n\ | |
5882 second and third outputs, which are the number of CPU seconds spent\n\ | |
5883 executing in user mode and the number of CPU seconds spent executing in\n\ | |
5884 system mode, respectively. If your system does not have a way to report\n\ | |
5885 CPU time usage, @code{cputime} returns 0 for each of its output values.\n\ | |
5886 Note that because Octave used some CPU time to start, it is reasonable\n\ | |
5887 to check to see if @code{cputime} works by checking to see if the total\n\ | |
5888 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
|
5889 @seealso{tic, toc}\n\ |
7045 | 5890 @end deftypefn") |
5891 { | |
5892 octave_value_list retval; | |
5893 int nargin = args.length (); | |
5894 double usr = 0.0; | |
5895 double sys = 0.0; | |
5896 | |
5897 if (nargin != 0) | |
5898 warning ("tic: ignoring extra arguments"); | |
5899 | |
5900 #if defined (HAVE_GETRUSAGE) | |
5901 | |
5902 struct rusage ru; | |
5903 | |
5904 getrusage (RUSAGE_SELF, &ru); | |
5905 | |
5906 usr = static_cast<double> (ru.ru_utime.tv_sec) + | |
5907 static_cast<double> (ru.ru_utime.tv_usec) * 1e-6; | |
5908 | |
5909 sys = static_cast<double> (ru.ru_stime.tv_sec) + | |
5910 static_cast<double> (ru.ru_stime.tv_usec) * 1e-6; | |
5911 | |
10240
fa7b5751730c
use gnulib time, sys_time, and sys_times modules
John W. Eaton <jwe@octave.org>
parents:
10185
diff
changeset
|
5912 #else |
7045 | 5913 |
5914 struct tms t; | |
5915 | |
5916 times (&t); | |
5917 | |
5918 unsigned long ticks; | |
5919 unsigned long seconds; | |
5920 unsigned long fraction; | |
5921 | |
5922 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
|
5923 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
|
5924 seconds = ticks / CLOCKS_PER_SEC; |
7045 | 5925 |
5926 usr = static_cast<double> (seconds) + static_cast<double>(fraction) / | |
10303
e4899d6320b6
data.cc: use CLOCKS_PER_SEC instead of HZ
John W. Eaton <jwe@octave.org>
parents:
10302
diff
changeset
|
5927 static_cast<double>(CLOCKS_PER_SEC); |
7045 | 5928 |
5929 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
|
5930 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
|
5931 seconds = ticks / CLOCKS_PER_SEC; |
7045 | 5932 |
5933 sys = static_cast<double> (seconds) + static_cast<double>(fraction) / | |
10303
e4899d6320b6
data.cc: use CLOCKS_PER_SEC instead of HZ
John W. Eaton <jwe@octave.org>
parents:
10302
diff
changeset
|
5934 static_cast<double>(CLOCKS_PER_SEC); |
7045 | 5935 |
5936 #endif | |
5937 | |
14843
7d4f87c75dbb
data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents:
14635
diff
changeset
|
5938 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
|
5939 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
|
5940 retval(0) = sys + usr; |
7045 | 5941 |
5942 return retval; | |
5943 } | |
5944 | |
7433 | 5945 DEFUN (sort, args, nargout, |
5946 "-*- 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
|
5947 @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
|
5948 @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
|
5949 @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
|
5950 @deftypefnx {Built-in Function} {[@var{s}, @var{i}] =} sort (@var{x}, @var{dim}, @var{mode})\n\ |
7433 | 5951 Return a copy of @var{x} with the elements arranged in increasing\n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
5952 order. For matrices, @code{sort} orders the elements within columns\n\ |
7433 | 5953 \n\ |
10840 | 5954 For example:\n\ |
7433 | 5955 \n\ |
5956 @example\n\ | |
5957 @group\n\ | |
5958 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
|
5959 @result{} 1 1\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
5960 2 2\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
5961 3 3\n\ |
7433 | 5962 @end group\n\ |
5963 @end example\n\ | |
5964 \n\ | |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
5965 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
|
5966 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
|
5967 defines the order in which the values will be sorted. Valid values of\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
|
5968 @code{mode} are \"ascend\" or \"descend\".\n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
5969 \n\ |
7433 | 5970 The @code{sort} function may also be used to produce a matrix\n\ |
5971 containing the original row indices of the elements in the sorted\n\ | |
10840 | 5972 matrix. For example:\n\ |
7433 | 5973 \n\ |
5974 @example\n\ | |
5975 @group\n\ | |
5976 [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
|
5977 @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
|
5978 2 2\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
5979 3 3\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
5980 @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
|
5981 2 1\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
5982 3 2\n\ |
7433 | 5983 @end group\n\ |
5984 @end example\n\ | |
5985 \n\ | |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
5986 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
|
5987 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
|
5988 \n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
5989 Sorting of complex entries is done first by magnitude (@code{abs (@var{z})})\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
5990 and for any ties by phase angle (@code{angle (z)}). For example:\n\ |
7433 | 5991 \n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
5992 @example\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
5993 @group\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
5994 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
|
5995 @result{} 1 + 0i\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
5996 1 - 1i\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14171
diff
changeset
|
5997 1 + 1i\n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
5998 @end group\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
5999 @end example\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
6000 \n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
6001 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
|
6002 to the end of the list.\n\ |
7433 | 6003 \n\ |
6004 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
|
6005 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
|
6006 lowercase 'a') of the strings is used.\n\ |
7433 | 6007 \n\ |
6008 The algorithm used in @code{sort} is optimized for the sorting of partially\n\ | |
6009 ordered lists.\n\ | |
15028
397f0d80bd47
Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents:
15024
diff
changeset
|
6010 @seealso{sortrows, issorted}\n\ |
7433 | 6011 @end deftypefn") |
6012 { | |
6013 octave_value_list retval; | |
6014 | |
6015 int nargin = args.length (); | |
6016 sortmode smode = ASCENDING; | |
6017 | |
6018 if (nargin < 1 || nargin > 3) | |
6019 { | |
6020 print_usage (); | |
6021 return retval; | |
6022 } | |
6023 | |
6024 bool return_idx = nargout > 1; | |
6025 | |
6026 octave_value arg = args(0); | |
6027 | |
6028 int dim = 0; | |
6029 if (nargin > 1) | |
6030 { | |
6031 if (args(1).is_string ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
6032 { |
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
|
6033 std::string mode = args(1).string_value (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
6034 if (mode == "ascend") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
6035 smode = ASCENDING; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
6036 else if (mode == "descend") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
6037 smode = DESCENDING; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
6038 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
6039 { |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11591
diff
changeset
|
6040 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
|
6041 return retval; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
6042 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
6043 } |
7433 | 6044 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
6045 dim = args(1).nint_value () - 1; |
7433 | 6046 } |
6047 | |
6048 if (nargin > 2) | |
6049 { | |
6050 if (args(1).is_string ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
6051 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
6052 print_usage (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
6053 return retval; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
6054 } |
7433 | 6055 |
6056 if (! args(2).is_string ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
6057 { |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11591
diff
changeset
|
6058 error ("sort: MODE must be a string"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
6059 return retval; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
6060 } |
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
|
6061 std::string mode = args(2).string_value (); |
7433 | 6062 if (mode == "ascend") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
6063 smode = ASCENDING; |
7433 | 6064 else if (mode == "descend") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
6065 smode = DESCENDING; |
7433 | 6066 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
6067 { |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11591
diff
changeset
|
6068 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
|
6069 return retval; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
6070 } |
7433 | 6071 } |
6072 | |
10285
22a7913bbeb5
optimize return values of find and sort
Jaroslav Hajek <highegg@gmail.com>
parents:
10277
diff
changeset
|
6073 const dim_vector dv = arg.dims (); |
7433 | 6074 if (nargin == 1 || args(1).is_string ()) |
6075 { | |
6076 // Find first non singleton dimension | |
10285
22a7913bbeb5
optimize return values of find and sort
Jaroslav Hajek <highegg@gmail.com>
parents:
10277
diff
changeset
|
6077 dim = dv.first_non_singleton (); |
7433 | 6078 } |
6079 else | |
6080 { | |
10703
5eb420d92307
fix sort and nth_element when trailing singleton dim is specified
Jaroslav Hajek <highegg@gmail.com>
parents:
10695
diff
changeset
|
6081 if (dim < 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
6082 { |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11591
diff
changeset
|
6083 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
|
6084 return retval; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
6085 } |
7433 | 6086 } |
6087 | |
6088 if (return_idx) | |
6089 { | |
14022
de90542b7afc
Return retval(1) before retval(0) to avoid re-sizing call on retval.
Rik <octave@nomad.inbox5.com>
parents:
13929
diff
changeset
|
6090 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
|
6091 |
7433 | 6092 Array<octave_idx_type> sidx; |
6093 | |
14843
7d4f87c75dbb
data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents:
14635
diff
changeset
|
6094 retval(0) = arg.sort (sidx, dim, smode); |
7d4f87c75dbb
data.cc: Use Octave coding conventions for cuddling/non-cuddling of parenthesis.
Rik <octave@nomad.inbox5.com>
parents:
14635
diff
changeset
|
6095 retval(1) = idx_vector (sidx, dv(dim)); // No checking, the extent is known. |
7433 | 6096 } |
6097 else | |
6098 retval(0) = arg.sort (dim, smode); | |
6099 | |
6100 return retval; | |
6101 } | |
6102 | |
6103 /* | |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6104 ## Double |
7433 | 6105 %!assert (sort ([NaN, 1, -1, 2, Inf]), [-1, 1, 2, Inf, NaN]) |
6106 %!assert (sort ([NaN, 1, -1, 2, Inf], 1), [NaN, 1, -1, 2, Inf]) | |
6107 %!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
|
6108 %!assert (sort ([NaN, 1, -1, 2, Inf], 3), [NaN, 1, -1, 2, Inf]) |
7433 | 6109 %!assert (sort ([NaN, 1, -1, 2, Inf], "ascend"), [-1, 1, 2, Inf, NaN]) |
6110 %!assert (sort ([NaN, 1, -1, 2, Inf], 2, "ascend"), [-1, 1, 2, Inf, NaN]) | |
6111 %!assert (sort ([NaN, 1, -1, 2, Inf], "descend"), [NaN, Inf, 2, 1, -1]) | |
6112 %!assert (sort ([NaN, 1, -1, 2, Inf], 2, "descend"), [NaN, Inf, 2, 1, -1]) | |
6113 %!assert (sort ([3, 1, 7, 5; 8, 2, 6, 4]), [3, 1, 6, 4; 8, 2, 7, 5]) | |
6114 %!assert (sort ([3, 1, 7, 5; 8, 2, 6, 4], 1), [3, 1, 6, 4; 8, 2, 7, 5]) | |
6115 %!assert (sort ([3, 1, 7, 5; 8, 2, 6, 4], 2), [1, 3, 5, 7; 2, 4, 6, 8]) | |
6116 %!assert (sort (1), 1) | |
6117 | |
6118 %!test | |
6119 %! [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
|
6120 %! 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
|
6121 %! 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
|
6122 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6123 ## Complex |
7433 | 6124 %!assert (sort ([NaN, 1i, -1, 2, Inf]), [1i, -1, 2, Inf, NaN]) |
6125 %!assert (sort ([NaN, 1i, -1, 2, Inf], 1), [NaN, 1i, -1, 2, Inf]) | |
6126 %!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
|
6127 %!assert (sort ([NaN, 1i, -1, 2, Inf], 3), [NaN, 1i, -1, 2, Inf]) |
7433 | 6128 %!assert (sort ([NaN, 1i, -1, 2, Inf], "ascend"), [1i, -1, 2, Inf, NaN]) |
6129 %!assert (sort ([NaN, 1i, -1, 2, Inf], 2, "ascend"), [1i, -1, 2, Inf, NaN]) | |
6130 %!assert (sort ([NaN, 1i, -1, 2, Inf], "descend"), [NaN, Inf, 2, -1, 1i]) | |
6131 %!assert (sort ([NaN, 1i, -1, 2, Inf], 2, "descend"), [NaN, Inf, 2, -1, 1i]) | |
6132 %!assert (sort ([3, 1i, 7, 5; 8, 2, 6, 4]), [3, 1i, 6, 4; 8, 2, 7, 5]) | |
6133 %!assert (sort ([3, 1i, 7, 5; 8, 2, 6, 4], 1), [3, 1i, 6, 4; 8, 2, 7, 5]) | |
6134 %!assert (sort ([3, 1i, 7, 5; 8, 2, 6, 4], 2), [1i, 3, 5, 7; 2, 4, 6, 8]) | |
6135 %!assert (sort (1i), 1i) | |
6136 | |
6137 %!test | |
6138 %! [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
|
6139 %! 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
|
6140 %! 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
|
6141 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6142 ## Single |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6143 %!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
|
6144 %!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
|
6145 %!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
|
6146 %!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
|
6147 %!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
|
6148 %!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
|
6149 %!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
|
6150 %!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
|
6151 %!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
|
6152 %!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
|
6153 %!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
|
6154 %!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
|
6155 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
6156 %!test |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6157 %! [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
|
6158 %! 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
|
6159 %! 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
|
6160 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6161 ## Single Complex |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6162 %!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
|
6163 %!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
|
6164 %!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
|
6165 %!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
|
6166 %!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
|
6167 %!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
|
6168 %!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
|
6169 %!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
|
6170 %!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
|
6171 %!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
|
6172 %!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
|
6173 %!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
|
6174 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
6175 %!test |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6176 %! [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
|
6177 %! 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
|
6178 %! 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
|
6179 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6180 ## Bool |
7433 | 6181 %!assert (sort ([true, false, true, false]), [false, false, true, true]) |
6182 %!assert (sort ([true, false, true, false], 1), [true, false, true, false]) | |
6183 %!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
|
6184 %!assert (sort ([true, false, true, false], 3), [true, false, true, false]) |
7433 | 6185 %!assert (sort ([true, false, true, false], "ascend"), [false, false, true, true]) |
6186 %!assert (sort ([true, false, true, false], 2, "ascend"), [false, false, true, true]) | |
6187 %!assert (sort ([true, false, true, false], "descend"), [true, true, false, false]) | |
6188 %!assert (sort ([true, false, true, false], 2, "descend"), [true, true, false, false]) | |
6189 %!assert (sort (true), true) | |
6190 | |
6191 %!test | |
6192 %! [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
|
6193 %! 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
|
6194 %! 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
|
6195 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6196 ## Sparse Double |
7433 | 6197 %!assert (sort (sparse ([0, NaN, 1, 0, -1, 2, Inf])), sparse ([-1, 0, 0, 1, 2, Inf, NaN])) |
6198 %!assert (sort (sparse ([0, NaN, 1, 0, -1, 2, Inf]), 1), sparse ([0, NaN, 1, 0, -1, 2, Inf])) | |
6199 %!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
|
6200 %!assert (sort (sparse ([0, NaN, 1, 0, -1, 2, Inf]), 3), sparse ([0, NaN, 1, 0, -1, 2, Inf])) |
7433 | 6201 %!assert (sort (sparse ([0, NaN, 1, 0, -1, 2, Inf]), "ascend"), sparse ([-1, 0, 0, 1, 2, Inf, NaN])) |
6202 %!assert (sort (sparse ([0, NaN, 1, 0, -1, 2, Inf]), 2, "ascend"), sparse ([-1, 0, 0, 1, 2, Inf, NaN])) | |
6203 %!assert (sort (sparse ([0, NaN, 1, 0, -1, 2, Inf]), "descend"), sparse ([NaN, Inf, 2, 1, 0, 0, -1])) | |
6204 %!assert (sort (sparse ([0, NaN, 1, 0, -1, 2, Inf]), 2, "descend"), sparse ([NaN, Inf, 2, 1, 0, 0, -1])) | |
6205 | |
6206 %!shared a | |
6207 %! a = randn (10, 10); | |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6208 %! a(a < 0) = 0; |
7433 | 6209 %!assert (sort (sparse (a)), sparse (sort (a))) |
6210 %!assert (sort (sparse (a), 1), sparse (sort (a, 1))) | |
6211 %!assert (sort (sparse (a), 2), sparse (sort (a, 2))) | |
6212 %!test | |
6213 %! [v, i] = sort (a); | |
6214 %! [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
|
6215 %! assert (vs, sparse (v)); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6216 %! assert (is, i); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6217 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6218 ## Sparse Complex |
7433 | 6219 %!assert (sort (sparse ([0, NaN, 1i, 0, -1, 2, Inf])), sparse ([0, 0, 1i, -1, 2, Inf, NaN])) |
6220 %!assert (sort (sparse ([0, NaN, 1i, 0, -1, 2, Inf]), 1), sparse ([0, NaN, 1i, 0, -1, 2, Inf])) | |
6221 %!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
|
6222 %!assert (sort (sparse ([0, NaN, 1i, 0, -1, 2, Inf]), 3), sparse ([0, NaN, 1i, 0, -1, 2, Inf])) |
7433 | 6223 %!assert (sort (sparse ([0, NaN, 1i, 0, -1, 2, Inf]), "ascend"), sparse ([0, 0, 1i, -1, 2, Inf, NaN])) |
6224 %!assert (sort (sparse ([0, NaN, 1i, 0, -1, 2, Inf]), 2, "ascend"), sparse ([0, 0, 1i, -1, 2, Inf, NaN])) | |
6225 %!assert (sort (sparse ([0, NaN, 1i, 0, -1, 2, Inf]), "descend"), sparse ([NaN, Inf, 2, -1, 1i, 0, 0])) | |
6226 %!assert (sort (sparse ([0, NaN, 1i, 0, -1, 2, Inf]), 2, "descend"), sparse ([NaN, Inf, 2, -1, 1i, 0, 0])) | |
6227 | |
6228 %!shared a | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
6229 %! a = randn (10, 10); |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6230 %! a(a < 0) = 0; |
7433 | 6231 %! a = 1i * a; |
6232 %!assert (sort (sparse (a)), sparse (sort (a))) | |
6233 %!assert (sort (sparse (a), 1), sparse (sort (a, 1))) | |
6234 %!assert (sort (sparse (a), 2), sparse (sort (a, 2))) | |
6235 %!test | |
6236 %! [v, i] = sort (a); | |
6237 %! [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
|
6238 %! assert (vs, sparse (v)); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6239 %! assert (is, i); |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6240 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6241 ## Sparse Bool |
7433 | 6242 %!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
|
6243 %!assert (sort (sparse ([true, false, true, false]), 1), sparse ([true, false, true, false])) |
7433 | 6244 %!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
|
6245 %!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
|
6246 %!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
|
6247 %!assert (sort (sparse ([true, false, true, false]), 2, "ascend"), sparse ([false, false, true, true])) |
7433 | 6248 %!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
|
6249 %!assert (sort (sparse ([true, false, true, false]), 2, "descend"), sparse ([true, true, false, false])) |
7433 | 6250 |
6251 %!test | |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6252 %! [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
|
6253 %! 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
|
6254 %! 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
|
6255 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6256 ## Cell string array |
7433 | 6257 %!shared a, b, c |
6258 %! a = {"Alice", "Cecile", "Eric", "Barry", "David"}; | |
6259 %! b = {"Alice", "Barry", "Cecile", "David", "Eric"}; | |
6260 %! 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
|
6261 %!assert (sort (a), b) |
7433 | 6262 %!assert (sort (a, 1), a) |
6263 %!assert (sort (a, 2), b) | |
10707
69c5f5ec55d7
fix invalid sort tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10703
diff
changeset
|
6264 %!assert (sort (a, 3), a) |
7433 | 6265 %!assert (sort (a, "ascend"), b) |
6266 %!assert (sort (a, 2, "ascend"), b) | |
6267 %!assert (sort (a, "descend"), c) | |
6268 %!assert (sort (a, 2, "descend"), c) | |
6269 | |
6270 %!test | |
6271 %! [v, i] = sort (a); | |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6272 %! 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
|
6273 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6274 %!error sort () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6275 %!error sort (1, 2, 3, 4) |
7433 | 6276 */ |
6277 | |
8812
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
8799
diff
changeset
|
6278 // 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
|
6279 // 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
|
6280 // 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
|
6281 // |
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
8799
diff
changeset
|
6282 // 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
|
6283 |
8733
3ef774603887
rename all uses of sortrows_idx to sort_rows_idx
John W. Eaton <jwe@octave.org>
parents:
8721
diff
changeset
|
6284 DEFUN (__sort_rows_idx__, args, , |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6285 "-*- texinfo -*-\n\ |
9517
a85dbf7b6ff9
fix some functions help markup
Jaroslav Hajek <highegg@gmail.com>
parents:
9513
diff
changeset
|
6286 @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
|
6287 Undocumented internal function.\n\ |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6288 @end deftypefn\n") |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6289 { |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6290 octave_value retval; |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6291 |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6292 int nargin = args.length (); |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6293 sortmode smode = ASCENDING; |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6294 |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6295 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
|
6296 { |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6297 print_usage (); |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6298 return retval; |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6299 } |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6300 |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6301 if (nargin > 1) |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6302 { |
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
|
6303 std::string mode = args(1).string_value (); |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6304 if (mode == "ascend") |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6305 smode = ASCENDING; |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6306 else if (mode == "descend") |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6307 smode = DESCENDING; |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6308 else |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6309 { |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11591
diff
changeset
|
6310 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
|
6311 return retval; |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6312 } |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6313 } |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6314 |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6315 octave_value arg = args(0); |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6316 |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6317 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
|
6318 error ("__sort_rows_idx__: sparse matrices not yet supported"); |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6319 if (arg.ndims () == 2) |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6320 { |
8733
3ef774603887
rename all uses of sortrows_idx to sort_rows_idx
John W. Eaton <jwe@octave.org>
parents:
8721
diff
changeset
|
6321 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
|
6322 |
9351
e2344f4af0cb
autocache indices returned from find et al.
Jaroslav Hajek <highegg@gmail.com>
parents:
9339
diff
changeset
|
6323 retval = octave_value (idx, true, true); |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6324 } |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6325 else |
8733
3ef774603887
rename all uses of sortrows_idx to sort_rows_idx
John W. Eaton <jwe@octave.org>
parents:
8721
diff
changeset
|
6326 error ("__sort_rows_idx__: needs a 2-dimensional object"); |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6327 |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6328 return retval; |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6329 } |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6330 |
9765
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6331 static sortmode |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6332 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
|
6333 { |
10076
4b270d1540f7
avoid various GCC warnings
John W. Eaton <jwe@octave.org>
parents:
10073
diff
changeset
|
6334 // FIXME -- we initialize to UNSORTED here to avoid a GCC warning |
4b270d1540f7
avoid various GCC warnings
John W. Eaton <jwe@octave.org>
parents:
10073
diff
changeset
|
6335 // about possibly using sortmode uninitialized. |
4b270d1540f7
avoid various GCC warnings
John W. Eaton <jwe@octave.org>
parents:
10073
diff
changeset
|
6336 // FIXME -- shouldn't these modes be scoped inside a class? |
4b270d1540f7
avoid various GCC warnings
John W. Eaton <jwe@octave.org>
parents:
10073
diff
changeset
|
6337 sortmode smode = UNSORTED; |
9765
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6338 |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6339 std::string mode = arg.string_value (); |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6340 |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6341 if (error_state) |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6342 error ("issorted: expecting %s argument to be a character string", argn); |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6343 else if (mode == "ascending") |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6344 smode = ASCENDING; |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6345 else if (mode == "descending") |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6346 smode = DESCENDING; |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6347 else if (mode == "either") |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6348 smode = UNSORTED; |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6349 else |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11591
diff
changeset
|
6350 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
|
6351 |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6352 return smode; |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6353 } |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6354 |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6355 DEFUN (issorted, args, , |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6356 "-*- texinfo -*-\n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
6357 @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
|
6358 @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
|
6359 @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
|
6360 Return true if the array is sorted according to @var{mode}, which\n\ |
9765
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6361 may be either \"ascending\", \"descending\", or \"either\". By default,\n\ |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11422
diff
changeset
|
6362 @var{mode} is \"ascending\". NaNs are treated in the same manner as\n\ |
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11422
diff
changeset
|
6363 @code{sort}.\n\ |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6364 \n\ |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11422
diff
changeset
|
6365 If the optional argument \"rows\" is supplied, check whether\n\ |
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11422
diff
changeset
|
6366 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
|
6367 (with no options).\n\ |
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11422
diff
changeset
|
6368 \n\ |
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11422
diff
changeset
|
6369 This function does not support sparse matrices.\n\ |
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11422
diff
changeset
|
6370 @seealso{sort, sortrows}\n\ |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6371 @end deftypefn\n") |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6372 { |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6373 octave_value retval; |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6374 |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6375 int nargin = args.length (); |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6376 |
9765
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6377 if (nargin < 1 || nargin > 3) |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6378 { |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6379 print_usage (); |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6380 return retval; |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6381 } |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6382 |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6383 bool by_rows = false; |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6384 |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6385 sortmode smode = ASCENDING; |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6386 |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6387 if (nargin > 1) |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6388 { |
9765
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6389 octave_value mode_arg; |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6390 |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6391 if (nargin == 3) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
6392 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
|
6393 |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6394 std::string tmp = args(1).string_value (); |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6395 |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6396 if (! error_state) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
6397 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
6398 if (tmp == "rows") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
6399 by_rows = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
6400 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
6401 smode = get_sort_mode_option (args(1), "second"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
6402 } |
9765
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6403 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
6404 error ("expecting second argument to be character string"); |
9765
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6405 |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6406 if (error_state) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
6407 return retval; |
9765
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6408 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
6409 |
9765
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6410 octave_value arg = args(0); |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6411 |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6412 if (by_rows) |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6413 { |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6414 if (arg.is_sparse_type ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
6415 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
|
6416 if (arg.ndims () == 2) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
6417 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
|
6418 else |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11591
diff
changeset
|
6419 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
|
6420 } |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6421 else |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6422 { |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6423 if (arg.dims ().is_vector ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
6424 retval = args(0).is_sorted (smode) != UNSORTED; |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6425 else |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6426 error ("issorted: needs a vector"); |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6427 } |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6428 |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6429 return retval; |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6430 } |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6431 |
9765
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6432 /* |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6433 %!shared sm, um, sv, uv |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6434 %! sm = [1, 2; 3, 4]; |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6435 %! um = [3, 1; 2, 4]; |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6436 %! sv = [1, 2, 3, 4]; |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6437 %! 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
|
6438 %!assert (issorted (sm, "rows")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6439 %!assert (!issorted (um, "rows")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6440 %!assert (issorted (sv)) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6441 %!assert (!issorted (uv)) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6442 %!assert (issorted (sv')) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6443 %!assert (!issorted (uv')) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6444 %!assert (issorted (sm, "rows", "ascending")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6445 %!assert (!issorted (um, "rows", "ascending")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6446 %!assert (issorted (sv, "ascending")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6447 %!assert (!issorted (uv, "ascending")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6448 %!assert (issorted (sv', "ascending")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6449 %!assert (!issorted (uv', "ascending")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6450 %!assert (!issorted (sm, "rows", "descending")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6451 %!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
|
6452 %!assert (!issorted (sv, "descending")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6453 %!assert (issorted (fliplr (sv), "descending")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6454 %!assert (!issorted (sv', "descending")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6455 %!assert (issorted (fliplr (sv)', "descending")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6456 %!assert (!issorted (um, "rows", "either")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6457 %!assert (!issorted (uv, "either")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6458 %!assert (issorted (sm, "rows", "either")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6459 %!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
|
6460 %!assert (issorted (sv, "either")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6461 %!assert (issorted (fliplr (sv), "either")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6462 %!assert (issorted (sv', "either")) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
6463 %!assert (issorted (fliplr (sv)', "either")) |
9765
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6464 */ |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
6465 |
9725 | 6466 DEFUN (nth_element, args, , |
6467 "-*- texinfo -*-\n\ | |
10840 | 6468 @deftypefn {Built-in Function} {} nth_element (@var{x}, @var{n})\n\ |
9725 | 6469 @deftypefnx {Built-in Function} {} nth_element (@var{x}, @var{n}, @var{dim})\n\ |
10840 | 6470 Select the n-th smallest element of a vector, using the ordering defined by\n\ |
6471 @code{sort}. In other words, the result is equivalent to\n\ | |
6472 @code{sort(@var{x})(@var{n})}.\n\ | |
9725 | 6473 @var{n} can also be a contiguous range, either ascending @code{l:u}\n\ |
6474 or descending @code{u:-1:l}, in which case a range of elements is returned.\n\ | |
10846
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10840
diff
changeset
|
6475 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
|
6476 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
|
6477 not given.\n\ |
9725 | 6478 \n\ |
10840 | 6479 nth_element encapsulates the C++ standard library algorithms nth_element and\n\ |
10846
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10840
diff
changeset
|
6480 partial_sort. On average, the complexity of the operation is O(M*log(K)),\n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
6481 where @w{@code{M = size (@var{x}, @var{dim})}} and\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
6482 @w{@code{K = length (@var{n})}}.\n\ |
9725 | 6483 This function is intended for cases where the ratio K/M is small; otherwise,\n\ |
6484 it may be better to use @code{sort}.\n\ | |
6485 @seealso{sort, min, max}\n\ | |
6486 @end deftypefn") | |
6487 { | |
6488 octave_value retval; | |
6489 int nargin = args.length (); | |
6490 | |
6491 if (nargin == 2 || nargin == 3) | |
6492 { | |
6493 octave_value argx = args(0); | |
6494 | |
6495 int dim = -1; | |
6496 if (nargin == 3) | |
6497 { | |
6498 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
|
6499 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
|
6500 error ("nth_element: DIM must be a valid dimension"); |
9725 | 6501 } |
6502 if (dim < 0) | |
6503 dim = argx.dims ().first_non_singleton (); | |
6504 | |
6505 idx_vector n = args(1).index_vector (); | |
6506 | |
6507 if (error_state) | |
6508 return retval; | |
6509 | |
6510 switch (argx.builtin_type ()) | |
6511 { | |
6512 case btyp_double: | |
6513 retval = argx.array_value ().nth_element (n, dim); | |
6514 break; | |
6515 case btyp_float: | |
6516 retval = argx.float_array_value ().nth_element (n, dim); | |
6517 break; | |
6518 case btyp_complex: | |
6519 retval = argx.complex_array_value ().nth_element (n, dim); | |
6520 break; | |
6521 case btyp_float_complex: | |
6522 retval = argx.float_complex_array_value ().nth_element (n, dim); | |
6523 break; | |
6524 #define MAKE_INT_BRANCH(X) \ | |
6525 case btyp_ ## X: \ | |
6526 retval = argx.X ## _array_value ().nth_element (n, dim); \ | |
6527 break | |
6528 | |
6529 MAKE_INT_BRANCH (int8); | |
6530 MAKE_INT_BRANCH (int16); | |
6531 MAKE_INT_BRANCH (int32); | |
6532 MAKE_INT_BRANCH (int64); | |
6533 MAKE_INT_BRANCH (uint8); | |
6534 MAKE_INT_BRANCH (uint16); | |
6535 MAKE_INT_BRANCH (uint32); | |
6536 MAKE_INT_BRANCH (uint64); | |
6537 #undef MAKE_INT_BRANCH | |
6538 default: | |
6539 if (argx.is_cellstr ()) | |
6540 retval = argx.cellstr_value ().nth_element (n, dim); | |
6541 else | |
6542 gripe_wrong_type_arg ("nth_element", argx); | |
6543 } | |
6544 } | |
6545 else | |
6546 print_usage (); | |
6547 | |
6548 return retval; | |
6549 } | |
6550 | |
8934
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6551 template <class NDT> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
6552 static NDT |
8934
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6553 do_accumarray_sum (const idx_vector& idx, const NDT& vals, |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6554 octave_idx_type n = -1) |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6555 { |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6556 typedef typename NDT::element_type T; |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6557 if (n < 0) |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6558 n = idx.extent (0); |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6559 else if (idx.extent (n) > n) |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6560 error ("accumarray: index out of range"); |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6561 |
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
|
6562 NDT retval (dim_vector (n, 1), T ()); |
8934
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6563 |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6564 if (vals.numel () == 1) |
9858
47c5af1868df
move idx_add methods to MArrayN
Jaroslav Hajek <highegg@gmail.com>
parents:
9856
diff
changeset
|
6565 retval.idx_add (idx, vals (0)); |
47c5af1868df
move idx_add methods to MArrayN
Jaroslav Hajek <highegg@gmail.com>
parents:
9856
diff
changeset
|
6566 else if (vals.numel () == idx.length (n)) |
47c5af1868df
move idx_add methods to MArrayN
Jaroslav Hajek <highegg@gmail.com>
parents:
9856
diff
changeset
|
6567 retval.idx_add (idx, vals); |
8934
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6568 else |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6569 error ("accumarray: dimensions mismatch"); |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6570 |
9858
47c5af1868df
move idx_add methods to MArrayN
Jaroslav Hajek <highegg@gmail.com>
parents:
9856
diff
changeset
|
6571 return retval; |
8934
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6572 } |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6573 |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6574 DEFUN (__accumarray_sum__, args, , |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6575 "-*- texinfo -*-\n\ |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6576 @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
|
6577 Undocumented internal function.\n\ |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6578 @end deftypefn") |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6579 { |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6580 octave_value retval; |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6581 int nargin = args.length (); |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6582 if (nargin >= 2 && nargin <= 3 && args(0).is_numeric_type ()) |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6583 { |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6584 idx_vector idx = args(0).index_vector (); |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6585 octave_idx_type n = -1; |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6586 if (nargin == 3) |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6587 n = args(2).idx_type_value (true); |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6588 |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6589 if (! error_state) |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6590 { |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6591 octave_value vals = args(1); |
9198
3b9aacf07744
optimize accumarray with constant ranges
Jaroslav Hajek <highegg@gmail.com>
parents:
9197
diff
changeset
|
6592 if (vals.is_range ()) |
3b9aacf07744
optimize accumarray with constant ranges
Jaroslav Hajek <highegg@gmail.com>
parents:
9197
diff
changeset
|
6593 { |
3b9aacf07744
optimize accumarray with constant ranges
Jaroslav Hajek <highegg@gmail.com>
parents:
9197
diff
changeset
|
6594 Range r = vals.range_value (); |
3b9aacf07744
optimize accumarray with constant ranges
Jaroslav Hajek <highegg@gmail.com>
parents:
9197
diff
changeset
|
6595 if (r.inc () == 0) |
3b9aacf07744
optimize accumarray with constant ranges
Jaroslav Hajek <highegg@gmail.com>
parents:
9197
diff
changeset
|
6596 vals = r.base (); |
3b9aacf07744
optimize accumarray with constant ranges
Jaroslav Hajek <highegg@gmail.com>
parents:
9197
diff
changeset
|
6597 } |
3b9aacf07744
optimize accumarray with constant ranges
Jaroslav Hajek <highegg@gmail.com>
parents:
9197
diff
changeset
|
6598 |
8934
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6599 if (vals.is_single_type ()) |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6600 { |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6601 if (vals.is_complex_type ()) |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6602 retval = do_accumarray_sum (idx, vals.float_complex_array_value (), n); |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6603 else |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6604 retval = do_accumarray_sum (idx, vals.float_array_value (), n); |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6605 } |
10269
217d36560dfa
small fixes to accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10268
diff
changeset
|
6606 else if (vals.is_numeric_type () || vals.is_bool_type ()) |
8934
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6607 { |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6608 if (vals.is_complex_type ()) |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6609 retval = do_accumarray_sum (idx, vals.complex_array_value (), n); |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6610 else |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6611 retval = do_accumarray_sum (idx, vals.array_value (), n); |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6612 } |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6613 else |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6614 gripe_wrong_type_arg ("accumarray", vals); |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6615 } |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6616 } |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6617 else |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6618 print_usage (); |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6619 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
6620 return retval; |
8934
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6621 } |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6622 |
9473
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6623 template <class NDT> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
6624 static NDT |
10268
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6625 do_accumarray_minmax (const idx_vector& idx, const NDT& vals, |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6626 octave_idx_type n, bool ismin, |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6627 const typename NDT::element_type& zero_val) |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6628 { |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6629 typedef typename NDT::element_type T; |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6630 if (n < 0) |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6631 n = idx.extent (0); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6632 else if (idx.extent (n) > n) |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6633 error ("accumarray: index out of range"); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6634 |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6635 NDT retval (dim_vector (n, 1), zero_val); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6636 |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6637 // Pick minimizer or maximizer. |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
6638 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
|
6639 ismin ? (&MArray<T>::idx_min) : (&MArray<T>::idx_max); |
10268
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6640 |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6641 octave_idx_type l = idx.length (n); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6642 if (vals.numel () == 1) |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6643 (retval.*op) (idx, NDT (dim_vector (l, 1), vals(0))); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6644 else if (vals.numel () == l) |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6645 (retval.*op) (idx, vals); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6646 else |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6647 error ("accumarray: dimensions mismatch"); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6648 |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6649 return retval; |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6650 } |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6651 |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6652 static octave_value_list |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6653 do_accumarray_minmax_fun (const octave_value_list& args, |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6654 bool ismin) |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6655 { |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6656 octave_value retval; |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6657 int nargin = args.length (); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6658 if (nargin >= 3 && nargin <= 4 && args(0).is_numeric_type ()) |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6659 { |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6660 idx_vector idx = args(0).index_vector (); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6661 octave_idx_type n = -1; |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6662 if (nargin == 4) |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6663 n = args(3).idx_type_value (true); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6664 |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6665 if (! error_state) |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6666 { |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6667 octave_value vals = args(1), zero = args (2); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6668 |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6669 switch (vals.builtin_type ()) |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6670 { |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6671 case btyp_double: |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6672 retval = do_accumarray_minmax (idx, vals.array_value (), n, ismin, |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6673 zero.double_value ()); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6674 break; |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6675 case btyp_float: |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6676 retval = do_accumarray_minmax (idx, vals.float_array_value (), n, ismin, |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6677 zero.float_value ()); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6678 break; |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6679 case btyp_complex: |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6680 retval = do_accumarray_minmax (idx, vals.complex_array_value (), n, ismin, |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6681 zero.complex_value ()); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6682 break; |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6683 case btyp_float_complex: |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6684 retval = do_accumarray_minmax (idx, vals.float_complex_array_value (), n, ismin, |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6685 zero.float_complex_value ()); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6686 break; |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6687 #define MAKE_INT_BRANCH(X) \ |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6688 case btyp_ ## X: \ |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6689 retval = do_accumarray_minmax (idx, vals.X ## _array_value (), n, ismin, \ |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6690 zero.X ## _scalar_value ()); \ |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6691 break |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6692 |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6693 MAKE_INT_BRANCH (int8); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6694 MAKE_INT_BRANCH (int16); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6695 MAKE_INT_BRANCH (int32); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6696 MAKE_INT_BRANCH (int64); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6697 MAKE_INT_BRANCH (uint8); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6698 MAKE_INT_BRANCH (uint16); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6699 MAKE_INT_BRANCH (uint32); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6700 MAKE_INT_BRANCH (uint64); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6701 #undef MAKE_INT_BRANCH |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6702 case btyp_bool: |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6703 retval = do_accumarray_minmax (idx, vals.array_value (), n, ismin, |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6704 zero.bool_value ()); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6705 break; |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6706 default: |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6707 gripe_wrong_type_arg ("accumarray", vals); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6708 } |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6709 } |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6710 } |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6711 else |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6712 print_usage (); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6713 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
6714 return retval; |
10268
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6715 } |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6716 |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6717 DEFUN (__accumarray_min__, args, , |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6718 "-*- texinfo -*-\n\ |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6719 @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
|
6720 Undocumented internal function.\n\ |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6721 @end deftypefn") |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6722 { |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6723 return do_accumarray_minmax_fun (args, true); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6724 } |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6725 |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6726 DEFUN (__accumarray_max__, args, , |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6727 "-*- texinfo -*-\n\ |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6728 @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
|
6729 Undocumented internal function.\n\ |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6730 @end deftypefn") |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6731 { |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6732 return do_accumarray_minmax_fun (args, false); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6733 } |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6734 |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6735 template <class NDT> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
6736 static NDT |
10396
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6737 do_accumdim_sum (const idx_vector& idx, const NDT& vals, |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6738 int dim = -1, octave_idx_type n = -1) |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6739 { |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6740 typedef typename NDT::element_type T; |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6741 if (n < 0) |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6742 n = idx.extent (0); |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6743 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
|
6744 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
|
6745 |
dac62c415e8b
Do more error checking on accumarray and accumdim input.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14100
diff
changeset
|
6746 dim_vector vals_dim = vals.dims (), rdv = vals_dim; |
dac62c415e8b
Do more error checking on accumarray and accumdim input.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14100
diff
changeset
|
6747 |
10396
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6748 if (dim < 0) |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6749 dim = vals.dims ().first_non_singleton (); |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6750 else if (dim >= rdv.length ()) |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6751 rdv.resize (dim+1, 1); |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6752 |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6753 rdv(dim) = n; |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6754 |
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
|
6755 NDT retval (rdv, T ()); |
10396
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6756 |
14113
dac62c415e8b
Do more error checking on accumarray and accumdim input.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14100
diff
changeset
|
6757 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
|
6758 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
|
6759 |
10396
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6760 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
|
6761 |
10396
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6762 return retval; |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6763 } |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6764 |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6765 DEFUN (__accumdim_sum__, args, , |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6766 "-*- texinfo -*-\n\ |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6767 @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
|
6768 Undocumented internal function.\n\ |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6769 @end deftypefn") |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6770 { |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6771 octave_value retval; |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6772 int nargin = args.length (); |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6773 if (nargin >= 2 && nargin <= 4 && args(0).is_numeric_type ()) |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6774 { |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6775 idx_vector idx = args(0).index_vector (); |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6776 int dim = -1; |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6777 if (nargin >= 3) |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6778 dim = args(2).int_value () - 1; |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6779 |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6780 octave_idx_type n = -1; |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6781 if (nargin == 4) |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6782 n = args(3).idx_type_value (true); |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6783 |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6784 if (! error_state) |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6785 { |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6786 octave_value vals = args(1); |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6787 |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6788 if (vals.is_single_type ()) |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6789 { |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6790 if (vals.is_complex_type ()) |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6791 retval = do_accumdim_sum (idx, vals.float_complex_array_value (), dim, n); |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6792 else |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6793 retval = do_accumdim_sum (idx, vals.float_array_value (), dim, n); |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6794 } |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6795 else if (vals.is_numeric_type () || vals.is_bool_type ()) |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6796 { |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6797 if (vals.is_complex_type ()) |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6798 retval = do_accumdim_sum (idx, vals.complex_array_value (), dim, n); |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6799 else |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6800 retval = do_accumdim_sum (idx, vals.array_value (), dim, n); |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6801 } |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6802 else |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6803 gripe_wrong_type_arg ("accumdim", vals); |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6804 } |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6805 } |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6806 else |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6807 print_usage (); |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6808 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
6809 return retval; |
10396
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6810 } |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6811 |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6812 template <class NDT> |
9473
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6813 static NDT |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6814 do_merge (const Array<bool>& mask, |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6815 const NDT& tval, const NDT& fval) |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6816 { |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6817 typedef typename NDT::element_type T; |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6818 dim_vector dv = mask.dims (); |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6819 NDT retval (dv); |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6820 |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6821 bool tscl = tval.numel () == 1, fscl = fval.numel () == 1; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
6822 |
9473
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6823 if ((! tscl && tval.dims () != dv) |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6824 || (! 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
|
6825 error ("merge: MASK, TVAL, and FVAL dimensions must match"); |
9473
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6826 else |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6827 { |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6828 T *rv = retval.fortran_vec (); |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6829 octave_idx_type n = retval.numel (); |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6830 |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6831 const T *tv = tval.data (), *fv = fval.data (); |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6832 const bool *mv = mask.data (); |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6833 |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6834 if (tscl) |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6835 { |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6836 if (fscl) |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6837 { |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6838 T ts = tv[0], fs = fv[0]; |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6839 for (octave_idx_type i = 0; i < n; i++) |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6840 rv[i] = mv[i] ? ts : fs; |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6841 } |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6842 else |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6843 { |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6844 T ts = tv[0]; |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6845 for (octave_idx_type i = 0; i < n; i++) |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6846 rv[i] = mv[i] ? ts : fv[i]; |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6847 } |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6848 } |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6849 else |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6850 { |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6851 if (fscl) |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6852 { |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6853 T fs = fv[0]; |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6854 for (octave_idx_type i = 0; i < n; i++) |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6855 rv[i] = mv[i] ? tv[i] : fs; |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6856 } |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6857 else |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6858 { |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6859 for (octave_idx_type i = 0; i < n; i++) |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6860 rv[i] = mv[i] ? tv[i] : fv[i]; |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6861 } |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6862 } |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6863 } |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6864 |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6865 return retval; |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6866 } |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6867 |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6868 #define MAKE_INT_BRANCH(INTX) \ |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6869 else if (tval.is_ ## INTX ## _type () && fval.is_ ## INTX ## _type ()) \ |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6870 { \ |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6871 retval = do_merge (mask, \ |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6872 tval.INTX ## _array_value (), \ |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6873 fval.INTX ## _array_value ()); \ |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6874 } |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6875 |
9505
a321a1c227c8
make ifelse an alias or merge
Jaroslav Hajek <highegg@gmail.com>
parents:
9475
diff
changeset
|
6876 DEFUN (merge, args, , |
9473
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6877 "-*- texinfo -*-\n\ |
10840 | 6878 @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
|
6879 @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
|
6880 Merge elements of @var{true_val} and @var{false_val}, depending on the\n\ |
10846
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10840
diff
changeset
|
6881 value of @var{mask}. If @var{mask} is a logical scalar, the other two\n\ |
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10840
diff
changeset
|
6882 arguments can be arbitrary values. Otherwise, @var{mask} must be a logical\n\ |
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10840
diff
changeset
|
6883 array, and @var{tval}, @var{fval} should be arrays of matching class, or\n\ |
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10840
diff
changeset
|
6884 cell arrays. In the scalar mask case, @var{tval} is returned if @var{mask}\n\ |
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10840
diff
changeset
|
6885 is true, otherwise @var{fval} is returned.\n\ |
9473
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6886 \n\ |
10846
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10840
diff
changeset
|
6887 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
|
6888 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
|
6889 constructed as follows:\n\ |
10840 | 6890 \n\ |
9473
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6891 @example\n\ |
9758
09da0bd91412
Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents:
9736
diff
changeset
|
6892 @group\n\ |
9473
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6893 result(mask) = tval(mask);\n\ |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6894 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
|
6895 @end group\n\ |
9473
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6896 @end example\n\ |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6897 \n\ |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6898 @var{mask} can also be arbitrary numeric type, in which case\n\ |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6899 it is first converted to logical.\n\ |
15028
397f0d80bd47
Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents:
15024
diff
changeset
|
6900 @seealso{logical, diff}\n\ |
9473
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6901 @end deftypefn") |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6902 { |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6903 int nargin = args.length (); |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6904 octave_value retval; |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6905 |
9856 | 6906 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
|
6907 { |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6908 octave_value mask_val = args(0); |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6909 |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6910 if (mask_val.is_scalar_type ()) |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6911 retval = mask_val.is_true () ? args(1) : args(2); |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6912 else |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6913 { |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6914 boolNDArray mask = mask_val.bool_array_value (); |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6915 octave_value tval = args(1), fval = args(2); |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6916 if (tval.is_double_type () && fval.is_double_type ()) |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6917 { |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6918 if (tval.is_complex_type () || fval.is_complex_type ()) |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6919 retval = do_merge (mask, |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6920 tval.complex_array_value (), |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6921 fval.complex_array_value ()); |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6922 else |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6923 retval = do_merge (mask, |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6924 tval.array_value (), |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6925 fval.array_value ()); |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6926 } |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6927 else if (tval.is_single_type () && fval.is_single_type ()) |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6928 { |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6929 if (tval.is_complex_type () || fval.is_complex_type ()) |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6930 retval = do_merge (mask, |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6931 tval.float_complex_array_value (), |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6932 fval.float_complex_array_value ()); |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6933 else |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6934 retval = do_merge (mask, |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6935 tval.float_array_value (), |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6936 fval.float_array_value ()); |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6937 } |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6938 else if (tval.is_string () && fval.is_string ()) |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6939 { |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6940 bool sq_string = tval.is_sq_string () || fval.is_sq_string (); |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6941 retval = octave_value (do_merge (mask, |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6942 tval.char_array_value (), |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6943 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
|
6944 sq_string ? '\'' : '"'); |
9473
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6945 } |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6946 else if (tval.is_cell () && fval.is_cell ()) |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6947 { |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6948 retval = do_merge (mask, |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6949 tval.cell_value (), |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6950 fval.cell_value ()); |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6951 } |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6952 |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6953 MAKE_INT_BRANCH (int8) |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6954 MAKE_INT_BRANCH (int16) |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6955 MAKE_INT_BRANCH (int32) |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6956 MAKE_INT_BRANCH (int64) |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6957 MAKE_INT_BRANCH (uint8) |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6958 MAKE_INT_BRANCH (uint16) |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6959 MAKE_INT_BRANCH (uint32) |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6960 MAKE_INT_BRANCH (uint64) |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6961 |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6962 else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
6963 error ("merge: cannot merge %s with %s with array mask", |
9473
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6964 tval.class_name ().c_str (), |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6965 fval.class_name ().c_str ()); |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6966 } |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6967 } |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6968 else |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6969 print_usage (); |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6970 |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6971 return retval; |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6972 } |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6973 |
9505
a321a1c227c8
make ifelse an alias or merge
Jaroslav Hajek <highegg@gmail.com>
parents:
9475
diff
changeset
|
6974 DEFALIAS (ifelse, merge); |
a321a1c227c8
make ifelse an alias or merge
Jaroslav Hajek <highegg@gmail.com>
parents:
9475
diff
changeset
|
6975 |
9473
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6976 #undef MAKE_INT_BRANCH |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6977 |
9513
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6978 template <class SparseT> |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6979 static SparseT |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6980 do_sparse_diff (const SparseT& array, octave_idx_type order, |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6981 int dim) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6982 { |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6983 SparseT retval = array; |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6984 if (dim == 1) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6985 { |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6986 octave_idx_type k = retval.columns (); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6987 while (order > 0 && k > 0) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6988 { |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6989 idx_vector col1 (':'), col2 (':'), sl1 (1, k), sl2 (0, k-1); |
10785
c2041adcf234
remove unnecessary sparse indexing overloads
Jaroslav Hajek <highegg@gmail.com>
parents:
10763
diff
changeset
|
6990 retval = SparseT (retval.index (col1, sl1)) - SparseT (retval.index (col2, sl2)); |
9513
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6991 assert (retval.columns () == k-1); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6992 order--; |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6993 k--; |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6994 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6995 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6996 else |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6997 { |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6998 octave_idx_type k = retval.rows (); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6999 while (order > 0 && k > 0) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7000 { |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7001 idx_vector col1 (':'), col2 (':'), sl1 (1, k), sl2 (0, k-1); |
10785
c2041adcf234
remove unnecessary sparse indexing overloads
Jaroslav Hajek <highegg@gmail.com>
parents:
10763
diff
changeset
|
7002 retval = SparseT (retval.index (sl1, col1)) - SparseT (retval.index (sl2, col2)); |
9513
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7003 assert (retval.rows () == k-1); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7004 order--; |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7005 k--; |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7006 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7007 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7008 |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7009 return retval; |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7010 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7011 |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7012 static octave_value |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7013 do_diff (const octave_value& array, octave_idx_type order, |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7014 int dim = -1) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7015 { |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7016 octave_value retval; |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7017 |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7018 const dim_vector& dv = array.dims (); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7019 if (dim == -1) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7020 { |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7021 dim = array.dims ().first_non_singleton (); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7022 |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7023 // Bother Matlab. This behavior is really wicked. |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7024 if (dv(dim) <= order) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7025 { |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7026 if (dv(dim) == 1) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7027 retval = array.resize (dim_vector (0, 0)); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7028 else |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7029 { |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7030 retval = array; |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7031 while (order > 0) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7032 { |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7033 if (dim == dv.length ()) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7034 { |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7035 retval = do_diff (array, order, dim - 1); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7036 order = 0; |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7037 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7038 else if (dv(dim) == 1) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7039 dim++; |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7040 else |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7041 { |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7042 retval = do_diff (array, dv(dim) - 1, dim); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7043 order -= dv(dim) - 1; |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7044 dim++; |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7045 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7046 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7047 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7048 |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7049 return retval; |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7050 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7051 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7052 |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7053 if (array.is_integer_type ()) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7054 { |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7055 if (array.is_int8_type ()) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7056 retval = array.int8_array_value ().diff (order, dim); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7057 else if (array.is_int16_type ()) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7058 retval = array.int16_array_value ().diff (order, dim); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7059 else if (array.is_int32_type ()) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7060 retval = array.int32_array_value ().diff (order, dim); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7061 else if (array.is_int64_type ()) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7062 retval = array.int64_array_value ().diff (order, dim); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7063 else if (array.is_uint8_type ()) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7064 retval = array.uint8_array_value ().diff (order, dim); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7065 else if (array.is_uint16_type ()) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7066 retval = array.uint16_array_value ().diff (order, dim); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7067 else if (array.is_uint32_type ()) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7068 retval = array.uint32_array_value ().diff (order, dim); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7069 else if (array.is_uint64_type ()) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7070 retval = array.uint64_array_value ().diff (order, dim); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7071 else |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7072 panic_impossible (); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7073 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7074 else if (array.is_sparse_type ()) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7075 { |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7076 if (array.is_complex_type ()) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7077 retval = do_sparse_diff (array.sparse_complex_matrix_value (), order, dim); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7078 else |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7079 retval = do_sparse_diff (array.sparse_matrix_value (), order, dim); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7080 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7081 else if (array.is_single_type ()) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7082 { |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7083 if (array.is_complex_type ()) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7084 retval = array.float_complex_array_value ().diff (order, dim); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7085 else |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7086 retval = array.float_array_value ().diff (order, dim); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7087 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7088 else |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7089 { |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7090 if (array.is_complex_type ()) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7091 retval = array.complex_array_value ().diff (order, dim); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7092 else |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7093 retval = array.array_value ().diff (order, dim); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7094 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7095 |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7096 return retval; |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7097 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7098 |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7099 DEFUN (diff, args, , |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7100 "-*- texinfo -*-\n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
7101 @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
|
7102 @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
|
7103 @deftypefnx {Built-in Function} {} diff (@var{x}, @var{k}, @var{dim})\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
7104 If @var{x} is a vector of length @math{n}, @code{diff (@var{x})} is the\n\ |
9513
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7105 vector of first differences\n\ |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7106 @tex\n\ |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7107 $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
|
7108 @end tex\n\ |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7109 @ifnottex\n\ |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7110 @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
|
7111 @end ifnottex\n\ |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7112 \n\ |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7113 If @var{x} is a matrix, @code{diff (@var{x})} is the matrix of column\n\ |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7114 differences along the first non-singleton dimension.\n\ |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7115 \n\ |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7116 The second argument is optional. If supplied, @code{diff (@var{x},\n\ |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7117 @var{k})}, where @var{k} is a non-negative integer, returns the\n\ |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7118 @var{k}-th differences. It is possible that @var{k} is larger than\n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
7119 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
|
7120 @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
|
7121 non-singleton dimension.\n\ |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7122 \n\ |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7123 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
|
7124 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
|
7125 @var{k}-th order differences are calculated along this dimension.\n\ |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7126 In the case where @var{k} exceeds @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
|
7127 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
|
7128 @seealso{sort, merge}\n\ |
9513
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7129 @end deftypefn") |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7130 { |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7131 int nargin = args.length (); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7132 octave_value retval; |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7133 |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7134 if (nargin < 1 || nargin > 3) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7135 print_usage (); |
10880 | 7136 else if (! (args(0).is_numeric_type () || args(0).is_bool_type ())) |
7137 error ("diff: X must be numeric or logical"); | |
9513
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7138 |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7139 if (! error_state) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7140 { |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7141 int dim = -1; |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7142 octave_idx_type order = 1; |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7143 if (nargin > 1) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7144 { |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7145 if (args(1).is_scalar_type ()) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7146 order = args(1).idx_type_value (true, false); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7147 else if (! args(1).is_zero_by_zero ()) |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11591
diff
changeset
|
7148 error ("order K must be a scalar or []"); |
9513
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7149 if (! error_state && order < 0) |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11591
diff
changeset
|
7150 error ("order K must be non-negative"); |
9513
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7151 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7152 |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7153 if (nargin > 2) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7154 { |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7155 dim = args(2).int_value (true, false); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7156 if (! error_state && (dim < 1 || dim > args(0).ndims ())) |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11591
diff
changeset
|
7157 error ("DIM must be a valid dimension"); |
9513
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7158 else |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7159 dim -= 1; |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7160 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7161 |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7162 if (! error_state) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7163 retval = do_diff (args(0), order, dim); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7164 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7165 |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7166 return retval; |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7167 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7168 |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7169 /* |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7170 %!assert (diff ([1, 2, 3, 4]), [1, 1, 1]) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7171 %!assert (diff ([1, 3, 7, 19], 2), [2, 8]) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7172 %!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
|
7173 %!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
|
7174 %!assert (isempty (diff (1))) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
7175 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
7176 %!error diff () |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
7177 %!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
|
7178 %!error diff ("foo") |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14361
diff
changeset
|
7179 %!error diff ([1, 2; 3, 4], -1) |
9513
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
7180 */ |
10799
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7181 |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7182 template <class T> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
7183 static Array<T> |
10799
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7184 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
|
7185 { |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7186 Array<T> retval; |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7187 |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7188 assert (rep.ndims () == 2 && rep.rows () == 2); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7189 |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7190 octave_idx_type n = rep.columns (), l = 0; |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7191 for (octave_idx_type i = 0; i < n; i++) |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7192 { |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7193 octave_idx_type k = rep(1, i); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7194 if (k < 0) |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7195 { |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11591
diff
changeset
|
7196 error ("repelems: second row must contain non-negative numbers"); |
10799
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7197 return retval; |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7198 } |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7199 |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7200 l += k; |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7201 } |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7202 |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7203 retval.clear (1, l); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7204 T *dest = retval.fortran_vec (); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7205 l = 0; |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7206 for (octave_idx_type i = 0; i < n; i++) |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7207 { |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7208 octave_idx_type k = rep(1, i); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7209 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
|
7210 dest += k; |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7211 } |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7212 |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7213 return retval; |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7214 } |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7215 |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7216 DEFUN (repelems, args, , |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7217 "-*- texinfo -*-\n\ |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7218 @deftypefn {Built-in Function} {} repelems (@var{x}, @var{r})\n\ |
10801
a40e32927b3a
Improve documentation for new repelems function.
Rik <octave@nomad.inbox5.com>
parents:
10799
diff
changeset
|
7219 Construct a vector of repeated elements from @var{x}. @var{r}\n\ |
a40e32927b3a
Improve documentation for new repelems function.
Rik <octave@nomad.inbox5.com>
parents:
10799
diff
changeset
|
7220 is a 2x@var{N} integer matrix specifying which elements to repeat and\n\ |
a40e32927b3a
Improve documentation for new repelems function.
Rik <octave@nomad.inbox5.com>
parents:
10799
diff
changeset
|
7221 how often to repeat each element.\n\ |
a40e32927b3a
Improve documentation for new repelems function.
Rik <octave@nomad.inbox5.com>
parents:
10799
diff
changeset
|
7222 \n\ |
a40e32927b3a
Improve documentation for new repelems function.
Rik <octave@nomad.inbox5.com>
parents:
10799
diff
changeset
|
7223 Entries in the first row, @var{r}(1,j), select an element to repeat.\n\ |
a40e32927b3a
Improve documentation for new repelems function.
Rik <octave@nomad.inbox5.com>
parents:
10799
diff
changeset
|
7224 The corresponding entry in the second row, @var{r}(2,j), specifies\n\ |
a40e32927b3a
Improve documentation for new repelems function.
Rik <octave@nomad.inbox5.com>
parents:
10799
diff
changeset
|
7225 the repeat count. If @var{x} is a matrix then the columns of @var{x} are\n\ |
a40e32927b3a
Improve documentation for new repelems function.
Rik <octave@nomad.inbox5.com>
parents:
10799
diff
changeset
|
7226 imagined to be stacked on top of each other for purposes of the selection\n\ |
a40e32927b3a
Improve documentation for new repelems function.
Rik <octave@nomad.inbox5.com>
parents:
10799
diff
changeset
|
7227 index. A row vector is always returned.\n\ |
a40e32927b3a
Improve documentation for new repelems function.
Rik <octave@nomad.inbox5.com>
parents:
10799
diff
changeset
|
7228 \n\ |
a40e32927b3a
Improve documentation for new repelems function.
Rik <octave@nomad.inbox5.com>
parents:
10799
diff
changeset
|
7229 Conceptually the result is calculated as follows:\n\ |
10799
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7230 \n\ |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7231 @example\n\ |
10840 | 7232 @group\n\ |
10801
a40e32927b3a
Improve documentation for new repelems function.
Rik <octave@nomad.inbox5.com>
parents:
10799
diff
changeset
|
7233 y = [];\n\ |
a40e32927b3a
Improve documentation for new repelems function.
Rik <octave@nomad.inbox5.com>
parents:
10799
diff
changeset
|
7234 for i = 1:columns (@var{r})\n\ |
a40e32927b3a
Improve documentation for new repelems function.
Rik <octave@nomad.inbox5.com>
parents:
10799
diff
changeset
|
7235 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
|
7236 endfor\n\ |
10840 | 7237 @end group\n\ |
10799
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7238 @end example\n\ |
15028
397f0d80bd47
Added many *seealso* to the help messages
Doug Stewart <doug.dastew@gmail.com>
parents:
15024
diff
changeset
|
7239 @seealso{repmat, cat}\n\ |
10799
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7240 @end deftypefn") |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7241 { |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7242 octave_value retval; |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7243 |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7244 if (args.length () == 2) |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7245 { |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7246 octave_value x = args(0); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7247 |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7248 const Matrix rm = args(1).matrix_value (); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7249 if (error_state) |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7250 return retval; |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7251 else if (rm.rows () != 2 || rm.ndims () != 2) |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7252 { |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11591
diff
changeset
|
7253 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
|
7254 return retval; |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7255 } |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7256 else |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7257 { |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7258 NoAlias< Array<octave_idx_type> > r (rm.dims ()); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7259 |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7260 for (octave_idx_type i = 0; i < rm.numel (); i++) |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7261 { |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7262 octave_idx_type rx = rm(i); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7263 if (static_cast<double> (rx) != rm(i)) |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7264 { |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11591
diff
changeset
|
7265 error ("repelems: R must be a matrix of integers"); |
10799
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7266 return retval; |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7267 } |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7268 |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7269 r(i) = rx; |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7270 } |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7271 |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7272 switch (x.builtin_type ()) |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7273 { |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7274 #define BTYP_BRANCH(X, EX) \ |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7275 case btyp_ ## X: \ |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7276 retval = do_repelems (x.EX ## _value (), r); \ |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7277 break |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7278 |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7279 BTYP_BRANCH (double, array); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7280 BTYP_BRANCH (float, float_array); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7281 BTYP_BRANCH (complex, complex_array); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7282 BTYP_BRANCH (float_complex, float_complex_array); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7283 BTYP_BRANCH (bool, bool_array); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7284 BTYP_BRANCH (char, char_array); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7285 |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7286 BTYP_BRANCH (int8, int8_array); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7287 BTYP_BRANCH (int16, int16_array); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7288 BTYP_BRANCH (int32, int32_array); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7289 BTYP_BRANCH (int64, int64_array); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7290 BTYP_BRANCH (uint8, uint8_array); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7291 BTYP_BRANCH (uint16, uint16_array); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7292 BTYP_BRANCH (uint32, uint32_array); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7293 BTYP_BRANCH (uint64, uint64_array); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7294 |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7295 BTYP_BRANCH (cell, cell); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7296 //BTYP_BRANCH (struct, map);//FIXME |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7297 #undef BTYP_BRANCH |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7298 |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7299 default: |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7300 gripe_wrong_type_arg ("repelems", x); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7301 } |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7302 } |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7303 } |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7304 else |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7305 print_usage (); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7306 |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7307 return retval; |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
7308 } |
15050
abc858bc5165
Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15038
diff
changeset
|
7309 |
15252
fa0118cb67d9
move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents:
15213
diff
changeset
|
7310 DEFUN (base64_encode, args, , |
fa0118cb67d9
move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents:
15213
diff
changeset
|
7311 "-*- texinfo -*-\n\ |
15052
70a1b50bcb45
maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents:
15050
diff
changeset
|
7312 @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
|
7313 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
|
7314 @var{s}.\n\ |
70a1b50bcb45
maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents:
15050
diff
changeset
|
7315 \n\ |
15050
abc858bc5165
Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15038
diff
changeset
|
7316 @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
|
7317 @end deftypefn") |
abc858bc5165
Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15038
diff
changeset
|
7318 { |
abc858bc5165
Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15038
diff
changeset
|
7319 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
|
7320 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
|
7321 |
15050
abc858bc5165
Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15038
diff
changeset
|
7322 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
|
7323 print_usage (); |
abc858bc5165
Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15038
diff
changeset
|
7324 else |
abc858bc5165
Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15038
diff
changeset
|
7325 { |
15111
5dd599df36de
generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15094
diff
changeset
|
7326 if (! args(0).is_numeric_type ()) |
5dd599df36de
generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15094
diff
changeset
|
7327 error ("base64_encode: encoding is supported only for numeric arrays"); |
5dd599df36de
generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15094
diff
changeset
|
7328 else if (args(0).is_complex_type () |
5dd599df36de
generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15094
diff
changeset
|
7329 || args(0).is_sparse_type ()) |
5dd599df36de
generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15094
diff
changeset
|
7330 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
|
7331 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
|
7332 { |
15111
5dd599df36de
generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15094
diff
changeset
|
7333 #define MAKE_INT_BRANCH(X) \ |
5dd599df36de
generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15094
diff
changeset
|
7334 if (args(0).is_ ## X ## _type ()) \ |
5dd599df36de
generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15094
diff
changeset
|
7335 { \ |
5dd599df36de
generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15094
diff
changeset
|
7336 const X##NDArray in = args(0). X## _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
|
7337 size_t inlen = \ |
5dd599df36de
generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15094
diff
changeset
|
7338 in.numel () * sizeof (X## _t) / sizeof (char); \ |
5dd599df36de
generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15094
diff
changeset
|
7339 const char* inc = \ |
5dd599df36de
generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15094
diff
changeset
|
7340 reinterpret_cast<const char*> (in.data ()); \ |
5dd599df36de
generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15094
diff
changeset
|
7341 char* out; \ |
5dd599df36de
generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15094
diff
changeset
|
7342 if (! error_state \ |
15252
fa0118cb67d9
move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents:
15213
diff
changeset
|
7343 && octave_base64_encode (inc, inlen, &out)) \ |
15111
5dd599df36de
generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15094
diff
changeset
|
7344 retval(0) = octave_value (out); \ |
5dd599df36de
generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15094
diff
changeset
|
7345 } |
5dd599df36de
generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15094
diff
changeset
|
7346 |
5dd599df36de
generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15094
diff
changeset
|
7347 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
|
7348 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
|
7349 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
|
7350 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
|
7351 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
|
7352 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
|
7353 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
|
7354 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
|
7355 #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
|
7356 |
5dd599df36de
generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15094
diff
changeset
|
7357 else |
5dd599df36de
generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15094
diff
changeset
|
7358 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
|
7359 } |
5dd599df36de
generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15094
diff
changeset
|
7360 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
|
7361 { |
5dd599df36de
generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15094
diff
changeset
|
7362 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
|
7363 size_t inlen; |
5dd599df36de
generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15094
diff
changeset
|
7364 inlen = in.numel () * sizeof (float) / sizeof (char); |
5dd599df36de
generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15094
diff
changeset
|
7365 const char* inc; |
5dd599df36de
generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15094
diff
changeset
|
7366 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
|
7367 char* out; |
15111
5dd599df36de
generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15094
diff
changeset
|
7368 if (! error_state |
15252
fa0118cb67d9
move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents:
15213
diff
changeset
|
7369 && octave_base64_encode (inc, inlen, &out)) |
15111
5dd599df36de
generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15094
diff
changeset
|
7370 retval(0) = octave_value (out); |
5dd599df36de
generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15094
diff
changeset
|
7371 } |
5dd599df36de
generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15094
diff
changeset
|
7372 else |
5dd599df36de
generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15094
diff
changeset
|
7373 { |
5dd599df36de
generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15094
diff
changeset
|
7374 const Array<double> in = args(0).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
|
7375 size_t inlen; |
5dd599df36de
generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15094
diff
changeset
|
7376 inlen = in.numel () * sizeof (double) / sizeof (char); |
5dd599df36de
generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15094
diff
changeset
|
7377 const char* inc; |
5dd599df36de
generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15094
diff
changeset
|
7378 inc = reinterpret_cast<const char*> (in.data ()); |
5dd599df36de
generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15094
diff
changeset
|
7379 char* out; |
5dd599df36de
generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15094
diff
changeset
|
7380 if (! error_state |
15252
fa0118cb67d9
move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents:
15213
diff
changeset
|
7381 && octave_base64_encode (inc, inlen, &out)) |
15052
70a1b50bcb45
maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents:
15050
diff
changeset
|
7382 retval(0) = octave_value (out); |
15050
abc858bc5165
Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15038
diff
changeset
|
7383 } |
15111
5dd599df36de
generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15094
diff
changeset
|
7384 } |
15052
70a1b50bcb45
maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents:
15050
diff
changeset
|
7385 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
|
7386 } |
abc858bc5165
Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15038
diff
changeset
|
7387 |
abc858bc5165
Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15038
diff
changeset
|
7388 /* |
15111
5dd599df36de
generalize base64_encode to work with data types other than double
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15094
diff
changeset
|
7389 %!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
|
7390 %!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
|
7391 %!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
|
7392 %!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
|
7393 %!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
|
7394 %!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
|
7395 |
70a1b50bcb45
maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents:
15050
diff
changeset
|
7396 %!error base64_encode () |
70a1b50bcb45
maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents:
15050
diff
changeset
|
7397 %!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
|
7398 %!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
|
7399 %!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
|
7400 %!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
|
7401 */ |
abc858bc5165
Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15038
diff
changeset
|
7402 |
15252
fa0118cb67d9
move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents:
15213
diff
changeset
|
7403 DEFUN (base64_decode, args, , |
fa0118cb67d9
move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents:
15213
diff
changeset
|
7404 "-*- texinfo -*-\n\ |
15052
70a1b50bcb45
maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents:
15050
diff
changeset
|
7405 @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
|
7406 @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
|
7407 Decode the double matrix or array @var{x} from the base64 encoded string\n\ |
15052
70a1b50bcb45
maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents:
15050
diff
changeset
|
7408 @var{s}. The optional input parameter @var{dims} should be a vector\n\ |
70a1b50bcb45
maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents:
15050
diff
changeset
|
7409 containing the 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
|
7410 @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
|
7411 @end deftypefn") |
abc858bc5165
Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15038
diff
changeset
|
7412 { |
15252
fa0118cb67d9
move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents:
15213
diff
changeset
|
7413 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
|
7414 |
abc858bc5165
Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15038
diff
changeset
|
7415 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
|
7416 |
15050
abc858bc5165
Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15038
diff
changeset
|
7417 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
|
7418 print_usage (); |
15052
70a1b50bcb45
maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents:
15050
diff
changeset
|
7419 else |
15050
abc858bc5165
Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15038
diff
changeset
|
7420 { |
15252
fa0118cb67d9
move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents:
15213
diff
changeset
|
7421 dim_vector dims; |
15052
70a1b50bcb45
maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents:
15050
diff
changeset
|
7422 |
15050
abc858bc5165
Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15038
diff
changeset
|
7423 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
|
7424 { |
15252
fa0118cb67d9
move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents:
15213
diff
changeset
|
7425 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
|
7426 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
|
7427 |
15050
abc858bc5165
Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15038
diff
changeset
|
7428 if (! error_state) |
abc858bc5165
Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15038
diff
changeset
|
7429 { |
15252
fa0118cb67d9
move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents:
15213
diff
changeset
|
7430 dims = dim_vector::alloc (size.length ()); |
fa0118cb67d9
move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents:
15213
diff
changeset
|
7431 for (octave_idx_type i = 0; i < size.length (); i++) |
fa0118cb67d9
move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents:
15213
diff
changeset
|
7432 dims(i) = size(i); |
15050
abc858bc5165
Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15038
diff
changeset
|
7433 } |
15052
70a1b50bcb45
maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents:
15050
diff
changeset
|
7434 } |
15050
abc858bc5165
Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15038
diff
changeset
|
7435 |
15252
fa0118cb67d9
move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents:
15213
diff
changeset
|
7436 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
|
7437 |
abc858bc5165
Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15038
diff
changeset
|
7438 if (! error_state) |
15052
70a1b50bcb45
maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents:
15050
diff
changeset
|
7439 { |
15252
fa0118cb67d9
move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents:
15213
diff
changeset
|
7440 Array<double> res = octave_base64_decode (str); |
fa0118cb67d9
move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents:
15213
diff
changeset
|
7441 |
fa0118cb67d9
move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents:
15213
diff
changeset
|
7442 if (nargin > 1) |
fa0118cb67d9
move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents:
15213
diff
changeset
|
7443 res = res.reshape (dims); |
fa0118cb67d9
move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents:
15213
diff
changeset
|
7444 |
fa0118cb67d9
move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents:
15213
diff
changeset
|
7445 retval = res; |
fa0118cb67d9
move base64 encode and decode functionality to liboctave
John W. Eaton <jwe@octave.org>
parents:
15213
diff
changeset
|
7446 } |
15050
abc858bc5165
Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15038
diff
changeset
|
7447 } |
15052
70a1b50bcb45
maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents:
15050
diff
changeset
|
7448 |
15050
abc858bc5165
Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15038
diff
changeset
|
7449 return retval; |
abc858bc5165
Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15038
diff
changeset
|
7450 } |
abc858bc5165
Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15038
diff
changeset
|
7451 |
abc858bc5165
Add functions to encode/decode double arrays to/from base64.
Carlo de Falco <cdf@users.sourceforge.net>
parents:
15038
diff
changeset
|
7452 /* |
15052
70a1b50bcb45
maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents:
15050
diff
changeset
|
7453 %!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
|
7454 %! |
70a1b50bcb45
maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents:
15050
diff
changeset
|
7455 %!test |
70a1b50bcb45
maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents:
15050
diff
changeset
|
7456 %! in = randn (10); |
70a1b50bcb45
maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents:
15050
diff
changeset
|
7457 %! outv = base64_decode (base64_encode (in)); |
70a1b50bcb45
maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents:
15050
diff
changeset
|
7458 %! outm = base64_decode (base64_encode (in), size (in)); |
70a1b50bcb45
maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents:
15050
diff
changeset
|
7459 %! assert (outv, in(:).'); |
70a1b50bcb45
maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents:
15050
diff
changeset
|
7460 %! assert (outm, in); |
70a1b50bcb45
maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents:
15050
diff
changeset
|
7461 |
70a1b50bcb45
maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents:
15050
diff
changeset
|
7462 %!error base64_decode () |
70a1b50bcb45
maint: Use some Octave coding conventions for base64_encode, base64_decode.
Rik <rik@octave.org>
parents:
15050
diff
changeset
|
7463 %!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
|
7464 %!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
|
7465 %!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
|
7466 %!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
|
7467 %!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
|
7468 */ |