Mercurial > octave-nkf
annotate src/data.cc @ 12905:f7a8d1dafda3
Let rand accept negative dimensions (bug #33301)
* rand.cc (do_rand): Make it so that ranges, matrices, and individual
arguments treat negative dimensions as zero.
* data.cc (eye): Document that negative dimensions are treated as zero
(rand's docstring references eye)
author | Jordi Gutiérrez Hermoso <jordigh@gmail.com> |
---|---|
date | Tue, 02 Aug 2011 10:50:11 -0500 |
parents | a539714f3291 |
children | 0dc4d9f1366c |
rev | line source |
---|---|
523 | 1 /* |
2 | |
11523 | 3 Copyright (C) 1994-2011 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 |
523 | 6 |
7 This file is part of Octave. | |
8 | |
9 Octave is free software; you can redistribute it and/or modify it | |
10 under the terms of the GNU General Public License as published by the | |
7016 | 11 Free Software Foundation; either version 3 of the License, or (at your |
12 option) any later version. | |
523 | 13 |
14 Octave is distributed in the hope that it will be useful, but WITHOUT | |
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
17 for more details. | |
18 | |
19 You should have received a copy of the GNU General Public License | |
7016 | 20 along with Octave; see the file COPYING. If not, see |
21 <http://www.gnu.org/licenses/>. | |
523 | 22 |
23 */ | |
24 | |
25 #ifdef HAVE_CONFIG_H | |
1192 | 26 #include <config.h> |
523 | 27 #endif |
28 | |
7078 | 29 #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
|
30 #include <sys/times.h> |
7078 | 31 |
32 #ifdef HAVE_SYS_RESOURCE_H | |
33 #include <sys/resource.h> | |
34 #endif | |
35 | |
2184 | 36 #include <cfloat> |
10303
e4899d6320b6
data.cc: use CLOCKS_PER_SEC instead of HZ
John W. Eaton <jwe@octave.org>
parents:
10302
diff
changeset
|
37 #include <ctime> |
2184 | 38 |
1728 | 39 #include <string> |
40 | |
2184 | 41 #include "lo-ieee.h" |
7231 | 42 #include "lo-math.h" |
10240
fa7b5751730c
use gnulib time, sys_time, and sys_times modules
John W. Eaton <jwe@octave.org>
parents:
10185
diff
changeset
|
43 #include "oct-time.h" |
1755 | 44 #include "str-vec.h" |
4153 | 45 #include "quit.h" |
9658
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
46 #include "mx-base.h" |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
47 #include "oct-binmap.h" |
1755 | 48 |
6953 | 49 #include "Cell.h" |
1352 | 50 #include "defun.h" |
51 #include "error.h" | |
52 #include "gripes.h" | |
6953 | 53 #include "oct-map.h" |
54 #include "oct-obj.h" | |
2366 | 55 #include "ov.h" |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7743
diff
changeset
|
56 #include "ov-float.h" |
5476 | 57 #include "ov-complex.h" |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7743
diff
changeset
|
58 #include "ov-flt-complex.h" |
5476 | 59 #include "ov-cx-mat.h" |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7743
diff
changeset
|
60 #include "ov-flt-cx-mat.h" |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7743
diff
changeset
|
61 #include "ov-cx-sparse.h" |
6953 | 62 #include "parse.h" |
63 #include "pt-mat.h" | |
523 | 64 #include "utils.h" |
6953 | 65 #include "variables.h" |
7045 | 66 #include "pager.h" |
8303
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
67 #include "xnorm.h" |
523 | 68 |
10303
e4899d6320b6
data.cc: use CLOCKS_PER_SEC instead of HZ
John W. Eaton <jwe@octave.org>
parents:
10302
diff
changeset
|
69 #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
|
70 #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
|
71 #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
|
72 #else |
10303
e4899d6320b6
data.cc: use CLOCKS_PER_SEC instead of HZ
John W. Eaton <jwe@octave.org>
parents:
10302
diff
changeset
|
73 #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
|
74 #endif |
5669a0b893db
data.cc: include <sys/times.h> and ensure that HZ is defined
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
75 #endif |
5669a0b893db
data.cc: include <sys/times.h> and ensure that HZ is defined
John W. Eaton <jwe@octave.org>
parents:
10293
diff
changeset
|
76 |
7914
e998e81224b5
Various compilation fixes for MSVC.
John W. Eaton <jwe@octave.org>
parents:
7815
diff
changeset
|
77 #if ! defined (HAVE_HYPOTF) && defined (HAVE__HYPOTF) |
e998e81224b5
Various compilation fixes for MSVC.
John W. Eaton <jwe@octave.org>
parents:
7815
diff
changeset
|
78 #define hypotf _hypotf |
e998e81224b5
Various compilation fixes for MSVC.
John W. Eaton <jwe@octave.org>
parents:
7815
diff
changeset
|
79 #define HAVE_HYPOTF 1 |
e998e81224b5
Various compilation fixes for MSVC.
John W. Eaton <jwe@octave.org>
parents:
7815
diff
changeset
|
80 #endif |
e998e81224b5
Various compilation fixes for MSVC.
John W. Eaton <jwe@octave.org>
parents:
7815
diff
changeset
|
81 |
4015 | 82 #define ANY_ALL(FCN) \ |
83 \ | |
4233 | 84 octave_value retval; \ |
4015 | 85 \ |
86 int nargin = args.length (); \ | |
87 \ | |
4021 | 88 if (nargin == 1 || nargin == 2) \ |
4015 | 89 { \ |
4021 | 90 int dim = (nargin == 1 ? -1 : args(1).int_value (true) - 1); \ |
91 \ | |
92 if (! error_state) \ | |
93 { \ | |
4556 | 94 if (dim >= -1) \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
95 retval = args(0).FCN (dim); \ |
4021 | 96 else \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
97 error (#FCN ": invalid dimension argument = %d", dim + 1); \ |
4021 | 98 } \ |
4015 | 99 else \ |
4021 | 100 error (#FCN ": expecting dimension argument to be an integer"); \ |
4015 | 101 } \ |
4021 | 102 else \ |
5823 | 103 print_usage (); \ |
4015 | 104 \ |
105 return retval | |
106 | |
1957 | 107 DEFUN (all, args, , |
3369 | 108 "-*- texinfo -*-\n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
109 @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
|
110 @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
|
111 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
|
112 are nonzero.\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
113 \n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
114 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
|
115 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
|
116 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
|
117 \n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
118 @example\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
119 @group\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
120 all ([2, 3; 1, 0]))\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
121 @result{} [ 1, 0 ]\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
122 @end group\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
123 @end example\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
124 \n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
125 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
|
126 @var{dim}.\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
127 @seealso{any}\n\ |
3369 | 128 @end deftypefn") |
523 | 129 { |
4015 | 130 ANY_ALL (all); |
523 | 131 } |
132 | |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
133 /* |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
134 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
135 %!test |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
136 %! 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
|
137 %! x(1,1) = 0; |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
138 %! assert((all (all (rand (3) + 1) == [1, 1, 1]) == 1 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
139 %! && all (all (x) == [0, 1, 1]) == 1 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
140 %! && all (x, 1) == [0, 1, 1] |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
141 %! && all (x, 2) == [0; 1; 1])); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
142 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
143 %!test |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
144 %! x = ones (3, 'single'); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
145 %! x(1,1) = 0; |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
146 %! assert((all (all (single (rand (3) + 1)) == [1, 1, 1]) == 1 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
147 %! && all (all (x) == [0, 1, 1]) == 1 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
148 %! && all (x, 1) == [0, 1, 1] |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
149 %! && all (x, 2) == [0; 1; 1])); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
150 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
151 %!error <Invalid call to all.*> all (); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
152 %!error <Invalid call to all.*> all (1, 2, 3); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
153 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
154 */ |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
155 |
1957 | 156 DEFUN (any, args, , |
3369 | 157 "-*- texinfo -*-\n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
158 @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
|
159 @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
|
160 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
|
161 is nonzero.\n\ |
3369 | 162 \n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
163 For a matrix argument, return a row vector of logical ones and\n\ |
3369 | 164 zeros with each element indicating whether any of the elements of the\n\ |
10840 | 165 corresponding column of the matrix are nonzero. For example:\n\ |
3369 | 166 \n\ |
167 @example\n\ | |
168 @group\n\ | |
169 any (eye (2, 4))\n\ | |
170 @result{} [ 1, 1, 0, 0 ]\n\ | |
171 @end group\n\ | |
172 @end example\n\ | |
173 \n\ | |
4015 | 174 If the optional argument @var{dim} is supplied, work along dimension\n\ |
10840 | 175 @var{dim}. For example:\n\ |
3369 | 176 \n\ |
177 @example\n\ | |
4015 | 178 @group\n\ |
179 any (eye (2, 4), 2)\n\ | |
180 @result{} [ 1; 1 ]\n\ | |
181 @end group\n\ | |
3369 | 182 @end example\n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
183 @seealso{all}\n\ |
3369 | 184 @end deftypefn") |
523 | 185 { |
4015 | 186 ANY_ALL (any); |
523 | 187 } |
188 | |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
189 /* |
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; |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
194 %! assert((all (any (x) == [0, 0, 1]) == 1 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
195 %! && all (any (ones (3)) == [1, 1, 1]) == 1 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
196 %! && any (x, 1) == [0, 0, 1] |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
197 %! && any (x, 2) == [0; 0; 1])); |
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 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
200 %! x = zeros (3,'single'); |
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; |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
202 %! assert((all (any (x) == [0, 0, 1]) == 1 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
203 %! && all (any (ones (3, 'single')) == [1, 1, 1]) == 1 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
204 %! && any (x, 1) == [0, 0, 1] |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
205 %! && any (x, 2) == [0; 0; 1])); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
206 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
207 %!error <Invalid call to any.*> any (); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
208 %!error <Invalid call to any.*> any (1, 2, 3); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
209 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
210 */ |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
211 |
649 | 212 // These mapping functions may also be useful in other places, eh? |
213 | |
1957 | 214 DEFUN (atan2, args, , |
3428 | 215 "-*- texinfo -*-\n\ |
216 @deftypefn {Mapping Function} {} atan2 (@var{y}, @var{x})\n\ | |
217 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
|
218 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
|
219 and orientation.\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]; |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
285 %! assert(atan2 (y, x), v, sqrt (eps)); |
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); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
290 %! v = single([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
|
291 %! y = single([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
|
292 %! x = single([1, 3, 1, 1, 1, 1, 3, 1]); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
293 %! assert(atan2 (y, x), v, sqrt (eps('single'))); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
294 |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
295 %!error <Invalid call to atan2.*> atan2 (); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
296 %!error <Invalid call to atan2.*> atan2 (1, 2, 3); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
297 |
7506
798b0a00e80c
atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents:
7505
diff
changeset
|
298 */ |
798b0a00e80c
atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents:
7505
diff
changeset
|
299 |
7815
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
300 |
10538
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
301 static octave_value |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
302 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
|
303 { |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
304 octave_value retval; |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
305 |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
306 octave_value arg0 = x, arg1 = y; |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
307 if (! arg0.is_numeric_type ()) |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
308 gripe_wrong_type_arg ("hypot", arg0); |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
309 else if (! arg1.is_numeric_type ()) |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
310 gripe_wrong_type_arg ("hypot", arg1); |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
311 else |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
312 { |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
313 if (arg0.is_complex_type ()) |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
314 arg0 = arg0.abs (); |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
315 if (arg1.is_complex_type ()) |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
316 arg1 = arg1.abs (); |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
317 |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
318 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
|
319 { |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
320 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
|
321 retval = hypotf (arg0.float_value (), arg1.float_value ()); |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
322 else |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
323 { |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
324 FloatNDArray a0 = arg0.float_array_value (); |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
325 FloatNDArray a1 = arg1.float_array_value (); |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
326 retval = binmap<float> (a0, a1, ::hypotf, "hypot"); |
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 } |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
329 else |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
330 { |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
331 bool a0_scalar = arg0.is_scalar_type (); |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
332 bool a1_scalar = arg1.is_scalar_type (); |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
333 if (a0_scalar && a1_scalar) |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
334 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
|
335 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
|
336 && (a1_scalar || arg1.is_sparse_type ())) |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
337 { |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
338 SparseMatrix m0 = arg0.sparse_matrix_value (); |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
339 SparseMatrix m1 = arg1.sparse_matrix_value (); |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
340 retval = binmap<double> (m0, m1, ::hypot, "hypot"); |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
341 } |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
342 else |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
343 { |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
344 NDArray a0 = arg0.array_value (); |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
345 NDArray a1 = arg1.array_value (); |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
346 retval = binmap<double> (a0, a1, ::hypot, "hypot"); |
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 |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
351 return retval; |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
352 } |
7815
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
353 |
7631 | 354 DEFUN (hypot, args, , |
355 "-*- texinfo -*-\n\ | |
10840 | 356 @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
|
357 @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
|
358 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
|
359 @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
|
360 @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
|
361 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
|
362 @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
|
363 the arguments are accumulated from left to right:\n\ |
10840 | 364 \n\ |
10538
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
365 @example\n\ |
10711
fbd7843974fa
Periodic grammar check of documentation files to ensure common format.
Rik <octave@nomad.inbox5.com>
parents:
10707
diff
changeset
|
366 @group\n\ |
10538
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
367 hypot (hypot (@var{x}, @var{y}), @var{z})\n\ |
10711
fbd7843974fa
Periodic grammar check of documentation files to ensure common format.
Rik <octave@nomad.inbox5.com>
parents:
10707
diff
changeset
|
368 hypot (hypot (hypot (@var{x}, @var{y}), @var{z}), @var{w}), etc.\n\ |
fbd7843974fa
Periodic grammar check of documentation files to ensure common format.
Rik <octave@nomad.inbox5.com>
parents:
10707
diff
changeset
|
369 @end group\n\ |
10538
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
370 @end example\n\ |
7631 | 371 @end deftypefn") |
372 { | |
373 octave_value retval; | |
374 | |
375 int nargin = args.length (); | |
376 | |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
377 if (nargin == 2) |
7631 | 378 { |
10538
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
379 retval = do_hypot (args(0), args(1)); |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
380 } |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
381 else if (nargin >= 3) |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
382 { |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
383 retval = args(0); |
26673015caec
extend hypot to accept >2 args
Jaroslav Hajek <highegg@gmail.com>
parents:
10533
diff
changeset
|
384 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
|
385 retval = do_hypot (retval, args(i)); |
7631 | 386 } |
387 else | |
388 print_usage (); | |
389 | |
390 return retval; | |
391 } | |
392 | |
393 /* | |
7741 | 394 %!assert (size (hypot (zeros (0, 2), zeros (0, 2))), [0, 2]) |
395 %!assert (size (hypot (rand (2, 3, 4), zeros (2, 3, 4))), [2, 3, 4]) | |
396 %!assert (size (hypot (rand (2, 3, 4), 1)), [2, 3, 4]) | |
397 %!assert (size (hypot (1, rand (2, 3, 4))), [2, 3, 4]) | |
398 %!assert (size (hypot (1, 2)), [1, 1]) | |
399 %!assert (hypot (1:10, 1:10), sqrt(2) * [1:10], 16*eps) | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7743
diff
changeset
|
400 %!assert (hypot (single(1:10), single(1:10)), single(sqrt(2) * [1:10])); |
7631 | 401 */ |
402 | |
9813
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
403 template<typename T, typename ET> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
404 void |
9813
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
405 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
|
406 { |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
407 f = Array<T>(x.dims ()); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
408 e = Array<ET>(x.dims ()); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
409 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
|
410 { |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
411 int exp; |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
412 f.xelem (i) = xlog2 (x(i), exp); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
413 e.xelem (i) = exp; |
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 |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
417 DEFUN (log2, args, nargout, |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
418 "-*- texinfo -*-\n\ |
10840 | 419 @deftypefn {Mapping Function} {} log2 (@var{x})\n\ |
9813
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
420 @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
|
421 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
|
422 \n\ |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
423 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
|
424 binary mantissa and exponent so that\n\ |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
425 @tex\n\ |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
426 ${1 \\over 2} \\le \\left| f \\right| < 1$\n\ |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
427 @end tex\n\ |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
428 @ifnottex\n\ |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
429 @code{1/2 <= abs(f) < 1}\n\ |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
430 @end ifnottex\n\ |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
431 and @var{e} is an integer. If\n\ |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
432 @tex\n\ |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
433 $x = 0$, $f = e = 0$.\n\ |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
434 @end tex\n\ |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
435 @ifnottex\n\ |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
436 @code{x = 0}, @code{f = e = 0}.\n\ |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
437 @end ifnottex\n\ |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
438 @seealso{pow2, log, log10, exp}\n\ |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
439 @end deftypefn") |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
440 { |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
441 octave_value_list retval; |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
442 |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
443 if (args.length () == 1) |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
444 { |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
445 if (nargout < 2) |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
446 retval(0) = args(0).log2 (); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
447 else if (args(0).is_single_type ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
448 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
449 if (args(0).is_real_type ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
450 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
451 FloatNDArray f; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
452 FloatNDArray x = args(0).float_array_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
453 // FIXME -- should E be an int value? |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
454 FloatMatrix e; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
455 map_2_xlog2 (x, f, e); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
456 retval (1) = e; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
457 retval (0) = f; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
458 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
459 else if (args(0).is_complex_type ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
460 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
461 FloatComplexNDArray f; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
462 FloatComplexNDArray x = args(0).float_complex_array_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
463 // FIXME -- should E be an int value? |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
464 FloatNDArray e; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
465 map_2_xlog2 (x, f, e); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
466 retval (1) = e; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
467 retval (0) = f; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
468 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
469 } |
9813
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
470 else if (args(0).is_real_type ()) |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
471 { |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
472 NDArray f; |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
473 NDArray x = args(0).array_value (); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
474 // FIXME -- should E be an int value? |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
475 Matrix e; |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
476 map_2_xlog2 (x, f, e); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
477 retval (1) = e; |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
478 retval (0) = f; |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
479 } |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
480 else if (args(0).is_complex_type ()) |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
481 { |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
482 ComplexNDArray f; |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
483 ComplexNDArray x = args(0).complex_array_value (); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
484 // FIXME -- should E be an int value? |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
485 NDArray e; |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
486 map_2_xlog2 (x, f, e); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
487 retval (1) = e; |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
488 retval (0) = f; |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
489 } |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
490 else |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
491 gripe_wrong_type_arg ("log2", args(0)); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
492 } |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
493 else |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
494 print_usage (); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
495 |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
496 return retval; |
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 |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
499 /* |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
500 %!assert(log2 ([1/4, 1/2, 1, 2, 4]), [-2, -1, 0, 1, 2]); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
501 %!assert(log2(Inf), Inf); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
502 %!assert(isnan(log2(NaN))); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
503 %!assert(log2(4*i), 2 + log2(1*i)); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
504 %!assert(log2(complex(0,Inf)), Inf + log2(i)); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
505 |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
506 %!test |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
507 %! [f, e] = log2 ([0,-1; 2,-4; Inf,-Inf]); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
508 %! assert (f, [0,-0.5; 0.5,-0.5; Inf,-Inf]); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
509 %! assert (e(1:2,:), [0,1;2,3]) |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
510 |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
511 %!test |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
512 %! [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
|
513 %! 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
|
514 %! assert (e(1:2,:), [0,1; 2,3]); |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
515 */ |
8fa32b527d9a
improve & partially revert previous change
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
516 |
10436
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
517 DEFUN (rem, args, , |
4311 | 518 "-*- texinfo -*-\n\ |
10840 | 519 @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
|
520 @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
|
521 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
|
522 using the expression\n\ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
523 \n\ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
524 @example\n\ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
525 x - y .* fix (x ./ y)\n\ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
526 @end example\n\ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
527 \n\ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
528 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
|
529 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
|
530 @seealso{mod}\n\ |
4311 | 531 @end deftypefn") |
532 { | |
533 octave_value retval; | |
534 | |
535 int nargin = args.length (); | |
536 | |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
537 if (nargin == 2) |
4311 | 538 { |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
539 if (! args(0).is_numeric_type ()) |
10436
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
540 gripe_wrong_type_arg ("rem", args(0)); |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
541 else if (! args(1).is_numeric_type ()) |
10436
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
542 gripe_wrong_type_arg ("rem", args(1)); |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
543 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
|
544 error ("rem: not defined for complex numbers"); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
545 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
|
546 { |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
547 builtin_type_t btyp0 = args(0).builtin_type (); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
548 builtin_type_t btyp1 = args(1).builtin_type (); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
549 if (btyp0 == btyp_double || btyp0 == btyp_float) |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
550 btyp0 = btyp1; |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
551 if (btyp1 == btyp_double || btyp1 == btyp_float) |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
552 btyp1 = btyp0; |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
553 |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
554 if (btyp0 == btyp1) |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
555 { |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
556 switch (btyp0) |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
557 { |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
558 #define MAKE_INT_BRANCH(X) \ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
559 case btyp_ ## X: \ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
560 { \ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
561 X##NDArray a0 = args(0).X##_array_value (); \ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
562 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
|
563 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
|
564 } \ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
565 break |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
566 MAKE_INT_BRANCH (int8); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
567 MAKE_INT_BRANCH (int16); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
568 MAKE_INT_BRANCH (int32); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
569 MAKE_INT_BRANCH (int64); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
570 MAKE_INT_BRANCH (uint8); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
571 MAKE_INT_BRANCH (uint16); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
572 MAKE_INT_BRANCH (uint32); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
573 MAKE_INT_BRANCH (uint64); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
574 #undef MAKE_INT_BRANCH |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
575 default: |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
576 panic_impossible (); |
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 } |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
579 else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
580 error ("rem: cannot combine %s and %d", |
10436
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
581 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
|
582 } |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
583 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
|
584 { |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
585 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
|
586 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
|
587 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
588 { |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
589 FloatNDArray a0 = args(0).float_array_value (); |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
590 FloatNDArray a1 = args(1).float_array_value (); |
11209
94d9d412a2a0
improve Matlab compatibility of rem and mod
John W. Eaton <jwe@octave.org>
parents:
10983
diff
changeset
|
591 retval = binmap<float> (a0, a1, xrem, "rem"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
592 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
593 } |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
594 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
595 { |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
596 bool a0_scalar = args(0).is_scalar_type (); |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
597 bool a1_scalar = args(1).is_scalar_type (); |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
598 if (a0_scalar && a1_scalar) |
11209
94d9d412a2a0
improve Matlab compatibility of rem and mod
John W. Eaton <jwe@octave.org>
parents:
10983
diff
changeset
|
599 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
|
600 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
|
601 && (a1_scalar || args(1).is_sparse_type ())) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
602 { |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
603 SparseMatrix m0 = args(0).sparse_matrix_value (); |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
604 SparseMatrix m1 = args(1).sparse_matrix_value (); |
11209
94d9d412a2a0
improve Matlab compatibility of rem and mod
John W. Eaton <jwe@octave.org>
parents:
10983
diff
changeset
|
605 retval = binmap<double> (m0, m1, xrem, "rem"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
606 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
607 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
608 { |
10435
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
609 NDArray a0 = args(0).array_value (); |
6a271334750c
implement general binary mapping facility
Jaroslav Hajek <highegg@gmail.com>
parents:
10405
diff
changeset
|
610 NDArray a1 = args(1).array_value (); |
11209
94d9d412a2a0
improve Matlab compatibility of rem and mod
John W. Eaton <jwe@octave.org>
parents:
10983
diff
changeset
|
611 retval = binmap<double> (a0, a1, xrem, "rem"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
612 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
613 } |
4311 | 614 } |
615 else | |
5823 | 616 print_usage (); |
4311 | 617 |
618 return retval; | |
619 } | |
620 | |
7506
798b0a00e80c
atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents:
7505
diff
changeset
|
621 /* |
10436
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
622 |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
623 %!assert(rem ([1, 2, 3; -1, -2, -3], 2), [1, 0, 1; -1, 0, -1]); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
624 %!assert(rem ([1, 2, 3; -1, -2, -3], 2 * ones (2, 3)),[1, 0, 1; -1, 0, -1]); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
625 %!error rem (); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
626 %!error rem (1, 2, 3); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
627 %!error rem ([1, 2], [3, 4, 5]); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
628 %!error rem (i, 1); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
629 %!assert(rem (uint8([1, 2, 3; -1, -2, -3]), uint8 (2)), uint8([1, 0, 1; -1, 0, -1])); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
630 %!assert(uint8(rem ([1, 2, 3; -1, -2, -3], 2 * ones (2, 3))),uint8([1, 0, 1; -1, 0, -1])); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
631 %!error rem (uint(8),int8(5)); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
632 %!error rem (uint8([1, 2]), uint8([3, 4, 5])); |
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 */ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
635 |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
636 /* |
7741 | 637 %!assert (size (fmod (zeros (0, 2), zeros (0, 2))), [0, 2]) |
638 %!assert (size (fmod (rand (2, 3, 4), zeros (2, 3, 4))), [2, 3, 4]) | |
7743 | 639 %!assert (size (fmod (rand (2, 3, 4), 1)), [2, 3, 4]) |
640 %!assert (size (fmod (1, rand (2, 3, 4))), [2, 3, 4]) | |
641 %!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
|
642 */ |
798b0a00e80c
atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents:
7505
diff
changeset
|
643 |
10436
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
644 DEFALIAS (fmod, rem) |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
645 |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
646 DEFUN (mod, args, , |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
647 "-*- texinfo -*-\n\ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
648 @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
|
649 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
|
650 \n\ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
651 @example\n\ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
652 x - y .* floor (x ./ y)\n\ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
653 @end example\n\ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
654 \n\ |
10846
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10840
diff
changeset
|
655 @noindent\n\ |
10436
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
656 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
|
657 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
|
658 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
|
659 @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
|
660 \n\ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
661 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
|
662 either of the arguments is complex.\n\ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
663 @seealso{rem}\n\ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
664 @end deftypefn") |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
665 { |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
666 octave_value retval; |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
667 |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
668 int nargin = args.length (); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
669 |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
670 if (nargin == 2) |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
671 { |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
672 if (! args(0).is_numeric_type ()) |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
673 gripe_wrong_type_arg ("mod", args(0)); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
674 else if (! args(1).is_numeric_type ()) |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
675 gripe_wrong_type_arg ("mod", args(1)); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
676 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
|
677 error ("mod: not defined for complex numbers"); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
678 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
|
679 { |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
680 builtin_type_t btyp0 = args(0).builtin_type (); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
681 builtin_type_t btyp1 = args(1).builtin_type (); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
682 if (btyp0 == btyp_double || btyp0 == btyp_float) |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
683 btyp0 = btyp1; |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
684 if (btyp1 == btyp_double || btyp1 == btyp_float) |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
685 btyp1 = btyp0; |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
686 |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
687 if (btyp0 == btyp1) |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
688 { |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
689 switch (btyp0) |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
690 { |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
691 #define MAKE_INT_BRANCH(X) \ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
692 case btyp_ ## X: \ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
693 { \ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
694 X##NDArray a0 = args(0).X##_array_value (); \ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
695 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
|
696 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
|
697 } \ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
698 break |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
699 MAKE_INT_BRANCH (int8); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
700 MAKE_INT_BRANCH (int16); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
701 MAKE_INT_BRANCH (int32); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
702 MAKE_INT_BRANCH (int64); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
703 MAKE_INT_BRANCH (uint8); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
704 MAKE_INT_BRANCH (uint16); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
705 MAKE_INT_BRANCH (uint32); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
706 MAKE_INT_BRANCH (uint64); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
707 #undef MAKE_INT_BRANCH |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
708 default: |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
709 panic_impossible (); |
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 } |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
712 else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
713 error ("mod: cannot combine %s and %d", |
10436
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
714 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
|
715 } |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
716 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
|
717 { |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
718 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
|
719 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
|
720 else |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
721 { |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
722 FloatNDArray a0 = args(0).float_array_value (); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
723 FloatNDArray a1 = args(1).float_array_value (); |
11209
94d9d412a2a0
improve Matlab compatibility of rem and mod
John W. Eaton <jwe@octave.org>
parents:
10983
diff
changeset
|
724 retval = binmap<float> (a0, a1, xmod, "mod"); |
10436
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 } |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
727 else |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
728 { |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
729 bool a0_scalar = args(0).is_scalar_type (); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
730 bool a1_scalar = args(1).is_scalar_type (); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
731 if (a0_scalar && a1_scalar) |
11209
94d9d412a2a0
improve Matlab compatibility of rem and mod
John W. Eaton <jwe@octave.org>
parents:
10983
diff
changeset
|
732 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
|
733 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
|
734 && (a1_scalar || args(1).is_sparse_type ())) |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
735 { |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
736 SparseMatrix m0 = args(0).sparse_matrix_value (); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
737 SparseMatrix m1 = args(1).sparse_matrix_value (); |
11209
94d9d412a2a0
improve Matlab compatibility of rem and mod
John W. Eaton <jwe@octave.org>
parents:
10983
diff
changeset
|
738 retval = binmap<double> (m0, m1, xmod, "mod"); |
10436
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
739 } |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
740 else |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
741 { |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
742 NDArray a0 = args(0).array_value (); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
743 NDArray a1 = args(1).array_value (); |
11209
94d9d412a2a0
improve Matlab compatibility of rem and mod
John W. Eaton <jwe@octave.org>
parents:
10983
diff
changeset
|
744 retval = binmap<double> (a0, a1, xmod, "mod"); |
10436
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 } |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
748 else |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
749 print_usage (); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
750 |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
751 return retval; |
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 /* |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
755 ## empty input test |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
756 %!assert (isempty(mod([], []))); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
757 |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
758 ## x mod y, y != 0 tests |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
759 %!assert (mod(5, 3), 2); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
760 %!assert (mod(-5, 3), 1); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
761 %!assert (mod(0, 3), 0); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
762 %!assert (mod([-5, 5, 0], [3, 3, 3]), [1, 2, 0]); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
763 %!assert (mod([-5; 5; 0], [3; 3; 3]), [1; 2; 0]); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
764 %!assert (mod([-5, 5; 0, 3], [3, 3 ; 3, 1]), [1, 2 ; 0, 0]); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
765 |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
766 ## x mod 0 tests |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
767 %!assert (mod(5, 0), 5); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
768 %!assert (mod(-5, 0), -5); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
769 %!assert (mod([-5, 5, 0], [3, 0, 3]), [1, 5, 0]); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
770 %!assert (mod([-5; 5; 0], [3; 0; 3]), [1; 5; 0]); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
771 %!assert (mod([-5, 5; 0, 3], [3, 0 ; 3, 1]), [1, 5 ; 0, 0]); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
772 %!assert (mod([-5, 5; 0, 3], [0, 0 ; 0, 0]), [-5, 5; 0, 3]); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
773 |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
774 ## mixed scalar/matrix tests |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
775 %!assert (mod([-5, 5; 0, 3], 0), [-5, 5; 0, 3]); |
10436
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
776 %!assert (mod([-5, 5; 0, 3], 3), [1, 2; 0, 0]); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
777 %!assert (mod(-5,[0,0; 0,0]), [-5, -5; -5, -5]); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
778 %!assert (mod(-5,[3,0; 3,1]), [1, -5; 1, 0]); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
779 %!assert (mod(-5,[3,2; 3,1]), [1, 1; 1, 0]); |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
780 |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
781 ## integer types |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
782 %!assert (mod(uint8(5),uint8(4)),uint8(1)) |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
783 %!assert (mod(uint8([1:5]),uint8(4)),uint8([1,2,3,0,1])) |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
784 %!assert (mod(uint8([1:5]),uint8(0)),uint8([1:5])) |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
785 %!error (mod(uint8(5),int8(4))) |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
786 |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
787 ## mixed integer/real types |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
788 %!assert (mod(uint8(5),4),uint8(1)) |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
789 %!assert (mod(5,uint8(4)),uint8(1)) |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
790 %!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
|
791 |
903c1a3df301
Add additional tests for mod with non-integer real values.
Rik <octave@nomad.inbox5.com>
parents:
11242
diff
changeset
|
792 ## non-integer real numbers |
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.1), 0) |
903c1a3df301
Add additional tests for mod with non-integer real values.
Rik <octave@nomad.inbox5.com>
parents:
11242
diff
changeset
|
794 %!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
|
795 */ |
00219bdd2d17
implement built-in rem and mod
Jaroslav Hajek <highegg@gmail.com>
parents:
10435
diff
changeset
|
796 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7743
diff
changeset
|
797 // FIXME Need to convert the reduction functions of this file for single precision |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7743
diff
changeset
|
798 |
7112 | 799 #define NATIVE_REDUCTION_1(FCN, TYPE, DIM) \ |
800 (arg.is_ ## TYPE ## _type ()) \ | |
801 { \ | |
802 TYPE ## NDArray tmp = arg. TYPE ##_array_value (); \ | |
803 \ | |
804 if (! error_state) \ | |
8780
ea76466605ba
support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents:
8756
diff
changeset
|
805 { \ |
ea76466605ba
support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents:
8756
diff
changeset
|
806 retval = tmp.FCN (DIM); \ |
ea76466605ba
support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents:
8756
diff
changeset
|
807 } \ |
7112 | 808 } |
809 | |
8780
ea76466605ba
support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents:
8756
diff
changeset
|
810 #define NATIVE_REDUCTION(FCN, BOOL_FCN) \ |
7112 | 811 \ |
812 octave_value retval; \ | |
813 \ | |
814 int nargin = args.length (); \ | |
815 \ | |
816 bool isnative = false; \ | |
7815
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
817 bool isdouble = false; \ |
7112 | 818 \ |
819 if (nargin > 1 && args(nargin - 1).is_string ()) \ | |
820 { \ | |
821 std::string str = args(nargin - 1).string_value (); \ | |
822 \ | |
823 if (! error_state) \ | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
824 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
825 if (str == "native") \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
826 isnative = true; \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
827 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
|
828 isdouble = true; \ |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
829 else \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
830 error ("sum: unrecognized string argument"); \ |
7112 | 831 nargin --; \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
832 } \ |
7112 | 833 } \ |
834 \ | |
835 if (nargin == 1 || nargin == 2) \ | |
836 { \ | |
837 octave_value arg = args(0); \ | |
838 \ | |
839 int dim = (nargin == 1 ? -1 : args(1).int_value (true) - 1); \ | |
840 \ | |
841 if (! error_state) \ | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
842 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
843 if (dim >= -1) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
844 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
845 if (arg.is_sparse_type ()) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
846 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
847 if (arg.is_real_type ()) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
848 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
849 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
|
850 \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
851 if (! error_state) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
852 retval = tmp.FCN (dim); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
853 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
854 else \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
855 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
856 SparseComplexMatrix tmp = arg.sparse_complex_matrix_value (); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
857 \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
858 if (! error_state) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
859 retval = tmp.FCN (dim); \ |
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 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
862 else \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
863 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
864 if (isnative) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
865 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
866 if NATIVE_REDUCTION_1 (FCN, uint8, dim) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
867 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
|
868 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
|
869 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
|
870 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
|
871 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
|
872 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
|
873 else if NATIVE_REDUCTION_1 (FCN, int64, dim) \ |
8756
d0755c9db5ed
implement fast logical sum (counting)
Jaroslav Hajek <highegg@gmail.com>
parents:
8734
diff
changeset
|
874 else if (arg.is_bool_type ()) \ |
d0755c9db5ed
implement fast logical sum (counting)
Jaroslav Hajek <highegg@gmail.com>
parents:
8734
diff
changeset
|
875 { \ |
8780
ea76466605ba
support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents:
8756
diff
changeset
|
876 boolNDArray tmp = arg.bool_array_value (); \ |
8756
d0755c9db5ed
implement fast logical sum (counting)
Jaroslav Hajek <highegg@gmail.com>
parents:
8734
diff
changeset
|
877 if (! error_state) \ |
8780
ea76466605ba
support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents:
8756
diff
changeset
|
878 retval = boolNDArray (tmp.BOOL_FCN (dim)); \ |
8756
d0755c9db5ed
implement fast logical sum (counting)
Jaroslav Hajek <highegg@gmail.com>
parents:
8734
diff
changeset
|
879 } \ |
7515
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7506
diff
changeset
|
880 else if (arg.is_char_matrix ()) \ |
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7506
diff
changeset
|
881 { \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
882 error (#FCN, ": invalid char type"); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
883 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
884 else if (!isdouble && arg.is_single_type ()) \ |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7743
diff
changeset
|
885 { \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
886 if (arg.is_complex_type ()) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
887 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
888 FloatComplexNDArray tmp = \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
889 arg.float_complex_array_value (); \ |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7743
diff
changeset
|
890 \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
891 if (! error_state) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
892 retval = tmp.FCN (dim); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
893 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
894 else if (arg.is_real_type ()) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
895 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
896 FloatNDArray tmp = arg.float_array_value (); \ |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7743
diff
changeset
|
897 \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
898 if (! error_state) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
899 retval = tmp.FCN (dim); \ |
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 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
902 else if (arg.is_complex_type ()) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
903 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
904 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
|
905 \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
906 if (! error_state) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
907 retval = tmp.FCN (dim); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
908 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
909 else if (arg.is_real_type ()) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
910 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
911 NDArray tmp = arg.array_value (); \ |
7515
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7506
diff
changeset
|
912 \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
913 if (! error_state) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
914 retval = tmp.FCN (dim); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
915 } \ |
7515
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7506
diff
changeset
|
916 else \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
917 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
918 gripe_wrong_type_arg (#FCN, arg); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
919 return retval; \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
920 } \ |
7112 | 921 } \ |
8756
d0755c9db5ed
implement fast logical sum (counting)
Jaroslav Hajek <highegg@gmail.com>
parents:
8734
diff
changeset
|
922 else if (arg.is_bool_type ()) \ |
d0755c9db5ed
implement fast logical sum (counting)
Jaroslav Hajek <highegg@gmail.com>
parents:
8734
diff
changeset
|
923 { \ |
d0755c9db5ed
implement fast logical sum (counting)
Jaroslav Hajek <highegg@gmail.com>
parents:
8734
diff
changeset
|
924 boolNDArray tmp = arg.bool_array_value (); \ |
d0755c9db5ed
implement fast logical sum (counting)
Jaroslav Hajek <highegg@gmail.com>
parents:
8734
diff
changeset
|
925 if (! error_state) \ |
d0755c9db5ed
implement fast logical sum (counting)
Jaroslav Hajek <highegg@gmail.com>
parents:
8734
diff
changeset
|
926 retval = tmp.FCN (dim); \ |
d0755c9db5ed
implement fast logical sum (counting)
Jaroslav Hajek <highegg@gmail.com>
parents:
8734
diff
changeset
|
927 } \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
928 else if (!isdouble && arg.is_single_type ()) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
929 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
930 if (arg.is_real_type ()) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
931 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
932 FloatNDArray tmp = arg.float_array_value (); \ |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7743
diff
changeset
|
933 \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
934 if (! error_state) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
935 retval = tmp.FCN (dim); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
936 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
937 else if (arg.is_complex_type ()) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
938 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
939 FloatComplexNDArray tmp = \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
940 arg.float_complex_array_value (); \ |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7743
diff
changeset
|
941 \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
942 if (! error_state) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
943 retval = tmp.FCN (dim); \ |
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 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
946 else if (arg.is_real_type ()) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
947 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
948 NDArray tmp = arg.array_value (); \ |
7515
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7506
diff
changeset
|
949 \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
950 if (! error_state) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
951 retval = tmp.FCN (dim); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
952 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
953 else if (arg.is_complex_type ()) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
954 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
955 ComplexNDArray tmp = arg.complex_array_value (); \ |
7112 | 956 \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
957 if (! error_state) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
958 retval = tmp.FCN (dim); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
959 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
960 else \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
961 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
962 gripe_wrong_type_arg (#FCN, arg); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
963 return retval; \ |
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 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
967 else \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
968 error (#FCN ": invalid dimension argument = %d", dim + 1); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
969 } \ |
7112 | 970 \ |
971 } \ | |
972 else \ | |
973 print_usage (); \ | |
974 \ | |
975 return retval | |
976 | |
3723 | 977 #define DATA_REDUCTION(FCN) \ |
978 \ | |
4233 | 979 octave_value retval; \ |
3723 | 980 \ |
981 int nargin = args.length (); \ | |
982 \ | |
983 if (nargin == 1 || nargin == 2) \ | |
984 { \ | |
985 octave_value arg = args(0); \ | |
986 \ | |
3864 | 987 int dim = (nargin == 1 ? -1 : args(1).int_value (true) - 1); \ |
3723 | 988 \ |
989 if (! error_state) \ | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
990 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
991 if (dim >= -1) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
992 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
993 if (arg.is_real_type ()) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
994 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
995 if (arg.is_sparse_type ()) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
996 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
997 SparseMatrix tmp = arg.sparse_matrix_value (); \ |
3723 | 998 \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
999 if (! error_state) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1000 retval = tmp.FCN (dim); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1001 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1002 else if (arg.is_single_type ()) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1003 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1004 FloatNDArray tmp = arg.float_array_value (); \ |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7743
diff
changeset
|
1005 \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1006 if (! error_state) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1007 retval = tmp.FCN (dim); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1008 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1009 else \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1010 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1011 NDArray tmp = arg.array_value (); \ |
7515
f3c00dc0912b
Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents:
7506
diff
changeset
|
1012 \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1013 if (! error_state) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1014 retval = tmp.FCN (dim); \ |
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 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1017 else if (arg.is_complex_type ()) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1018 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1019 if (arg.is_sparse_type ()) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1020 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1021 SparseComplexMatrix tmp = arg.sparse_complex_matrix_value (); \ |
3723 | 1022 \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1023 if (! error_state) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1024 retval = tmp.FCN (dim); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1025 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1026 else if (arg.is_single_type ()) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1027 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1028 FloatComplexNDArray tmp = arg.float_complex_array_value (); \ |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7743
diff
changeset
|
1029 \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1030 if (! error_state) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1031 retval = tmp.FCN (dim); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1032 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1033 else \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1034 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1035 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
|
1036 \ |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1037 if (! error_state) \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1038 retval = tmp.FCN (dim); \ |
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 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1041 else \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1042 { \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1043 gripe_wrong_type_arg (#FCN, arg); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1044 return retval; \ |
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 } \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1047 else \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1048 error (#FCN ": invalid dimension argument = %d", dim + 1); \ |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1049 } \ |
3723 | 1050 } \ |
1051 else \ | |
5823 | 1052 print_usage (); \ |
3723 | 1053 \ |
1054 return retval | |
1055 | |
1957 | 1056 DEFUN (cumprod, args, , |
3428 | 1057 "-*- texinfo -*-\n\ |
9163
9cb0c21e97f7
Update section 17.4 (Sums and Products) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9155
diff
changeset
|
1058 @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
|
1059 @deftypefnx {Built-in Function} {} cumprod (@var{x}, @var{dim})\n\ |
3723 | 1060 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
|
1061 @var{dim} is omitted, it defaults to the first non-singleton dimension.\n\ |
5061 | 1062 \n\ |
9163
9cb0c21e97f7
Update section 17.4 (Sums and Products) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9155
diff
changeset
|
1063 @seealso{prod, cumsum}\n\ |
3428 | 1064 @end deftypefn") |
523 | 1065 { |
3723 | 1066 DATA_REDUCTION (cumprod); |
523 | 1067 } |
1068 | |
7815
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1069 /* |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1070 |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1071 %!assert (cumprod ([1, 2, 3]), [1, 2, 6]); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1072 %!assert (cumprod ([-1; -2; -3]), [-1; 2; -6]); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1073 %!assert (cumprod ([i, 2+i, -3+2i, 4]), [i, -1+2i, -1-8i, -4-32i]); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1074 %!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]); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1075 |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1076 %!assert (cumprod (single([1, 2, 3])), single([1, 2, 6])); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1077 %!assert (cumprod (single([-1; -2; -3])), single([-1; 2; -6])); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1078 %!assert (cumprod (single([i, 2+i, -3+2i, 4])), single([i, -1+2i, -1-8i, -4-32i])); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1079 %!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])); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1080 |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1081 %!error <Invalid call to cumprod.*> cumprod (); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1082 |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1083 %!assert (cumprod ([2, 3; 4, 5], 1), [2, 3; 8, 15]); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1084 %!assert (cumprod ([2, 3; 4, 5], 2), [2, 6; 4, 20]); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1085 |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1086 %!assert (cumprod (single([2, 3; 4, 5]), 1), single([2, 3; 8, 15])); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1087 %!assert (cumprod (single([2, 3; 4, 5]), 2), single([2, 6; 4, 20])); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1088 |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1089 */ |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1090 |
1957 | 1091 DEFUN (cumsum, args, , |
3428 | 1092 "-*- texinfo -*-\n\ |
9163
9cb0c21e97f7
Update section 17.4 (Sums and Products) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9155
diff
changeset
|
1093 @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
|
1094 @deftypefnx {Built-in Function} {} cumsum (@var{x}, @var{dim})\n\ |
8780
ea76466605ba
support native cumsum, gripe on overflow in sum/cumsum
Jaroslav Hajek <highegg@gmail.com>
parents:
8756
diff
changeset
|
1095 @deftypefnx {Built-in Function} {} cumsum (@dots{}, 'native')\n\ |
12546
39ca02387a32
Improve docstrings for a number of functions.
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
1096 @deftypefnx {Built-in Function} {} cumsum (@dots{}, 'double')\n\ |
39ca02387a32
Improve docstrings for a number of functions.
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
1097 @deftypefnx {Built-in Function} {} cumsum (@dots{}, 'extra')\n\ |
3723 | 1098 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
|
1099 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
|
1100 \n\ |
12546
39ca02387a32
Improve docstrings for a number of functions.
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
1101 See @code{sum} for an explanation of the optional parameters 'native',\n\ |
39ca02387a32
Improve docstrings for a number of functions.
Rik <octave@nomad.inbox5.com>
parents:
12483
diff
changeset
|
1102 '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
|
1103 @seealso{sum, cumprod}\n\ |
3428 | 1104 @end deftypefn") |
523 | 1105 { |
9721
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1106 octave_value retval; |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1107 |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1108 int nargin = args.length (); |
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 bool isnative = false; |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1111 bool isdouble = false; |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1112 |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1113 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
|
1114 { |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1115 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
|
1116 |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1117 if (! error_state) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1118 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1119 if (str == "native") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1120 isnative = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1121 else if (str == "double") |
9721
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1122 isdouble = true; |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1123 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1124 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
|
1125 nargin --; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1126 } |
9721
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1127 } |
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 (error_state) |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1130 return retval; |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1131 |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1132 if (nargin == 1 || nargin == 2) |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1133 { |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1134 octave_value arg = args(0); |
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 int dim = -1; |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1137 if (nargin == 2) |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1138 { |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1139 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
|
1140 if (dim < 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1141 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
|
1142 } |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1143 |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1144 if (! error_state) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1145 { |
9721
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1146 switch (arg.builtin_type ()) |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1147 { |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1148 case btyp_double: |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1149 if (arg.is_sparse_type ()) |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1150 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
|
1151 else |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1152 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
|
1153 break; |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1154 case btyp_complex: |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1155 if (arg.is_sparse_type ()) |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1156 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
|
1157 else |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1158 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
|
1159 break; |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1160 case btyp_float: |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1161 if (isdouble) |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1162 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
|
1163 else |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1164 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
|
1165 break; |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1166 case btyp_float_complex: |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1167 if (isdouble) |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1168 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
|
1169 else |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1170 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
|
1171 break; |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1172 |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1173 #define MAKE_INT_BRANCH(X) \ |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1174 case btyp_ ## X: \ |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1175 if (isnative) \ |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1176 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
|
1177 else \ |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1178 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
|
1179 break |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1180 MAKE_INT_BRANCH (int8); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1181 MAKE_INT_BRANCH (int16); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1182 MAKE_INT_BRANCH (int32); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1183 MAKE_INT_BRANCH (int64); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1184 MAKE_INT_BRANCH (uint8); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1185 MAKE_INT_BRANCH (uint16); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1186 MAKE_INT_BRANCH (uint32); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1187 MAKE_INT_BRANCH (uint64); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1188 #undef MAKE_INT_BRANCH |
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 case btyp_bool: |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1191 if (arg.is_sparse_type ()) |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1192 { |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1193 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
|
1194 if (isnative) |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1195 retval = cs != 0.0; |
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 retval = cs; |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1198 } |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1199 else |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1200 { |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1201 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
|
1202 if (isnative) |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1203 retval = cs != 0.0; |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1204 else |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1205 retval = cs; |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1206 } |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1207 break; |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1208 |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1209 default: |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1210 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
|
1211 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1212 } |
9721
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 else |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1215 print_usage (); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1216 |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
1217 return retval; |
523 | 1218 } |
1219 | |
7815
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1220 /* |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1221 |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1222 %!assert (cumsum ([1, 2, 3]), [1, 3, 6]); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1223 %!assert (cumsum ([-1; -2; -3]), [-1; -3; -6]); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1224 %!assert (cumsum ([i, 2+i, -3+2i, 4]), [i, 2+2i, -1+4i, 3+4i]); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1225 %!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]); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1226 |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1227 %!assert (cumsum (single([1, 2, 3])), single([1, 3, 6])); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1228 %!assert (cumsum (single([-1; -2; -3])), single([-1; -3; -6])); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1229 %!assert (cumsum (single([i, 2+i, -3+2i, 4])), single([i, 2+2i, -1+4i, 3+4i])); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1230 %!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])); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1231 |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1232 %!error <Invalid call to cumsum.*> cumsum (); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1233 |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1234 %!assert (cumsum ([1, 2; 3, 4], 1), [1, 2; 4, 6]); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1235 %!assert (cumsum ([1, 2; 3, 4], 2), [1, 3; 3, 7]); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1236 |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1237 %!assert (cumsum (single([1, 2; 3, 4]), 1), single([1, 2; 4, 6])); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1238 %!assert (cumsum (single([1, 2; 3, 4]), 2), single([1, 3; 3, 7])); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1239 |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1240 */ |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1241 |
1957 | 1242 DEFUN (diag, args, , |
3369 | 1243 "-*- texinfo -*-\n\ |
12567
cc8ccdfec424
Remove archaic 3-input argument form of diag function.
Rik <octave@nomad.inbox5.com>
parents:
12546
diff
changeset
|
1244 @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
|
1245 @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
|
1246 @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
|
1247 @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
|
1248 @deftypefnx {Built-in Function} {@var{v} =} diag (@var{M}, @var{k})\n\ |
3369 | 1249 Return a diagonal matrix with vector @var{v} on diagonal @var{k}. The\n\ |
1250 second argument is optional. If it is positive, the vector is placed on\n\ | |
1251 the @var{k}-th super-diagonal. If it is negative, it is placed on the\n\ | |
1252 @var{-k}-th sub-diagonal. The default value of @var{k} is 0, and the\n\ | |
10840 | 1253 vector is placed on the main diagonal. For example:\n\ |
3369 | 1254 \n\ |
1255 @example\n\ | |
1256 @group\n\ | |
1257 diag ([1, 2, 3], 1)\n\ | |
1258 @result{} 0 1 0 0\n\ | |
1259 0 0 2 0\n\ | |
1260 0 0 0 3\n\ | |
1261 0 0 0 0\n\ | |
1262 @end group\n\ | |
1263 @end example\n\ | |
6772 | 1264 \n\ |
1265 @noindent\n\ | |
12571
bed932910eb9
Add documentation for 3-input form of diag(). Add new tests.
Rik <octave@nomad.inbox5.com>
parents:
12570
diff
changeset
|
1266 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
|
1267 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
|
1268 columns.\n\ |
bed932910eb9
Add documentation for 3-input form of diag(). Add new tests.
Rik <octave@nomad.inbox5.com>
parents:
12570
diff
changeset
|
1269 \n\ |
6772 | 1270 Given a matrix argument, instead of a vector, @code{diag} extracts the\n\ |
6774 | 1271 @var{k}-th diagonal of the matrix.\n\ |
3369 | 1272 @end deftypefn") |
523 | 1273 { |
4233 | 1274 octave_value retval; |
523 | 1275 |
1276 int nargin = args.length (); | |
1277 | |
712 | 1278 if (nargin == 1 && args(0).is_defined ()) |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7618
diff
changeset
|
1279 retval = args(0).diag(); |
712 | 1280 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
|
1281 { |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7618
diff
changeset
|
1282 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
|
1283 |
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7618
diff
changeset
|
1284 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
|
1285 error ("diag: invalid argument K"); |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7618
diff
changeset
|
1286 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1287 retval = args(0).diag(k); |
7620
36594d5bbe13
Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents:
7618
diff
changeset
|
1288 } |
12570
1a93988610a3
Reverse changset cc8ccdfec424. Restore 3-input form of diag().
Rik <octave@nomad.inbox5.com>
parents:
12567
diff
changeset
|
1289 else if (nargin == 3) |
1a93988610a3
Reverse changset cc8ccdfec424. Restore 3-input form of diag().
Rik <octave@nomad.inbox5.com>
parents:
12567
diff
changeset
|
1290 { |
1a93988610a3
Reverse changset cc8ccdfec424. Restore 3-input form of diag().
Rik <octave@nomad.inbox5.com>
parents:
12567
diff
changeset
|
1291 octave_value arg0 = args(0); |
1a93988610a3
Reverse changset cc8ccdfec424. Restore 3-input form of diag().
Rik <octave@nomad.inbox5.com>
parents:
12567
diff
changeset
|
1292 if (arg0.ndims () == 2 && (args(0).rows () == 1 || args(0).columns () == 1)) |
1a93988610a3
Reverse changset cc8ccdfec424. Restore 3-input form of diag().
Rik <octave@nomad.inbox5.com>
parents:
12567
diff
changeset
|
1293 { |
1a93988610a3
Reverse changset cc8ccdfec424. Restore 3-input form of diag().
Rik <octave@nomad.inbox5.com>
parents:
12567
diff
changeset
|
1294 octave_idx_type m = args(1).int_value (), n = args(2).int_value (); |
1a93988610a3
Reverse changset cc8ccdfec424. Restore 3-input form of diag().
Rik <octave@nomad.inbox5.com>
parents:
12567
diff
changeset
|
1295 if (! error_state) |
1a93988610a3
Reverse changset cc8ccdfec424. Restore 3-input form of diag().
Rik <octave@nomad.inbox5.com>
parents:
12567
diff
changeset
|
1296 retval = arg0.diag ().resize (dim_vector (m, n)); |
1a93988610a3
Reverse changset cc8ccdfec424. Restore 3-input form of diag().
Rik <octave@nomad.inbox5.com>
parents:
12567
diff
changeset
|
1297 else |
1a93988610a3
Reverse changset cc8ccdfec424. Restore 3-input form of diag().
Rik <octave@nomad.inbox5.com>
parents:
12567
diff
changeset
|
1298 error ("diag: invalid dimensions"); |
1a93988610a3
Reverse changset cc8ccdfec424. Restore 3-input form of diag().
Rik <octave@nomad.inbox5.com>
parents:
12567
diff
changeset
|
1299 } |
1a93988610a3
Reverse changset cc8ccdfec424. Restore 3-input form of diag().
Rik <octave@nomad.inbox5.com>
parents:
12567
diff
changeset
|
1300 else |
1a93988610a3
Reverse changset cc8ccdfec424. Restore 3-input form of diag().
Rik <octave@nomad.inbox5.com>
parents:
12567
diff
changeset
|
1301 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
|
1302 } |
523 | 1303 else |
5823 | 1304 print_usage (); |
523 | 1305 |
1306 return retval; | |
1307 } | |
1308 | |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1309 /* |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1310 |
8459
d17874a6f161
improve indexing of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8458
diff
changeset
|
1311 %!assert(full (diag ([1; 2; 3])), [1, 0, 0; 0, 2, 0; 0, 0, 3]); |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1312 %!assert(diag ([1; 2; 3], 1), [0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0]); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1313 %!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]); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1314 %!assert(diag ([1; 2; 3],-1), [0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0]); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1315 %!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]); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1316 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1317 %!assert(diag ([1, 0, 0; 0, 2, 0; 0, 0, 3]), [1; 2; 3]); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1318 %!assert(diag ([0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0], 1), [1; 2; 3]); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1319 %!assert(diag ([0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0], -1), [1; 2; 3]); |
12567
cc8ccdfec424
Remove archaic 3-input argument form of diag function.
Rik <octave@nomad.inbox5.com>
parents:
12546
diff
changeset
|
1320 %!assert(diag (ones(1, 0), 2), zeros (2)); |
12571
bed932910eb9
Add documentation for 3-input form of diag(). Add new tests.
Rik <octave@nomad.inbox5.com>
parents:
12570
diff
changeset
|
1321 %!assert(diag (1:3, 4, 2), [1, 0; 0, 2; 0, 0; 0, 0]); |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1322 |
8459
d17874a6f161
improve indexing of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8458
diff
changeset
|
1323 %!assert(full (diag (single([1; 2; 3]))), single([1, 0, 0; 0, 2, 0; 0, 0, 3])); |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1324 %!assert(diag (single([1; 2; 3]), 1), single([0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0])); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1325 %!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])); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1326 %!assert(diag (single([1; 2; 3]),-1), single([0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0])); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1327 %!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])); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1328 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1329 %!assert(diag (single([1, 0, 0; 0, 2, 0; 0, 0, 3])), single([1; 2; 3])); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1330 %!assert(diag (single([0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0]), 1), single([1; 2; 3])); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1331 %!assert(diag (single([0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0]), -1), single([1; 2; 3])); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1332 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1333 %!assert(diag (int8([1; 2; 3])), int8([1, 0, 0; 0, 2, 0; 0, 0, 3])); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1334 %!assert(diag (int8([1; 2; 3]), 1), int8([0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0])); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1335 %!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])); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1336 %!assert(diag (int8([1; 2; 3]),-1), int8([0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0])); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1337 %!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])); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1338 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1339 %!assert(diag (int8([1, 0, 0; 0, 2, 0; 0, 0, 3])), int8([1; 2; 3])); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1340 %!assert(diag (int8([0, 1, 0, 0; 0, 0, 2, 0; 0, 0, 0, 3; 0, 0, 0, 0]), 1), int8([1; 2; 3])); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1341 %!assert(diag (int8([0, 0, 0, 0; 1, 0, 0, 0; 0, 2, 0, 0; 0, 0, 3, 0]), -1), int8([1; 2; 3])); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1342 |
12571
bed932910eb9
Add documentation for 3-input form of diag(). Add new tests.
Rik <octave@nomad.inbox5.com>
parents:
12570
diff
changeset
|
1343 %% Test input validation |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1344 %!error <Invalid call to diag.*> diag (); |
12571
bed932910eb9
Add documentation for 3-input form of diag(). Add new tests.
Rik <octave@nomad.inbox5.com>
parents:
12570
diff
changeset
|
1345 %!error <Invalid call to diag.*> diag (1,2,3,4); |
bed932910eb9
Add documentation for 3-input form of diag(). Add new tests.
Rik <octave@nomad.inbox5.com>
parents:
12570
diff
changeset
|
1346 %!error diag (ones (2), 3, 3); |
bed932910eb9
Add documentation for 3-input form of diag(). Add new tests.
Rik <octave@nomad.inbox5.com>
parents:
12570
diff
changeset
|
1347 %!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
|
1348 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1349 */ |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1350 |
1957 | 1351 DEFUN (prod, args, , |
3428 | 1352 "-*- texinfo -*-\n\ |
9163
9cb0c21e97f7
Update section 17.4 (Sums and Products) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9155
diff
changeset
|
1353 @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
|
1354 @deftypefnx {Built-in Function} {} prod (@var{x}, @var{dim})\n\ |
3723 | 1355 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
|
1356 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
|
1357 @seealso{cumprod, sum}\n\ |
3428 | 1358 @end deftypefn") |
523 | 1359 { |
3723 | 1360 DATA_REDUCTION (prod); |
523 | 1361 } |
1362 | |
7815
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1363 /* |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1364 |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1365 %!assert (prod ([1, 2, 3]), 6); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1366 %!assert (prod ([-1; -2; -3]), -6); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1367 %!assert (prod ([i, 2+i, -3+2i, 4]), -4 - 32i); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1368 %!assert (prod ([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i]), [-1+i, -8+8i, -27+27i]); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1369 |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1370 %!assert (prod (single([1, 2, 3])), single(6)); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1371 %!assert (prod (single([-1; -2; -3])), single(-6)); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1372 %!assert (prod (single([i, 2+i, -3+2i, 4])), single(-4 - 32i)); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1373 %!assert (prod (single([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i])), single([-1+i, -8+8i, -27+27i])); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1374 |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1375 %!error <Invalid call to prod.*> prod (); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1376 |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1377 %!assert (prod ([1, 2; 3, 4], 1), [3, 8]); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1378 %!assert (prod ([1, 2; 3, 4], 2), [2; 12]); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1379 %!assert (prod (zeros (1, 0)), 1); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1380 %!assert (prod (zeros (1, 0), 1), zeros (1, 0)); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1381 %!assert (prod (zeros (1, 0), 2), 1); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1382 %!assert (prod (zeros (0, 1)), 1); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1383 %!assert (prod (zeros (0, 1), 1), 1); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1384 %!assert (prod (zeros (0, 1), 2), zeros (0, 1)); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1385 %!assert (prod (zeros (2, 0)), zeros (1, 0)); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1386 %!assert (prod (zeros (2, 0), 1), zeros (1, 0)); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1387 %!assert (prod (zeros (2, 0), 2), [1; 1]); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1388 %!assert (prod (zeros (0, 2)), [1, 1]); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1389 %!assert (prod (zeros (0, 2), 1), [1, 1]); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1390 %!assert (prod (zeros (0, 2), 2), zeros(0, 1)); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1391 |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1392 %!assert (prod (single([1, 2; 3, 4]), 1), single([3, 8])); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1393 %!assert (prod (single([1, 2; 3, 4]), 2), single([2; 12])); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1394 %!assert (prod (zeros (1, 0, 'single')), single(1)); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1395 %!assert (prod (zeros (1, 0, 'single'), 1), zeros (1, 0, 'single')); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1396 %!assert (prod (zeros (1, 0, 'single'), 2), single(1)); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1397 %!assert (prod (zeros (0, 1, 'single')), single(1)); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1398 %!assert (prod (zeros (0, 1, 'single'), 1), single(1)); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1399 %!assert (prod (zeros (0, 1, 'single'), 2), zeros (0, 1, 'single')); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1400 %!assert (prod (zeros (2, 0, 'single')), zeros (1, 0, 'single')); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1401 %!assert (prod (zeros (2, 0, 'single'), 1), zeros (1, 0, 'single')); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1402 %!assert (prod (zeros (2, 0, 'single'), 2), single([1; 1])); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1403 %!assert (prod (zeros (0, 2, 'single')), single([1, 1])); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1404 %!assert (prod (zeros (0, 2, 'single'), 1), single([1, 1])); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1405 %!assert (prod (zeros (0, 2, 'single'), 2), zeros(0, 1, 'single')); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1406 |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1407 */ |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
1408 |
10758
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1409 static bool |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1410 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
|
1411 { |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1412 int n_args = args.length (); |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1413 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
|
1414 if (args(i).numel () != 1) |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1415 return false; |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1416 |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1417 return true; |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1418 } |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1419 |
10533
f094ac9bc93e
reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents:
10498
diff
changeset
|
1420 template <class TYPE, class T> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
1421 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
|
1422 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
|
1423 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
|
1424 int dim) |
f094ac9bc93e
reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents:
10498
diff
changeset
|
1425 { |
f094ac9bc93e
reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents:
10498
diff
changeset
|
1426 int n_args = args.length (); |
10758
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1427 if (! (equal_types<T, char>::value |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1428 || equal_types<T, octave_value>::value) |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1429 && 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
|
1430 { |
10758
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1431 // Optimize all scalars case. |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1432 dim_vector dv (1, 1); |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1433 if (dim == -1 || dim == -2) |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1434 dim = -dim - 1; |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1435 else if (dim >= 2) |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1436 dv.resize (dim+1, 1); |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1437 dv(dim) = n_args; |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1438 |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1439 result.clear (dv); |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1440 |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1441 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
|
1442 { |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1443 octave_quit (); |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1444 |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1445 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
|
1446 } |
10533
f094ac9bc93e
reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents:
10498
diff
changeset
|
1447 } |
10758
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1448 else |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1449 { |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1450 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
|
1451 |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1452 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
|
1453 { |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1454 octave_quit (); |
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 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
|
1457 } |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1458 |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1459 if (! error_state) |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1460 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
|
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 } |
f094ac9bc93e
reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents:
10498
diff
changeset
|
1463 |
f094ac9bc93e
reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents:
10498
diff
changeset
|
1464 template <class TYPE, class T> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
1465 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
|
1466 single_type_concat (Sparse<T>& result, |
10498
8615b55b5caf
fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents:
10436
diff
changeset
|
1467 const octave_value_list& args, |
8615b55b5caf
fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents:
10436
diff
changeset
|
1468 int dim) |
8615b55b5caf
fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents:
10436
diff
changeset
|
1469 { |
10533
f094ac9bc93e
reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents:
10498
diff
changeset
|
1470 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
|
1471 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
|
1472 |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1473 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
|
1474 { |
8615b55b5caf
fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents:
10436
diff
changeset
|
1475 octave_quit (); |
8615b55b5caf
fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents:
10436
diff
changeset
|
1476 |
10716
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1477 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
|
1478 } |
10533
f094ac9bc93e
reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents:
10498
diff
changeset
|
1479 |
f094ac9bc93e
reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents:
10498
diff
changeset
|
1480 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
|
1481 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
|
1482 } |
8615b55b5caf
fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents:
10436
diff
changeset
|
1483 |
10533
f094ac9bc93e
reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents:
10498
diff
changeset
|
1484 // Dispatcher. |
10498
8615b55b5caf
fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents:
10436
diff
changeset
|
1485 template<class TYPE> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
1486 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
|
1487 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
|
1488 { |
10533
f094ac9bc93e
reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents:
10498
diff
changeset
|
1489 TYPE result; |
f094ac9bc93e
reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents:
10498
diff
changeset
|
1490 |
f094ac9bc93e
reuse Array<T>::cat and Sparse<T>::cat in cat/horzcat/vertcat
Jaroslav Hajek <highegg@gmail.com>
parents:
10498
diff
changeset
|
1491 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
|
1492 |
8615b55b5caf
fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents:
10436
diff
changeset
|
1493 return result; |
8615b55b5caf
fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents:
10436
diff
changeset
|
1494 } |
8615b55b5caf
fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents:
10436
diff
changeset
|
1495 |
10758
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1496 template<class MAP> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
1497 static void |
10758
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1498 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
|
1499 const octave_value_list& args, |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1500 int dim) |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1501 { |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1502 int n_args = args.length (); |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1503 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
|
1504 |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1505 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
|
1506 { |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1507 octave_quit (); |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1508 |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1509 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
|
1510 } |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1511 |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1512 if (! error_state) |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1513 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
|
1514 } |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1515 |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1516 static octave_map |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1517 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
|
1518 int dim) |
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 octave_map result; |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1521 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
|
1522 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
|
1523 else |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1524 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
|
1525 |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1526 return result; |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1527 } |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1528 |
4824 | 1529 static octave_value |
10716
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1530 do_cat (const octave_value_list& args, int dim, std::string fname) |
4806 | 1531 { |
1532 octave_value retval; | |
1533 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
1534 int n_args = args.length (); |
4806 | 1535 |
10716
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1536 if (n_args == 0) |
5714 | 1537 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
|
1538 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
|
1539 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
|
1540 else if (n_args > 1) |
4824 | 1541 { |
10716
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1542 |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1543 std::string result_type = args(0).class_name (); |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1544 |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1545 bool all_sq_strings_p = args(0).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
|
1546 bool all_dq_strings_p = args(0).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
|
1547 bool all_real_p = args(0).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
|
1548 bool any_sparse_p = args(0).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
|
1549 |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1550 for (int i = 1; i < args.length (); i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1551 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
1552 result_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
|
1553 get_concat_class (result_type, args(i).class_name ()); |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1554 |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1555 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
|
1556 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
|
1557 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
|
1558 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
|
1559 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
|
1560 all_real_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
|
1561 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
|
1562 any_sparse_p = true; |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1563 } |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1564 |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1565 if (result_type == "double") |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1566 { |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1567 if (any_sparse_p) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
1568 { |
10716
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1569 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
|
1570 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
|
1571 else |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1572 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
|
1573 } |
10716
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1574 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1575 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1576 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
|
1577 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
|
1578 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
|
1579 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
|
1580 } |
10716
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1581 } |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1582 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
|
1583 { |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1584 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
|
1585 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
|
1586 else |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1587 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
|
1588 } |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1589 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
|
1590 { |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1591 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
|
1592 |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1593 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
|
1594 |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1595 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
|
1596 |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1597 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
|
1598 } |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1599 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
|
1600 { |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1601 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
|
1602 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
|
1603 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
|
1604 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
|
1605 } |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1606 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
|
1607 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
|
1608 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
|
1609 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
|
1610 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
|
1611 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
|
1612 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
|
1613 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
|
1614 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
|
1615 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
|
1616 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
|
1617 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
|
1618 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
|
1619 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
|
1620 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
|
1621 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
|
1622 else if (result_type == "cell") |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1623 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
|
1624 else if (result_type == "struct") |
f3892d8eea9f
optimize horzcat/vertcat for scalars, cells and structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10716
diff
changeset
|
1625 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
|
1626 else |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1627 { |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1628 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
|
1629 |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1630 // 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
|
1631 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
|
1632 |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1633 if (dim == -1 || dim == -2) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1634 { |
10716
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1635 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
|
1636 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
|
1637 } |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1638 |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1639 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
|
1640 { |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1641 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
|
1642 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
1643 // 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
|
1644 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
|
1645 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
|
1646 } |
10716
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1647 } |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1648 |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1649 // 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
|
1650 // 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
|
1651 // 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
|
1652 // 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
|
1653 // 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
|
1654 // 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
|
1655 // 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
|
1656 // |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1657 // 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
|
1658 // 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
|
1659 // (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
|
1660 // 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
|
1661 // 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
|
1662 |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1663 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
|
1664 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
|
1665 |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1666 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
|
1667 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
|
1668 |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1669 int dv_len = dv.length (); |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1670 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
|
1671 |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1672 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
|
1673 { |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1674 // Can't fast return here to skip empty matrices as something |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1675 // like cat(1,[],single([])) must return an empty matrix of |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1676 // 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
|
1677 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
|
1678 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1679 if (error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1680 return retval; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1681 |
10716
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1682 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
|
1683 |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1684 if (dim >= dv_len) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1685 { |
10716
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1686 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
|
1687 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
|
1688 break; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1689 } |
10716
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1690 else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
1691 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
|
1692 dv_tmp (dim) : 1); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1693 } |
10716
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1694 retval = tmp; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1695 } |
4806 | 1696 } |
1697 else | |
5823 | 1698 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
|
1699 |
4806 | 1700 return retval; |
1701 } | |
1702 | |
1703 DEFUN (horzcat, args, , | |
4824 | 1704 "-*- texinfo -*-\n\ |
4806 | 1705 @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
|
1706 Return the horizontal concatenation of N-D array objects, @var{array1},\n\ |
4806 | 1707 @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
|
1708 \n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
1709 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
|
1710 new matrices. For example:\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
1711 \n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
1712 @example\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
1713 @var{hcat} = [ @var{array1}, @var{array2}, @dots{} ];\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
1714 @end example\n\ |
5642 | 1715 @seealso{cat, vertcat}\n\ |
1716 @end deftypefn") | |
4806 | 1717 { |
10716
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1718 return do_cat (args, -2, "horzcat"); |
4806 | 1719 } |
1720 | |
1721 DEFUN (vertcat, args, , | |
1722 "-*- texinfo -*-\n\ | |
1723 @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
|
1724 Return the vertical concatenation of N-D array objects, @var{array1},\n\ |
4806 | 1725 @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
|
1726 \n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
1727 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
|
1728 new matrices. For example:\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
1729 \n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
1730 @example\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
1731 @var{vcat} = [ @var{array1}; @var{array2}; @dots{} ];\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
1732 @end example\n\ |
5642 | 1733 @seealso{cat, horzcat}\n\ |
1734 @end deftypefn") | |
4806 | 1735 { |
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 return do_cat (args, -1, "vertcat"); |
4806 | 1737 } |
1738 | |
4758 | 1739 DEFUN (cat, args, , |
1740 "-*- texinfo -*-\n\ | |
1741 @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
|
1742 Return the concatenation of N-D array objects, @var{array1},\n\ |
4806 | 1743 @var{array2}, @dots{}, @var{arrayN} along dimension @var{dim}.\n\ |
4758 | 1744 \n\ |
1745 @example\n\ | |
1746 @group\n\ | |
1747 A = ones (2, 2);\n\ | |
1748 B = zeros (2, 2);\n\ | |
1749 cat (2, A, B)\n\ | |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
1750 @result{} 1 1 0 0\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
1751 1 1 0 0\n\ |
4758 | 1752 @end group\n\ |
1753 @end example\n\ | |
1754 \n\ | |
1755 Alternatively, we can concatenate @var{A} and @var{B} along the\n\ | |
1756 second dimension the following way:\n\ | |
1757 \n\ | |
1758 @example\n\ | |
1759 @group\n\ | |
1760 [A, B].\n\ | |
1761 @end group\n\ | |
1762 @end example\n\ | |
1763 \n\ | |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
1764 @var{dim} can be larger than the dimensions of the N-D array objects\n\ |
4758 | 1765 and the result will thus have @var{dim} dimensions as the\n\ |
1766 following example shows:\n\ | |
10840 | 1767 \n\ |
4758 | 1768 @example\n\ |
1769 @group\n\ | |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
1770 cat (4, ones (2, 2), zeros (2, 2))\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
1771 @result{} ans =\n\ |
4758 | 1772 \n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
1773 ans(:,:,1,1) =\n\ |
4758 | 1774 \n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
1775 1 1\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
1776 1 1\n\ |
4758 | 1777 \n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
1778 ans(:,:,1,2) =\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
1779 0 0\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
1780 0 0\n\ |
4758 | 1781 @end group\n\ |
1782 @end example\n\ | |
5642 | 1783 @seealso{horzcat, vertcat}\n\ |
1784 @end deftypefn") | |
4758 | 1785 { |
10716
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1786 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
|
1787 |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1788 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
|
1789 { |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1790 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
|
1791 |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1792 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
|
1793 { |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1794 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
|
1795 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
|
1796 else |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11591
diff
changeset
|
1797 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
|
1798 } |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1799 else |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11591
diff
changeset
|
1800 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
|
1801 } |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1802 else |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1803 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
|
1804 |
f7f26094021b
improve cat code design in data.cc, make horzcat/vertcat more Matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10711
diff
changeset
|
1805 return retval; |
4758 | 1806 } |
1807 | |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1808 /* |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1809 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1810 %!function ret = testcat (t1, t2, tr, cmplx) |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1811 %! assert (cat (1, cast ([], t1), cast([], t2)), cast ([], tr)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1812 %! |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1813 %! assert (cat (1, cast (1, t1), cast (2, t2)), cast ([1; 2], tr)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1814 %! assert (cat (1, cast (1, t1), cast ([2; 3], t2)), cast ([1; 2; 3], tr)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1815 %! assert (cat (1, cast ([1; 2], t1), cast (3, t2)), cast ([1; 2; 3], tr)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1816 %! assert (cat (1, cast ([1; 2], t1), cast ([3; 4], t2)), cast ([1; 2; 3; 4], tr)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1817 %! assert (cat (2, cast (1, t1), cast (2, t2)), cast ([1, 2], tr)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1818 %! assert (cat (2, cast (1, t1), cast ([2, 3], t2)), cast ([1, 2, 3], tr)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1819 %! assert (cat (2, cast ([1, 2], t1), cast (3, t2)), cast ([1, 2, 3], tr)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1820 %! assert (cat (2, cast ([1, 2], t1), cast ([3, 4], t2)), cast ([1, 2, 3, 4], tr)); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
1821 %! |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1822 %! assert ([cast(1, t1); cast(2, t2)], cast ([1; 2], tr)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1823 %! assert ([cast(1, t1); cast([2; 3], t2)], cast ([1; 2; 3], tr)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1824 %! assert ([cast([1; 2], t1); cast(3, t2)], cast ([1; 2; 3], tr)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1825 %! assert ([cast([1; 2], t1); cast([3; 4], t2)], cast ([1; 2; 3; 4], tr)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1826 %! assert ([cast(1, t1), cast(2, t2)], cast ([1, 2], tr)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1827 %! assert ([cast(1, t1), cast([2, 3], t2)], cast ([1, 2, 3], tr)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1828 %! assert ([cast([1, 2], t1), cast(3, t2)], cast ([1, 2, 3], tr)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1829 %! assert ([cast([1, 2], t1), cast([3, 4], t2)], cast ([1, 2, 3, 4], tr)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1830 %! |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1831 %! if (nargin == 3 || cmplx) |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1832 %! assert (cat (1, cast (1i, t1), cast (2, t2)), cast ([1i; 2], tr)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1833 %! assert (cat (1, cast (1i, t1), cast ([2; 3], t2)), cast ([1i; 2; 3], tr)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1834 %! assert (cat (1, cast ([1i; 2], t1), cast (3, t2)), cast ([1i; 2; 3], tr)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1835 %! assert (cat (1, cast ([1i; 2], t1), cast ([3; 4], t2)), cast ([1i; 2; 3; 4], tr)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1836 %! assert (cat (2, cast (1i, t1), cast (2, t2)), cast ([1i, 2], tr)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1837 %! assert (cat (2, cast (1i, t1), cast ([2, 3], t2)), cast ([1i, 2, 3], tr)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1838 %! assert (cat (2, cast ([1i, 2], t1), cast (3, t2)), cast ([1i, 2, 3], tr)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1839 %! assert (cat (2, cast ([1i, 2], t1), cast ([3, 4], t2)), cast ([1i, 2, 3, 4], tr)); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
1840 %! |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1841 %! assert ([cast(1i, t1); cast(2, t2)], cast ([1i; 2], tr)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1842 %! assert ([cast(1i, t1); cast([2; 3], t2)], cast ([1i; 2; 3], tr)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1843 %! assert ([cast([1i; 2], t1); cast(3, t2)], cast ([1i; 2; 3], tr)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1844 %! assert ([cast([1i; 2], t1); cast([3; 4], t2)], cast ([1i; 2; 3; 4], tr)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1845 %! assert ([cast(1i, t1), cast(2, t2)], cast ([1i, 2], tr)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1846 %! assert ([cast(1i, t1), cast([2, 3], t2)], cast ([1i, 2, 3], tr)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1847 %! assert ([cast([1i, 2], t1), cast(3, t2)], cast ([1i, 2, 3], tr)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1848 %! assert ([cast([1i, 2], t1), cast([3, 4], t2)], cast ([1i, 2, 3, 4], tr)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1849 %! |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1850 %! assert (cat (1, cast (1, t1), cast (2i, t2)), cast ([1; 2i], tr)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1851 %! assert (cat (1, cast (1, t1), cast ([2i; 3], t2)), cast ([1; 2i; 3], tr)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1852 %! assert (cat (1, cast ([1; 2], t1), cast (3i, t2)), cast ([1; 2; 3i], tr)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1853 %! assert (cat (1, cast ([1; 2], t1), cast ([3i; 4], t2)), cast ([1; 2; 3i; 4], tr)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1854 %! assert (cat (2, cast (1, t1), cast (2i, t2)), cast ([1, 2i], tr)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1855 %! assert (cat (2, cast (1, t1), cast ([2i, 3], t2)), cast ([1, 2i, 3], tr)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1856 %! assert (cat (2, cast ([1, 2], t1), cast (3i, t2)), cast ([1, 2, 3i], tr)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1857 %! assert (cat (2, cast ([1, 2], t1), cast ([3i, 4], t2)), cast ([1, 2, 3i, 4], tr)); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
1858 %! |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1859 %! assert ([cast(1, t1); cast(2i, t2)], cast ([1; 2i], tr)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1860 %! assert ([cast(1, t1); cast([2i; 3], t2)], cast ([1; 2i; 3], tr)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1861 %! assert ([cast([1; 2], t1); cast(3i, t2)], cast ([1; 2; 3i], tr)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1862 %! assert ([cast([1; 2], t1); cast([3i; 4], t2)], cast ([1; 2; 3i; 4], tr)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1863 %! assert ([cast(1, t1), cast(2i, t2)], cast ([1, 2i], tr)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1864 %! assert ([cast(1, t1), cast([2i, 3], t2)], cast ([1, 2i, 3], tr)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1865 %! assert ([cast([1, 2], t1), cast(3i, t2)], cast ([1, 2, 3i], tr)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1866 %! assert ([cast([1, 2], t1), cast([3i, 4], t2)], cast ([1, 2, 3i, 4], tr)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1867 %! |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1868 %! assert (cat (1, cast (1i, t1), cast (2i, t2)), cast ([1i; 2i], tr)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1869 %! assert (cat (1, cast (1i, t1), cast ([2i; 3], t2)), cast ([1i; 2i; 3], tr)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1870 %! assert (cat (1, cast ([1i; 2], t1), cast (3i, t2)), cast ([1i; 2; 3i], tr)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1871 %! assert (cat (1, cast ([1i; 2], t1), cast ([3i; 4], t2)), cast ([1i; 2; 3i; 4], tr)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1872 %! assert (cat (2, cast (1i, t1), cast (2i, t2)), cast ([1i, 2i], tr)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1873 %! assert (cat (2, cast (1i, t1), cast ([2i, 3], t2)), cast ([1i, 2i, 3], tr)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1874 %! assert (cat (2, cast ([1i, 2], t1), cast (3i, t2)), cast ([1i, 2, 3i], tr)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1875 %! assert (cat (2, cast ([1i, 2], t1), cast ([3i, 4], t2)), cast ([1i, 2, 3i, 4], tr)); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
1876 %! |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1877 %! assert ([cast(1i, t1); cast(2i, t2)], cast ([1i; 2i], tr)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1878 %! assert ([cast(1i, t1); cast([2i; 3], t2)], cast ([1i; 2i; 3], tr)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1879 %! assert ([cast([1i; 2], t1); cast(3i, t2)], cast ([1i; 2; 3i], tr)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1880 %! assert ([cast([1i; 2], t1); cast([3i; 4], t2)], cast ([1i; 2; 3i; 4], tr)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1881 %! assert ([cast(1i, t1), cast(2i, t2)], cast ([1i, 2i], tr)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1882 %! assert ([cast(1i, t1), cast([2i, 3], t2)], cast ([1i, 2i, 3], tr)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1883 %! assert ([cast([1i, 2], t1), cast(3i, t2)], cast ([1i, 2, 3i], tr)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1884 %! assert ([cast([1i, 2], t1), cast([3i, 4], t2)], cast ([1i, 2, 3i, 4], tr)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1885 %! endif |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1886 %! ret = true; |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1887 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1888 %!assert (testcat('double', 'double', 'double')); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1889 %!assert (testcat('single', 'double', 'single')); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1890 %!assert (testcat('double', 'single', 'single')); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1891 %!assert (testcat('single', 'single', 'single')); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1892 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1893 %!assert (testcat('double', 'int8', 'int8', false)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1894 %!assert (testcat('int8', 'double', 'int8', false)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1895 %!assert (testcat('single', 'int8', 'int8', false)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1896 %!assert (testcat('int8', 'single', 'int8', false)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1897 %!assert (testcat('int8', 'int8', 'int8', false)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1898 %!assert (testcat('double', 'int16', 'int16', false)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1899 %!assert (testcat('int16', 'double', 'int16', false)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1900 %!assert (testcat('single', 'int16', 'int16', false)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1901 %!assert (testcat('int16', 'single', 'int16', false)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1902 %!assert (testcat('int16', 'int16', 'int16', false)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1903 %!assert (testcat('double', 'int32', 'int32', false)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1904 %!assert (testcat('int32', 'double', 'int32', false)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1905 %!assert (testcat('single', 'int32', 'int32', false)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1906 %!assert (testcat('int32', 'single', 'int32', false)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1907 %!assert (testcat('int32', 'int32', 'int32', false)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1908 %!assert (testcat('double', 'int64', 'int64', false)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1909 %!assert (testcat('int64', 'double', 'int64', false)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1910 %!assert (testcat('single', 'int64', 'int64', false)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1911 %!assert (testcat('int64', 'single', 'int64', false)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1912 %!assert (testcat('int64', 'int64', 'int64', false)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1913 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1914 %!assert (testcat('double', 'uint8', 'uint8', false)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1915 %!assert (testcat('uint8', 'double', 'uint8', false)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1916 %!assert (testcat('single', 'uint8', 'uint8', false)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1917 %!assert (testcat('uint8', 'single', 'uint8', false)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1918 %!assert (testcat('uint8', 'uint8', 'uint8', false)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1919 %!assert (testcat('double', 'uint16', 'uint16', false)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1920 %!assert (testcat('uint16', 'double', 'uint16', false)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1921 %!assert (testcat('single', 'uint16', 'uint16', false)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1922 %!assert (testcat('uint16', 'single', 'uint16', false)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1923 %!assert (testcat('uint16', 'uint16', 'uint16', false)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1924 %!assert (testcat('double', 'uint32', 'uint32', false)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1925 %!assert (testcat('uint32', 'double', 'uint32', false)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1926 %!assert (testcat('single', 'uint32', 'uint32', false)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1927 %!assert (testcat('uint32', 'single', 'uint32', false)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1928 %!assert (testcat('uint32', 'uint32', 'uint32', false)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1929 %!assert (testcat('double', 'uint64', 'uint64', false)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1930 %!assert (testcat('uint64', 'double', 'uint64', false)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1931 %!assert (testcat('single', 'uint64', 'uint64', false)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1932 %!assert (testcat('uint64', 'single', 'uint64', false)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1933 %!assert (testcat('uint64', 'uint64', 'uint64', false)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1934 |
11241
80e01d79cf80
special case for concatenation of empty matrices
John W. Eaton <jwe@octave.org>
parents:
11209
diff
changeset
|
1935 %!assert (cat (3, [], [1,2;3,4]), [1,2;3,4]); |
80e01d79cf80
special case for concatenation of empty matrices
John W. Eaton <jwe@octave.org>
parents:
11209
diff
changeset
|
1936 %!assert (cat (3, [1,2;3,4], []), [1,2;3,4]); |
80e01d79cf80
special case for concatenation of empty matrices
John W. Eaton <jwe@octave.org>
parents:
11209
diff
changeset
|
1937 %!assert (cat (3, [], [1,2;3,4], []), [1,2;3,4]); |
80e01d79cf80
special case for concatenation of empty matrices
John W. Eaton <jwe@octave.org>
parents:
11209
diff
changeset
|
1938 %!assert (cat (3, [], [], []), zeros (0, 0, 3)); |
80e01d79cf80
special case for concatenation of empty matrices
John W. Eaton <jwe@octave.org>
parents:
11209
diff
changeset
|
1939 |
11242
0090bb47d0b5
simplify special case for concatenation of empty matrices
John W. Eaton <jwe@octave.org>
parents:
11241
diff
changeset
|
1940 %!assert (cat (3, [], [], 1, 2), cat (3, 1, 2)); |
11241
80e01d79cf80
special case for concatenation of empty matrices
John W. Eaton <jwe@octave.org>
parents:
11209
diff
changeset
|
1941 %!assert (cat (3, [], [], [1,2;3,4]), [1,2;3,4]); |
80e01d79cf80
special case for concatenation of empty matrices
John W. Eaton <jwe@octave.org>
parents:
11209
diff
changeset
|
1942 %!assert (cat (4, [], [], [1,2;3,4]), [1,2;3,4]); |
80e01d79cf80
special case for concatenation of empty matrices
John W. Eaton <jwe@octave.org>
parents:
11209
diff
changeset
|
1943 %!error <dimension mismatch> cat (3, cat (3, [], []), [1,2;3,4]); |
80e01d79cf80
special case for concatenation of empty matrices
John W. Eaton <jwe@octave.org>
parents:
11209
diff
changeset
|
1944 %!error <dimension mismatch> cat (3, zeros (0, 0, 2), [1,2;3,4]); |
10498
8615b55b5caf
fix & improve cat (bug #29465)
Jaroslav Hajek <highegg@gmail.com>
parents:
10436
diff
changeset
|
1945 |
12861
5ad509db825b
test: Tests for bug #32683 involving incorrect ndarray concatenation
Alois Schlögl
parents:
12681
diff
changeset
|
1946 %!assert ([zeros(3,2,2); ones(1,2,2)], repmat([0;0;0;1],[1,2,2]) ); |
5ad509db825b
test: Tests for bug #32683 involving incorrect ndarray concatenation
Alois Schlögl
parents:
12681
diff
changeset
|
1947 %!assert ([zeros(3,2,2); ones(1,2,2)], vertcat(zeros(3,2,2), ones(1,2,2)) ); |
5ad509db825b
test: Tests for bug #32683 involving incorrect ndarray concatenation
Alois Schlögl
parents:
12681
diff
changeset
|
1948 |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1949 */ |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
1950 |
4593 | 1951 static octave_value |
6959 | 1952 do_permute (const octave_value_list& args, bool inv) |
4593 | 1953 { |
1954 octave_value retval; | |
1955 | |
5148 | 1956 if (args.length () == 2 && args(1).length () >= args(1).ndims ()) |
4593 | 1957 { |
1958 Array<int> vec = args(1).int_vector_value (); | |
1959 | |
5775 | 1960 // FIXME -- maybe we should create an idx_vector object |
5148 | 1961 // here and pass that to permute? |
1962 | |
1963 int n = vec.length (); | |
1964 | |
1965 for (int i = 0; i < n; i++) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1966 vec(i)--; |
5148 | 1967 |
4593 | 1968 octave_value ret = args(0).permute (vec, inv); |
1969 | |
1970 if (! error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
1971 retval = ret; |
4593 | 1972 } |
1973 else | |
5823 | 1974 print_usage (); |
4593 | 1975 |
1976 return retval; | |
1977 } | |
1978 | |
1979 DEFUN (permute, args, , | |
1980 "-*- texinfo -*-\n\ | |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
1981 @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
|
1982 Return the generalized transpose for an N-D array object @var{A}.\n\ |
4593 | 1983 The permutation vector @var{perm} must contain the elements\n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
1984 @code{1:ndims(A)} (in any order, but each element must appear only once).\n\ |
5642 | 1985 @seealso{ipermute}\n\ |
1986 @end deftypefn") | |
4593 | 1987 { |
6959 | 1988 return do_permute (args, false); |
4593 | 1989 } |
1990 | |
1991 DEFUN (ipermute, args, , | |
1992 "-*- texinfo -*-\n\ | |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
1993 @deftypefn {Built-in Function} {} ipermute (@var{A}, @var{iperm})\n\ |
4593 | 1994 The inverse of the @code{permute} function. The expression\n\ |
1995 \n\ | |
1996 @example\n\ | |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
1997 ipermute (permute (A, perm), perm)\n\ |
4593 | 1998 @end example\n\ |
10840 | 1999 \n\ |
10846
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10840
diff
changeset
|
2000 @noindent\n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
2001 returns the original array @var{A}.\n\ |
5642 | 2002 @seealso{permute}\n\ |
2003 @end deftypefn") | |
4593 | 2004 { |
6959 | 2005 return do_permute (args, true); |
4593 | 2006 } |
2007 | |
3195 | 2008 DEFUN (length, args, , |
3373 | 2009 "-*- texinfo -*-\n\ |
2010 @deftypefn {Built-in Function} {} length (@var{a})\n\ | |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
2011 Return the \"length\" of the object @var{a}. For matrix objects, the\n\ |
3373 | 2012 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
|
2013 odd definition is used for compatibility with @sc{matlab}).\n\ |
3373 | 2014 @end deftypefn") |
3195 | 2015 { |
2016 octave_value retval; | |
2017 | |
2018 if (args.length () == 1) | |
9706
71160b139b07
simplify length,ndims,size and size_equal
Jaroslav Hajek <highegg@gmail.com>
parents:
9705
diff
changeset
|
2019 retval = args(0).length (); |
3195 | 2020 else |
5823 | 2021 print_usage (); |
3195 | 2022 |
2023 return retval; | |
2024 } | |
2025 | |
4554 | 2026 DEFUN (ndims, args, , |
2027 "-*- texinfo -*-\n\ | |
2028 @deftypefn {Built-in Function} {} ndims (@var{a})\n\ | |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
2029 Return the number of dimensions of @var{a}.\n\ |
4554 | 2030 For any array, the result will always be larger than or equal to 2.\n\ |
2031 Trailing singleton dimensions are not counted.\n\ | |
10840 | 2032 \n\ |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
2033 @example\n\ |
10711
fbd7843974fa
Periodic grammar check of documentation files to ensure common format.
Rik <octave@nomad.inbox5.com>
parents:
10707
diff
changeset
|
2034 @group\n\ |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
2035 ndims (ones (4, 1, 2, 1)\n\ |
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
2036 @result{} 3\n\ |
10711
fbd7843974fa
Periodic grammar check of documentation files to ensure common format.
Rik <octave@nomad.inbox5.com>
parents:
10707
diff
changeset
|
2037 @end group\n\ |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
2038 @end example\n\ |
4554 | 2039 @end deftypefn") |
2040 { | |
2041 octave_value retval; | |
2042 | |
2043 if (args.length () == 1) | |
9706
71160b139b07
simplify length,ndims,size and size_equal
Jaroslav Hajek <highegg@gmail.com>
parents:
9705
diff
changeset
|
2044 retval = args(0).ndims (); |
4554 | 2045 else |
5823 | 2046 print_usage (); |
4554 | 2047 |
2048 return retval; | |
2049 } | |
2050 | |
4559 | 2051 DEFUN (numel, args, , |
2052 "-*- texinfo -*-\n\ | |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
2053 @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
|
2054 @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
|
2055 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
|
2056 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
|
2057 return the number of elements that would result from the indexing\n\ |
10840 | 2058 \n\ |
9705
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
2059 @example\n\ |
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
2060 @var{a}(@var{idx1}, @var{idx2}, @dots{})\n\ |
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
2061 @end example\n\ |
10840 | 2062 \n\ |
9705
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
2063 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
|
2064 indexing, i.e., @code{object@{@dots{}@}} or @code{object(@dots{}).field}.\n\ |
5724 | 2065 @seealso{size}\n\ |
4559 | 2066 @end deftypefn") |
2067 { | |
2068 octave_value retval; | |
9329
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9319
diff
changeset
|
2069 octave_idx_type nargin = args.length (); |
67fc970dad7d
improve indexed assignment using indexed numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9319
diff
changeset
|
2070 |
9705
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
2071 if (nargin == 1) |
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
2072 retval = args(0).numel (); |
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
2073 else if (nargin > 1) |
4559 | 2074 { |
9705
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
2075 // 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
|
2076 // an overloaded call, not to builtin! |
5acd99c3e794
avoid recursive overloaded calls in builtin numel
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
2077 retval = dims_to_numel (args(0).dims (), args.slice (1, nargin-1)); |
4559 | 2078 } |
2079 else | |
5823 | 2080 print_usage (); |
4559 | 2081 |
2082 return retval; | |
2083 } | |
2084 | |
1957 | 2085 DEFUN (size, args, nargout, |
3373 | 2086 "-*- texinfo -*-\n\ |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
2087 @deftypefn {Built-in Function} {} size (@var{a})\n\ |
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
2088 @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
|
2089 Return the number of rows and columns of @var{a}.\n\ |
3373 | 2090 \n\ |
2091 With one input argument and one output argument, the result is returned\n\ | |
4741 | 2092 in a row vector. If there are multiple output arguments, the number of\n\ |
2093 rows is assigned to the first, and the number of columns to the second,\n\ | |
10840 | 2094 etc. For example:\n\ |
3373 | 2095 \n\ |
2096 @example\n\ | |
2097 @group\n\ | |
2098 size ([1, 2; 3, 4; 5, 6])\n\ | |
2099 @result{} [ 3, 2 ]\n\ | |
1031 | 2100 \n\ |
3373 | 2101 [nr, nc] = size ([1, 2; 3, 4; 5, 6])\n\ |
2102 @result{} nr = 3\n\ | |
2103 @result{} nc = 2\n\ | |
2104 @end group\n\ | |
2105 @end example\n\ | |
2106 \n\ | |
4741 | 2107 If given a second argument, @code{size} will return the size of the\n\ |
10840 | 2108 corresponding dimension. For example,\n\ |
1031 | 2109 \n\ |
3373 | 2110 @example\n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
9041
diff
changeset
|
2111 @group\n\ |
3373 | 2112 size ([1, 2; 3, 4; 5, 6], 2)\n\ |
2113 @result{} 2\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
9041
diff
changeset
|
2114 @end group\n\ |
3373 | 2115 @end example\n\ |
2116 \n\ | |
2117 @noindent\n\ | |
2118 returns the number of columns in the given matrix.\n\ | |
5724 | 2119 @seealso{numel}\n\ |
3373 | 2120 @end deftypefn") |
523 | 2121 { |
2086 | 2122 octave_value_list retval; |
523 | 2123 |
2124 int nargin = args.length (); | |
2125 | |
4513 | 2126 if (nargin == 1) |
523 | 2127 { |
9706
71160b139b07
simplify length,ndims,size and size_equal
Jaroslav Hajek <highegg@gmail.com>
parents:
9705
diff
changeset
|
2128 const dim_vector dimensions = args(0).dims (); |
4513 | 2129 |
2130 if (nargout > 1) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2131 { |
9706
71160b139b07
simplify length,ndims,size and size_equal
Jaroslav Hajek <highegg@gmail.com>
parents:
9705
diff
changeset
|
2132 const dim_vector rdims = dimensions.redim (nargout); |
71160b139b07
simplify length,ndims,size and size_equal
Jaroslav Hajek <highegg@gmail.com>
parents:
9705
diff
changeset
|
2133 retval.resize (nargout); |
71160b139b07
simplify length,ndims,size and size_equal
Jaroslav Hajek <highegg@gmail.com>
parents:
9705
diff
changeset
|
2134 for (int i = 0; i < nargout; i++) |
71160b139b07
simplify length,ndims,size and size_equal
Jaroslav Hajek <highegg@gmail.com>
parents:
9705
diff
changeset
|
2135 retval(i) = rdims(i); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2136 } |
4513 | 2137 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2138 { |
9706
71160b139b07
simplify length,ndims,size and size_equal
Jaroslav Hajek <highegg@gmail.com>
parents:
9705
diff
changeset
|
2139 int ndims = dimensions.length (); |
71160b139b07
simplify length,ndims,size and size_equal
Jaroslav Hajek <highegg@gmail.com>
parents:
9705
diff
changeset
|
2140 |
71160b139b07
simplify length,ndims,size and size_equal
Jaroslav Hajek <highegg@gmail.com>
parents:
9705
diff
changeset
|
2141 NoAlias<Matrix> m (1, ndims); |
71160b139b07
simplify length,ndims,size and size_equal
Jaroslav Hajek <highegg@gmail.com>
parents:
9705
diff
changeset
|
2142 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2143 for (int i = 0; i < ndims; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2144 m(i) = dimensions(i); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2145 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2146 retval(0) = m; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2147 } |
1031 | 2148 } |
2149 else if (nargin == 2 && nargout < 2) | |
2150 { | |
5275 | 2151 octave_idx_type nd = args(1).int_value (true); |
1031 | 2152 |
2153 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
|
2154 error ("size: DIM must be a scalar"); |
712 | 2155 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2156 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2157 const dim_vector dv = args(0).dims (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2158 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2159 if (nd > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2160 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2161 if (nd <= dv.length ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2162 retval(0) = dv(nd-1); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
2163 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2164 retval(0) = 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2165 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
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 ("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
|
2168 } |
523 | 2169 } |
712 | 2170 else |
5823 | 2171 print_usage (); |
523 | 2172 |
2173 return retval; | |
2174 } | |
2175 | |
6156 | 2176 DEFUN (size_equal, args, , |
2177 "-*- texinfo -*-\n\ | |
6561 | 2178 @deftypefn {Built-in Function} {} size_equal (@var{a}, @var{b}, @dots{})\n\ |
2179 Return true if the dimensions of all arguments agree.\n\ | |
6156 | 2180 Trailing singleton dimensions are ignored.\n\ |
10002
e93c9bfff8b8
allow size_equal with 0 arguments
Jaroslav Hajek <highegg@gmail.com>
parents:
9866
diff
changeset
|
2181 Called with a single or no argument, size_equal returns true.\n\ |
6156 | 2182 @seealso{size, numel}\n\ |
2183 @end deftypefn") | |
2184 { | |
2185 octave_value retval; | |
2186 | |
6561 | 2187 int nargin = args.length (); |
2188 | |
10002
e93c9bfff8b8
allow size_equal with 0 arguments
Jaroslav Hajek <highegg@gmail.com>
parents:
9866
diff
changeset
|
2189 retval = true; |
e93c9bfff8b8
allow size_equal with 0 arguments
Jaroslav Hajek <highegg@gmail.com>
parents:
9866
diff
changeset
|
2190 |
8947
1e4b3149365a
allow size_equal called with 1 arg
Jaroslav Hajek <highegg@gmail.com>
parents:
8934
diff
changeset
|
2191 if (nargin >= 1) |
6156 | 2192 { |
2193 dim_vector a_dims = args(0).dims (); | |
6561 | 2194 |
2195 for (int i = 1; i < nargin; ++i) | |
2196 { | |
2197 dim_vector b_dims = args(i).dims (); | |
2198 | |
2199 if (a_dims != b_dims) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2200 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2201 retval = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2202 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2203 } |
6561 | 2204 } |
6156 | 2205 } |
2206 | |
2207 return retval; | |
2208 } | |
2209 | |
5602 | 2210 DEFUN (nnz, args, , |
2211 "-*- texinfo -*-\n\ | |
6156 | 2212 @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
|
2213 Return the number of non zero elements in @var{a}.\n\ |
5602 | 2214 @seealso{sparse}\n\ |
2215 @end deftypefn") | |
2216 { | |
2217 octave_value retval; | |
2218 | |
2219 if (args.length () == 1) | |
2220 retval = args(0).nnz (); | |
2221 else | |
5823 | 2222 print_usage (); |
5602 | 2223 |
2224 return retval; | |
2225 } | |
2226 | |
5604 | 2227 DEFUN (nzmax, args, , |
2228 "-*- texinfo -*-\n\ | |
6156 | 2229 @deftypefn {Built-in Function} {@var{scalar} =} nzmax (@var{SM})\n\ |
5604 | 2230 Return the amount of storage allocated to the sparse matrix @var{SM}.\n\ |
7001 | 2231 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
|
2232 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
|
2233 where the value returned by @dfn{nzmax} will not be the same as @dfn{nnz},\n\ |
5604 | 2234 but in general they will give the same result.\n\ |
2235 @seealso{sparse, spalloc}\n\ | |
2236 @end deftypefn") | |
2237 { | |
2238 octave_value retval; | |
2239 | |
2240 if (args.length() == 1) | |
2241 retval = args(0).nzmax (); | |
2242 else | |
5823 | 2243 print_usage (); |
5604 | 2244 |
2245 return retval; | |
2246 } | |
2247 | |
5677 | 2248 DEFUN (rows, args, , |
2249 "-*- texinfo -*-\n\ | |
2250 @deftypefn {Built-in Function} {} rows (@var{a})\n\ | |
2251 Return the number of rows of @var{a}.\n\ | |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
2252 @seealso{columns, size, length, numel, isscalar, isvector, ismatrix}\n\ |
5677 | 2253 @end deftypefn") |
2254 { | |
2255 octave_value retval; | |
2256 | |
2257 if (args.length () == 1) | |
2258 retval = args(0).rows (); | |
2259 else | |
5823 | 2260 print_usage (); |
5677 | 2261 |
2262 return retval; | |
2263 } | |
2264 | |
2265 DEFUN (columns, args, , | |
2266 "-*- texinfo -*-\n\ | |
2267 @deftypefn {Built-in Function} {} columns (@var{a})\n\ | |
2268 Return the number of columns of @var{a}.\n\ | |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
2269 @seealso{rows, size, length, numel, isscalar, isvector, ismatrix}\n\ |
5677 | 2270 @end deftypefn") |
2271 { | |
2272 octave_value retval; | |
2273 | |
2274 if (args.length () == 1) | |
2275 retval = args(0).columns (); | |
2276 else | |
5823 | 2277 print_usage (); |
5677 | 2278 |
2279 return retval; | |
2280 } | |
2281 | |
1957 | 2282 DEFUN (sum, args, , |
3428 | 2283 "-*- texinfo -*-\n\ |
9163
9cb0c21e97f7
Update section 17.4 (Sums and Products) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9155
diff
changeset
|
2284 @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
|
2285 @deftypefnx {Built-in Function} {} sum (@var{x}, @var{dim})\n\ |
7112 | 2286 @deftypefnx {Built-in Function} {} sum (@dots{}, 'native')\n\ |
9721
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2287 @deftypefnx {Built-in Function} {} sum (@dots{}, 'double')\n\ |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2288 @deftypefnx {Built-in Function} {} sum (@dots{}, 'extra')\n\ |
3723 | 2289 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
|
2290 omitted, it defaults to the first non-singleton dimension.\n\ |
7112 | 2291 \n\ |
2292 If the optional argument 'native' is given, then the sum is performed\n\ | |
2293 in the same type as the original argument, rather than in the default\n\ | |
10840 | 2294 double type. For example:\n\ |
7112 | 2295 \n\ |
2296 @example\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
9041
diff
changeset
|
2297 @group\n\ |
7112 | 2298 sum ([true, true])\n\ |
2299 @result{} 2\n\ | |
2300 sum ([true, true], 'native')\n\ | |
2301 @result{} true\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
9041
diff
changeset
|
2302 @end group\n\ |
7112 | 2303 @end example\n\ |
10840 | 2304 \n\ |
10846
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10840
diff
changeset
|
2305 On the contrary, if 'double' is given, the sum is performed in double\n\ |
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10840
diff
changeset
|
2306 precision even for single precision inputs.\n\ |
9723
f426899f4b9c
fix reduction functions docstrings
Jaroslav Hajek <highegg@gmail.com>
parents:
9721
diff
changeset
|
2307 \n\ |
9721
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2308 For double precision inputs, 'extra' indicates that a more accurate algorithm\n\ |
10840 | 2309 than straightforward summation is to be used. For single precision inputs,\n\ |
2310 'extra' is the same as 'double'. Otherwise, 'extra' has no effect.\n\ | |
9163
9cb0c21e97f7
Update section 17.4 (Sums and Products) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9155
diff
changeset
|
2311 @seealso{cumsum, sumsq, prod}\n\ |
3428 | 2312 @end deftypefn") |
523 | 2313 { |
9721
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2314 octave_value retval; |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2315 |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2316 int nargin = args.length (); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2317 |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2318 bool isnative = false; |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2319 bool isdouble = false; |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2320 bool isextra = false; |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2321 |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2322 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
|
2323 { |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2324 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
|
2325 |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2326 if (! error_state) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2327 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2328 if (str == "native") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2329 isnative = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2330 else if (str == "double") |
9721
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2331 isdouble = true; |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2332 else if (str == "extra") |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2333 isextra = true; |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2334 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2335 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
|
2336 nargin --; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2337 } |
9721
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2338 } |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2339 |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2340 if (error_state) |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2341 return retval; |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2342 |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2343 if (nargin == 1 || nargin == 2) |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2344 { |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2345 octave_value arg = args(0); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2346 |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2347 int dim = -1; |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2348 if (nargin == 2) |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2349 { |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2350 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
|
2351 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
|
2352 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
|
2353 } |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2354 |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2355 if (! error_state) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2356 { |
9721
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2357 switch (arg.builtin_type ()) |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2358 { |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2359 case btyp_double: |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2360 if (arg.is_sparse_type ()) |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2361 { |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2362 if (isextra) |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2363 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
|
2364 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
|
2365 } |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2366 else if (isextra) |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2367 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
|
2368 else |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2369 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
|
2370 break; |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2371 case btyp_complex: |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2372 if (arg.is_sparse_type ()) |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2373 { |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2374 if (isextra) |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2375 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
|
2376 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
|
2377 } |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2378 else if (isextra) |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2379 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
|
2380 else |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2381 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
|
2382 break; |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2383 case btyp_float: |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2384 if (isdouble || isextra) |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2385 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
|
2386 else |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2387 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
|
2388 break; |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2389 case btyp_float_complex: |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2390 if (isdouble || isextra) |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2391 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
|
2392 else |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2393 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
|
2394 break; |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2395 |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2396 #define MAKE_INT_BRANCH(X) \ |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2397 case btyp_ ## X: \ |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2398 if (isnative) \ |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2399 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
|
2400 else \ |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2401 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
|
2402 break |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2403 MAKE_INT_BRANCH (int8); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2404 MAKE_INT_BRANCH (int16); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2405 MAKE_INT_BRANCH (int32); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2406 MAKE_INT_BRANCH (int64); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2407 MAKE_INT_BRANCH (uint8); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2408 MAKE_INT_BRANCH (uint16); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2409 MAKE_INT_BRANCH (uint32); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2410 MAKE_INT_BRANCH (uint64); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2411 #undef MAKE_INT_BRANCH |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2412 |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2413 case btyp_bool: |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2414 if (arg.is_sparse_type ()) |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2415 { |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2416 if (isnative) |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2417 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
|
2418 else |
10983
4b51c0a20a98
optimize sum of sparse logical matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10880
diff
changeset
|
2419 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
|
2420 } |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2421 else if (isnative) |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2422 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
|
2423 else |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2424 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
|
2425 break; |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2426 |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2427 default: |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2428 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
|
2429 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2430 } |
9721
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2431 } |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2432 else |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2433 print_usage (); |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2434 |
192d94cff6c1
improve sum & implement the 'extra' option, refactor some code
Jaroslav Hajek <highegg@gmail.com>
parents:
9706
diff
changeset
|
2435 return retval; |
523 | 2436 } |
2437 | |
7112 | 2438 /* |
2439 | |
2440 %!assert (sum([true,true]), 2) | |
2441 %!assert (sum([true,true],'native'), true) | |
2442 %!assert (sum(int8([127,10,-20])), 117); | |
2443 %!assert (sum(int8([127,10,-20]),'native'), int8(107)); | |
2444 | |
7815
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2445 %!assert(sum ([1, 2, 3]), 6) |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2446 %!assert(sum ([-1; -2; -3]), -6); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2447 %!assert(sum ([i, 2+i, -3+2i, 4]), 3+4i); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2448 %!assert(sum ([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i]), [2+2i, 4+4i, 6+6i]); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2449 |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2450 %!assert(sum (single([1, 2, 3])), single(6)) |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2451 %!assert(sum (single([-1; -2; -3])), single(-6)); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2452 %!assert(sum (single([i, 2+i, -3+2i, 4])), single(3+4i)); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2453 %!assert(sum (single([1, 2, 3; i, 2i, 3i; 1+i, 2+2i, 3+3i])), single([2+2i, 4+4i, 6+6i])); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2454 |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2455 %!error <Invalid call to sum.*> sum (); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2456 |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2457 %!assert (sum ([1, 2; 3, 4], 1), [4, 6]); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2458 %!assert (sum ([1, 2; 3, 4], 2), [3; 7]); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2459 %!assert (sum (zeros (1, 0)), 0); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2460 %!assert (sum (zeros (1, 0), 1), zeros(1, 0)); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2461 %!assert (sum (zeros (1, 0), 2), 0); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2462 %!assert (sum (zeros (0, 1)), 0); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2463 %!assert (sum (zeros (0, 1), 1), 0); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2464 %!assert (sum (zeros (0, 1), 2), zeros(0, 1)); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2465 %!assert (sum (zeros (2, 0)), zeros(1, 0)); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2466 %!assert (sum (zeros (2, 0), 1), zeros(1, 0)); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2467 %!assert (sum (zeros (2, 0), 2), [0; 0]); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2468 %!assert (sum (zeros (0, 2)), [0, 0]); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2469 %!assert (sum (zeros (0, 2), 1), [0, 0]); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2470 %!assert (sum (zeros (0, 2), 2), zeros(0, 1)); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2471 %!assert (sum (zeros (2, 2, 0, 3)), zeros(1, 2, 0, 3)); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2472 %!assert (sum (zeros (2, 2, 0, 3), 2), zeros(2, 1, 0, 3)); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2473 %!assert (sum (zeros (2, 2, 0, 3), 3), zeros(2, 2, 1, 3)); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2474 %!assert (sum (zeros (2, 2, 0, 3), 4), zeros(2, 2, 0)); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2475 %!assert (sum (zeros (2, 2, 0, 3), 7), zeros(2, 2, 0, 3)); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2476 |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2477 %!assert (sum (single([1, 2; 3, 4]), 1), single([4, 6])); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2478 %!assert (sum (single([1, 2; 3, 4]), 2), single([3; 7])); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2479 %!assert (sum (zeros (1, 0, 'single')), single(0)); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2480 %!assert (sum (zeros (1, 0, 'single'), 1), zeros(1, 0, 'single')); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2481 %!assert (sum (zeros (1, 0, 'single'), 2), single(0)); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2482 %!assert (sum (zeros (0, 1, 'single')), single(0)); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2483 %!assert (sum (zeros (0, 1, 'single'), 1), single(0)); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2484 %!assert (sum (zeros (0, 1, 'single'), 2), zeros(0, 1, 'single')); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2485 %!assert (sum (zeros (2, 0, 'single')), zeros(1, 0, 'single')); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2486 %!assert (sum (zeros (2, 0, 'single'), 1), zeros(1, 0, 'single')); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2487 %!assert (sum (zeros (2, 0, 'single'), 2), single([0; 0])); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2488 %!assert (sum (zeros (0, 2, 'single')), single([0, 0])); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2489 %!assert (sum (zeros (0, 2, 'single'), 1), single([0, 0])); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2490 %!assert (sum (zeros (0, 2, 'single'), 2), zeros(0, 1, 'single')); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2491 %!assert (sum (zeros (2, 2, 0, 3, 'single')), zeros(1, 2, 0, 3, 'single')); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2492 %!assert (sum (zeros (2, 2, 0, 3, 'single'), 2), zeros(2, 1, 0, 3, 'single')); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2493 %!assert (sum (zeros (2, 2, 0, 3, 'single'), 3), zeros(2, 2, 1, 3, 'single')); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2494 %!assert (sum (zeros (2, 2, 0, 3, 'single'), 4), zeros(2, 2, 0, 'single')); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2495 %!assert (sum (zeros (2, 2, 0, 3, 'single'), 7), zeros(2, 2, 0, 3, 'single')); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2496 |
7112 | 2497 */ |
2498 | |
1957 | 2499 DEFUN (sumsq, args, , |
3428 | 2500 "-*- texinfo -*-\n\ |
9163
9cb0c21e97f7
Update section 17.4 (Sums and Products) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9155
diff
changeset
|
2501 @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
|
2502 @deftypefnx {Built-in Function} {} sumsq (@var{x}, @var{dim})\n\ |
3723 | 2503 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
|
2504 is omitted, it defaults to the first non-singleton dimension.\n\ |
5061 | 2505 \n\ |
2506 This function is conceptually equivalent to computing\n\ | |
10840 | 2507 \n\ |
3723 | 2508 @example\n\ |
2509 sum (x .* conj (x), dim)\n\ | |
2510 @end example\n\ | |
10840 | 2511 \n\ |
10846
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10840
diff
changeset
|
2512 @noindent\n\ |
9163
9cb0c21e97f7
Update section 17.4 (Sums and Products) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9155
diff
changeset
|
2513 but it uses less memory and avoids calling @code{conj} if @var{x} is real.\n\ |
9cb0c21e97f7
Update section 17.4 (Sums and Products) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9155
diff
changeset
|
2514 @seealso{sum}\n\ |
3428 | 2515 @end deftypefn") |
523 | 2516 { |
3723 | 2517 DATA_REDUCTION (sumsq); |
523 | 2518 } |
2519 | |
7815
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2520 /* |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2521 |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2522 %!assert(sumsq ([1, 2, 3]), 14) |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2523 %!assert(sumsq ([-1; -2; 4i]), 21); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2524 %!assert(sumsq ([1, 2, 3; 2, 3, 4; 4i, 6i, 2]), [21, 49, 29]); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2525 |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2526 %!assert(sumsq (single([1, 2, 3])), single(14)) |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2527 %!assert(sumsq (single([-1; -2; 4i])), single(21)); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2528 %!assert(sumsq (single([1, 2, 3; 2, 3, 4; 4i, 6i, 2])), single([21, 49, 29])); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2529 |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2530 %!error <Invalid call to sumsq.*> sumsq (); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2531 |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2532 %!assert (sumsq ([1, 2; 3, 4], 1), [10, 20]); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2533 %!assert (sumsq ([1, 2; 3, 4], 2), [5; 25]); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2534 |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2535 %!assert (sumsq (single([1, 2; 3, 4]), 1), single([10, 20])); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2536 %!assert (sumsq (single([1, 2; 3, 4]), 2), single([5; 25])); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2537 |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2538 */ |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2539 |
6688 | 2540 DEFUN (islogical, args, , |
3428 | 2541 "-*- texinfo -*-\n\ |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11422
diff
changeset
|
2542 @deftypefn {Built-in Function} {} islogical (@var{x})\n\ |
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11422
diff
changeset
|
2543 @deftypefnx {Built-in Function} {} isbool (@var{x})\n\ |
6688 | 2544 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
|
2545 @seealso{isfloat, isinteger, ischar, isnumeric, isa}\n\ |
3439 | 2546 @end deftypefn") |
3209 | 2547 { |
2548 octave_value retval; | |
2549 | |
2550 if (args.length () == 1) | |
3258 | 2551 retval = args(0).is_bool_type (); |
3209 | 2552 else |
5823 | 2553 print_usage (); |
3209 | 2554 |
2555 return retval; | |
2556 } | |
2557 | |
6688 | 2558 DEFALIAS (isbool, islogical); |
3209 | 2559 |
7815
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2560 /* |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2561 |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2562 %!assert (islogical(true), true) |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2563 %!assert (islogical(false), true) |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2564 %!assert (islogical([true, false]), true) |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2565 %!assert (islogical(1), false) |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2566 %!assert (islogical(1i), false) |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2567 %!assert (islogical([1,1]), false) |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2568 %!assert (islogical(single(1)), false) |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2569 %!assert (islogical(single(1i)), false) |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2570 %!assert (islogical(single([1,1])), false) |
11435
20f53b3a558f
Add tests for sparse forms of logical matrices to islogical, isnumeric.
Rik <octave@nomad.inbox5.com>
parents:
11431
diff
changeset
|
2571 %!assert (islogical(sparse ([true, false])), true) |
20f53b3a558f
Add tests for sparse forms of logical matrices to islogical, isnumeric.
Rik <octave@nomad.inbox5.com>
parents:
11431
diff
changeset
|
2572 %!assert (islogical(sparse ([1, 0])), false) |
7815
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2573 |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2574 */ |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7814
diff
changeset
|
2575 |
6223 | 2576 DEFUN (isinteger, args, , |
2577 "-*- texinfo -*-\n\ | |
6230 | 2578 @deftypefn {Built-in Function} {} isinteger (@var{x})\n\ |
6223 | 2579 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
|
2580 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
|
2581 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
|
2582 @seealso{isfloat, ischar, islogical, isnumeric, isa}\n\ |
6223 | 2583 @end deftypefn") |
2584 { | |
2585 octave_value retval; | |
2586 | |
2587 if (args.length () == 1) | |
2588 retval = args(0).is_integer_type (); | |
2589 else | |
2590 print_usage (); | |
2591 | |
2592 return retval; | |
2593 } | |
2594 | |
4028 | 2595 DEFUN (iscomplex, args, , |
3428 | 2596 "-*- texinfo -*-\n\ |
4028 | 2597 @deftypefn {Built-in Function} {} iscomplex (@var{x})\n\ |
3428 | 2598 Return true if @var{x} is a complex-valued numeric object.\n\ |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11422
diff
changeset
|
2599 @seealso{isreal, isnumeric}\n\ |
3428 | 2600 @end deftypefn") |
3186 | 2601 { |
2602 octave_value retval; | |
2603 | |
2604 if (args.length () == 1) | |
3258 | 2605 retval = args(0).is_complex_type (); |
3186 | 2606 else |
5823 | 2607 print_usage (); |
3186 | 2608 |
2609 return retval; | |
2610 } | |
2611 | |
7576 | 2612 DEFUN (isfloat, args, , |
2613 "-*- texinfo -*-\n\ | |
2614 @deftypefn {Built-in Function} {} isfloat (@var{x})\n\ | |
2615 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
|
2616 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
|
2617 @seealso{isinteger, ischar, islogical, isnumeric, isa}\n\ |
7576 | 2618 @end deftypefn") |
2619 { | |
2620 octave_value retval; | |
2621 | |
2622 if (args.length () == 1) | |
2623 retval = args(0).is_float_type (); | |
2624 else | |
2625 print_usage (); | |
2626 | |
2627 return retval; | |
2628 } | |
2629 | |
5775 | 2630 // FIXME -- perhaps this should be implemented with an |
5476 | 2631 // octave_value member function? |
2632 | |
2633 DEFUN (complex, args, , | |
2634 "-*- texinfo -*-\n\ | |
9309
fb8b8589dd46
Expand documentation for 'complex' function
Rik <rdrider0-list@yahoo.com>
parents:
9308
diff
changeset
|
2635 @deftypefn {Built-in Function} {} complex (@var{x})\n\ |
5476 | 2636 @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
|
2637 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
|
2638 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
|
2639 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
|
2640 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
|
2641 For example:\n\ |
fb8b8589dd46
Expand documentation for 'complex' function
Rik <rdrider0-list@yahoo.com>
parents:
9308
diff
changeset
|
2642 \n\ |
fb8b8589dd46
Expand documentation for 'complex' function
Rik <rdrider0-list@yahoo.com>
parents:
9308
diff
changeset
|
2643 @example\n\ |
9758
09da0bd91412
Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents:
9736
diff
changeset
|
2644 @group\n\ |
9309
fb8b8589dd46
Expand documentation for 'complex' function
Rik <rdrider0-list@yahoo.com>
parents:
9308
diff
changeset
|
2645 complex ([1, 2], [3, 4])\n\ |
fb8b8589dd46
Expand documentation for 'complex' function
Rik <rdrider0-list@yahoo.com>
parents:
9308
diff
changeset
|
2646 @result{}\n\ |
fb8b8589dd46
Expand documentation for 'complex' function
Rik <rdrider0-list@yahoo.com>
parents:
9308
diff
changeset
|
2647 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
|
2648 @end group\n\ |
9309
fb8b8589dd46
Expand documentation for 'complex' function
Rik <rdrider0-list@yahoo.com>
parents:
9308
diff
changeset
|
2649 @end example\n\ |
fb8b8589dd46
Expand documentation for 'complex' function
Rik <rdrider0-list@yahoo.com>
parents:
9308
diff
changeset
|
2650 @seealso{real, imag, iscomplex}\n\ |
5476 | 2651 @end deftypefn") |
2652 { | |
2653 octave_value retval; | |
2654 | |
2655 int nargin = args.length (); | |
2656 | |
2657 if (nargin == 1) | |
2658 { | |
2659 octave_value arg = args(0); | |
2660 | |
2661 if (arg.is_complex_type ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2662 retval = arg; |
5476 | 2663 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2664 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2665 if (arg.is_sparse_type ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2666 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2667 SparseComplexMatrix val = arg.sparse_complex_matrix_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2668 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2669 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2670 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
|
2671 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2672 else if (arg.is_single_type ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2673 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2674 if (arg.numel () == 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2675 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2676 FloatComplex val = arg.float_complex_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2677 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2678 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2679 retval = octave_value (new octave_float_complex (val)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2680 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2681 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2682 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2683 FloatComplexNDArray val = arg.float_complex_array_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2684 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2685 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2686 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
|
2687 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2688 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2689 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2690 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2691 if (arg.numel () == 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2692 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2693 Complex val = arg.complex_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2694 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2695 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2696 retval = octave_value (new octave_complex (val)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2697 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2698 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2699 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2700 ComplexNDArray val = arg.complex_array_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2701 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2702 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2703 retval = octave_value (new octave_complex_matrix (val)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2704 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2705 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2706 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2707 if (error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2708 error ("complex: invalid conversion"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2709 } |
5476 | 2710 } |
2711 else if (nargin == 2) | |
2712 { | |
2713 octave_value re = args(0); | |
2714 octave_value im = args(1); | |
2715 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7743
diff
changeset
|
2716 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
|
2717 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2718 const SparseMatrix re_val = re.sparse_matrix_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2719 const SparseMatrix im_val = im.sparse_matrix_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2720 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2721 if (!error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2722 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2723 if (re.numel () == 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2724 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2725 SparseComplexMatrix result; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2726 if (re_val.nnz () == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2727 result = Complex(0, 1) * SparseComplexMatrix (im_val); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2728 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2729 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2730 result = SparseComplexMatrix (im_val.dims (), re_val (0)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2731 octave_idx_type nr = im_val.rows (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2732 octave_idx_type nc = im_val.cols (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2733 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2734 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
|
2735 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2736 octave_idx_type off = j * nr; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
2737 for (octave_idx_type i = im_val.cidx(j); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2738 i < im_val.cidx(j + 1); i++) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
2739 result.data (im_val.ridx(i) + off) = |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
2740 result.data (im_val.ridx(i) + off) + |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2741 Complex (0, im_val.data (i)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2742 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2743 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2744 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
|
2745 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2746 else if (im.numel () == 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2747 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2748 SparseComplexMatrix result; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2749 if (im_val.nnz () == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2750 result = SparseComplexMatrix (re_val); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2751 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2752 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2753 result = SparseComplexMatrix (re_val.rows(), re_val.cols(), Complex(0, im_val (0))); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2754 octave_idx_type nr = re_val.rows (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2755 octave_idx_type nc = re_val.cols (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2756 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2757 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
|
2758 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2759 octave_idx_type off = j * nr; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
2760 for (octave_idx_type i = re_val.cidx(j); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2761 i < re_val.cidx(j + 1); i++) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
2762 result.data (re_val.ridx(i) + off) = |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
2763 result.data (re_val.ridx(i) + off) + |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2764 re_val.data (i); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2765 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2766 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2767 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
|
2768 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2769 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2770 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2771 if (re_val.dims () == im_val.dims ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2772 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
2773 SparseComplexMatrix result = SparseComplexMatrix(re_val) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2774 + Complex(0, 1) * SparseComplexMatrix (im_val); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2775 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
|
2776 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2777 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2778 error ("complex: dimension mismatch"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2779 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2780 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2781 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7743
diff
changeset
|
2782 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
|
2783 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2784 if (re.numel () == 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2785 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2786 float re_val = re.float_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2787 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2788 if (im.numel () == 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2789 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2790 float im_val = im.double_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2791 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2792 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2793 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
|
2794 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2795 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2796 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2797 const FloatNDArray im_val = im.float_array_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2798 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2799 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2800 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2801 FloatComplexNDArray result (im_val.dims (), FloatComplex ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2802 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2803 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
|
2804 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
|
2805 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2806 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
|
2807 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2808 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2809 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2810 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2811 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2812 const FloatNDArray re_val = re.float_array_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2813 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2814 if (im.numel () == 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2815 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2816 float im_val = im.float_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2817 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2818 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2819 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2820 FloatComplexNDArray result (re_val.dims (), FloatComplex ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2821 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2822 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
|
2823 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
|
2824 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2825 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
|
2826 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2827 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2828 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2829 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2830 const FloatNDArray im_val = im.float_array_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2831 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2832 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2833 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2834 if (re_val.dims () == im_val.dims ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2835 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2836 FloatComplexNDArray result (re_val.dims (), FloatComplex ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2837 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2838 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
|
2839 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
|
2840 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2841 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
|
2842 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2843 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2844 error ("complex: dimension mismatch"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2845 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2846 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2847 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2848 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7743
diff
changeset
|
2849 else if (re.numel () == 1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2850 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2851 double re_val = re.double_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2852 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2853 if (im.numel () == 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2854 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2855 double im_val = im.double_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2856 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2857 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2858 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
|
2859 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2860 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2861 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2862 const NDArray im_val = im.array_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2863 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2864 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2865 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2866 ComplexNDArray result (im_val.dims (), Complex ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2867 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2868 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
|
2869 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
|
2870 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2871 retval = octave_value (new octave_complex_matrix (result)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2872 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2873 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2874 } |
5476 | 2875 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2876 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2877 const NDArray re_val = re.array_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2878 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2879 if (im.numel () == 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2880 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2881 double im_val = im.double_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2882 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2883 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2884 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2885 ComplexNDArray result (re_val.dims (), Complex ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2886 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2887 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
|
2888 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
|
2889 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2890 retval = octave_value (new octave_complex_matrix (result)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2891 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2892 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2893 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2894 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2895 const NDArray im_val = im.array_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2896 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2897 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2898 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2899 if (re_val.dims () == im_val.dims ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2900 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2901 ComplexNDArray result (re_val.dims (), Complex ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2902 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2903 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
|
2904 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
|
2905 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2906 retval = octave_value (new octave_complex_matrix (result)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2907 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2908 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2909 error ("complex: dimension mismatch"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2910 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2911 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2912 } |
5476 | 2913 |
2914 if (error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
2915 error ("complex: invalid conversion"); |
5476 | 2916 } |
2917 else | |
5823 | 2918 print_usage (); |
5476 | 2919 |
2920 return retval; | |
2921 } | |
2922 | |
3258 | 2923 DEFUN (isreal, args, , |
3428 | 2924 "-*- texinfo -*-\n\ |
2925 @deftypefn {Built-in Function} {} isreal (@var{x})\n\ | |
10291
fc879f361bda
make isreal matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10290
diff
changeset
|
2926 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
|
2927 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
|
2928 matrices.\n\ |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11422
diff
changeset
|
2929 @seealso{iscomplex, isnumeric}\n\ |
3428 | 2930 @end deftypefn") |
3258 | 2931 { |
2932 octave_value retval; | |
2933 | |
2934 if (args.length () == 1) | |
2935 retval = args(0).is_real_type (); | |
2936 else | |
5823 | 2937 print_usage (); |
3258 | 2938 |
2939 return retval; | |
2940 } | |
2941 | |
3202 | 2942 DEFUN (isempty, args, , |
3373 | 2943 "-*- texinfo -*-\n\ |
2944 @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
|
2945 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
|
2946 zero). Otherwise, return false.\n\ |
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11422
diff
changeset
|
2947 @seealso{isnull}\n\ |
3373 | 2948 @end deftypefn") |
3202 | 2949 { |
4233 | 2950 octave_value retval = false; |
3202 | 2951 |
2952 if (args.length () == 1) | |
4559 | 2953 retval = args(0).is_empty (); |
3202 | 2954 else |
5823 | 2955 print_usage (); |
3202 | 2956 |
2957 return retval; | |
2958 } | |
2959 | |
3206 | 2960 DEFUN (isnumeric, args, , |
3428 | 2961 "-*- texinfo -*-\n\ |
2962 @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
|
2963 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
|
2964 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
|
2965 numeric.\n\ |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11422
diff
changeset
|
2966 @seealso{isinteger, isfloat, isreal, iscomplex, islogical, ischar, iscell, isstruct}\n\ |
3428 | 2967 @end deftypefn") |
3206 | 2968 { |
2969 octave_value retval; | |
2970 | |
2971 if (args.length () == 1) | |
3258 | 2972 retval = args(0).is_numeric_type (); |
3206 | 2973 else |
5823 | 2974 print_usage (); |
3206 | 2975 |
2976 return retval; | |
2977 } | |
2978 | |
11435
20f53b3a558f
Add tests for sparse forms of logical matrices to islogical, isnumeric.
Rik <octave@nomad.inbox5.com>
parents:
11431
diff
changeset
|
2979 /* |
20f53b3a558f
Add tests for sparse forms of logical matrices to islogical, isnumeric.
Rik <octave@nomad.inbox5.com>
parents:
11431
diff
changeset
|
2980 |
20f53b3a558f
Add tests for sparse forms of logical matrices to islogical, isnumeric.
Rik <octave@nomad.inbox5.com>
parents:
11431
diff
changeset
|
2981 %!assert (isnumeric(1), true) |
20f53b3a558f
Add tests for sparse forms of logical matrices to islogical, isnumeric.
Rik <octave@nomad.inbox5.com>
parents:
11431
diff
changeset
|
2982 %!assert (isnumeric(1i), true) |
20f53b3a558f
Add tests for sparse forms of logical matrices to islogical, isnumeric.
Rik <octave@nomad.inbox5.com>
parents:
11431
diff
changeset
|
2983 %!assert (isnumeric([1,1]), true) |
20f53b3a558f
Add tests for sparse forms of logical matrices to islogical, isnumeric.
Rik <octave@nomad.inbox5.com>
parents:
11431
diff
changeset
|
2984 %!assert (isnumeric(single(1)), true) |
20f53b3a558f
Add tests for sparse forms of logical matrices to islogical, isnumeric.
Rik <octave@nomad.inbox5.com>
parents:
11431
diff
changeset
|
2985 %!assert (isnumeric(single(1i)), true) |
20f53b3a558f
Add tests for sparse forms of logical matrices to islogical, isnumeric.
Rik <octave@nomad.inbox5.com>
parents:
11431
diff
changeset
|
2986 %!assert (isnumeric(single([1,1])), true) |
20f53b3a558f
Add tests for sparse forms of logical matrices to islogical, isnumeric.
Rik <octave@nomad.inbox5.com>
parents:
11431
diff
changeset
|
2987 %!assert (isnumeric(int8(1)), true) |
20f53b3a558f
Add tests for sparse forms of logical matrices to islogical, isnumeric.
Rik <octave@nomad.inbox5.com>
parents:
11431
diff
changeset
|
2988 %!assert (isnumeric(uint8([1,1])), true) |
20f53b3a558f
Add tests for sparse forms of logical matrices to islogical, isnumeric.
Rik <octave@nomad.inbox5.com>
parents:
11431
diff
changeset
|
2989 %!assert (isnumeric("Hello World"), false) |
20f53b3a558f
Add tests for sparse forms of logical matrices to islogical, isnumeric.
Rik <octave@nomad.inbox5.com>
parents:
11431
diff
changeset
|
2990 %!assert (isnumeric(true), false) |
20f53b3a558f
Add tests for sparse forms of logical matrices to islogical, isnumeric.
Rik <octave@nomad.inbox5.com>
parents:
11431
diff
changeset
|
2991 %!assert (isnumeric(false), false) |
20f53b3a558f
Add tests for sparse forms of logical matrices to islogical, isnumeric.
Rik <octave@nomad.inbox5.com>
parents:
11431
diff
changeset
|
2992 %!assert (isnumeric([true, false]), false) |
20f53b3a558f
Add tests for sparse forms of logical matrices to islogical, isnumeric.
Rik <octave@nomad.inbox5.com>
parents:
11431
diff
changeset
|
2993 %!assert (isnumeric(sparse ([true, false])), false) |
20f53b3a558f
Add tests for sparse forms of logical matrices to islogical, isnumeric.
Rik <octave@nomad.inbox5.com>
parents:
11431
diff
changeset
|
2994 |
20f53b3a558f
Add tests for sparse forms of logical matrices to islogical, isnumeric.
Rik <octave@nomad.inbox5.com>
parents:
11431
diff
changeset
|
2995 */ |
20f53b3a558f
Add tests for sparse forms of logical matrices to islogical, isnumeric.
Rik <octave@nomad.inbox5.com>
parents:
11431
diff
changeset
|
2996 |
4028 | 2997 DEFUN (ismatrix, args, , |
3321 | 2998 "-*- texinfo -*-\n\ |
4028 | 2999 @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
|
3000 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
|
3001 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
|
3002 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
|
3003 will return true for these objects as well.\n\ |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11422
diff
changeset
|
3004 @seealso{isscalar, isvector, iscell, isstruct, issparse}\n\ |
3333 | 3005 @end deftypefn") |
3202 | 3006 { |
4233 | 3007 octave_value retval = false; |
3202 | 3008 |
3009 if (args.length () == 1) | |
3010 { | |
3011 octave_value arg = args(0); | |
3012 | |
9866
b5aa5d9ee6b9
make ismatrix consistent for empty matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
9858
diff
changeset
|
3013 retval = arg.is_matrix_type () || arg.is_scalar_type () || arg.is_range (); |
3202 | 3014 } |
3015 else | |
5823 | 3016 print_usage (); |
3202 | 3017 |
3018 return retval; | |
3019 } | |
3020 | |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3021 /* |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3022 |
9866
b5aa5d9ee6b9
make ismatrix consistent for empty matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
9858
diff
changeset
|
3023 %!assert(ismatrix ([])); |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3024 %!assert(ismatrix (1)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3025 %!assert(ismatrix ([1, 2, 3])); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3026 %!assert(ismatrix ([1, 2; 3, 4])); |
9866
b5aa5d9ee6b9
make ismatrix consistent for empty matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
9858
diff
changeset
|
3027 %!assert(ismatrix (zeros (3, 2, 4))); |
b5aa5d9ee6b9
make ismatrix consistent for empty matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
9858
diff
changeset
|
3028 |
b5aa5d9ee6b9
make ismatrix consistent for empty matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
9858
diff
changeset
|
3029 %!assert(ismatrix (single([]))); |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3030 %!assert(ismatrix (single(1))); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3031 %!assert(ismatrix (single([1, 2, 3]))); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3032 %!assert(ismatrix (single([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
|
3033 |
10024
184060864627
allow ismatrix on character matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10002
diff
changeset
|
3034 %!assert(ismatrix ("t")); |
184060864627
allow ismatrix on character matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10002
diff
changeset
|
3035 %!assert(ismatrix ("test")); |
184060864627
allow ismatrix on character matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10002
diff
changeset
|
3036 %!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
|
3037 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3038 %!test |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3039 %! s.a = 1; |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3040 %! assert(ismatrix (s), false); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3041 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3042 %!error <Invalid call to ismatrix.*> ismatrix (); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3043 %!error <Invalid call to ismatrix.*> ismatrix ([1, 2; 3, 4], 2); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3044 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3045 */ |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3046 |
3354 | 3047 static octave_value |
5747 | 3048 fill_matrix (const octave_value_list& args, int val, const char *fcn) |
523 | 3049 { |
3354 | 3050 octave_value retval; |
523 | 3051 |
3052 int nargin = args.length (); | |
3053 | |
4946 | 3054 oct_data_conv::data_type dt = oct_data_conv::dt_double; |
4481 | 3055 |
4946 | 3056 dim_vector dims (1, 1); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
3057 |
4481 | 3058 if (nargin > 0 && args(nargin-1).is_string ()) |
3059 { | |
4946 | 3060 std::string nm = args(nargin-1).string_value (); |
4481 | 3061 nargin--; |
3062 | |
4946 | 3063 dt = oct_data_conv::string_to_data_type (nm); |
3064 | |
3065 if (error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3066 return retval; |
4481 | 3067 } |
3068 | |
523 | 3069 switch (nargin) |
3070 { | |
712 | 3071 case 0: |
3072 break; | |
777 | 3073 |
610 | 3074 case 1: |
4481 | 3075 get_dimensions (args(0), fcn, dims); |
610 | 3076 break; |
777 | 3077 |
4563 | 3078 default: |
3079 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3080 dims.resize (nargin); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3081 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3082 for (int i = 0; i < nargin; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3083 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3084 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
|
3085 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3086 if (error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3087 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3088 error ("%s: expecting scalar integer arguments", fcn); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3089 break; |
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 } |
4563 | 3092 } |
3093 break; | |
4481 | 3094 } |
3095 | |
3096 if (! error_state) | |
3097 { | |
4946 | 3098 dims.chop_trailing_singletons (); |
4565 | 3099 |
4481 | 3100 check_dimensions (dims, fcn); |
3354 | 3101 |
5775 | 3102 // FIXME -- perhaps this should be made extensible by |
4946 | 3103 // using the class name to lookup a function to call to create |
3104 // the new value. | |
3105 | |
3106 // Note that automatic narrowing will handle conversion from | |
3107 // NDArray to scalar. | |
3108 | |
4481 | 3109 if (! error_state) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3110 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3111 switch (dt) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3112 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3113 case oct_data_conv::dt_int8: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3114 retval = int8NDArray (dims, val); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3115 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3116 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3117 case oct_data_conv::dt_uint8: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3118 retval = uint8NDArray (dims, val); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3119 break; |
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 case oct_data_conv::dt_int16: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3122 retval = int16NDArray (dims, val); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3123 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3124 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3125 case oct_data_conv::dt_uint16: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3126 retval = uint16NDArray (dims, val); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3127 break; |
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 case oct_data_conv::dt_int32: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3130 retval = int32NDArray (dims, val); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3131 break; |
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 case oct_data_conv::dt_uint32: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3134 retval = uint32NDArray (dims, val); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3135 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3136 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3137 case oct_data_conv::dt_int64: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3138 retval = int64NDArray (dims, val); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3139 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3140 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3141 case oct_data_conv::dt_uint64: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3142 retval = uint64NDArray (dims, val); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3143 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3144 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3145 case oct_data_conv::dt_single: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3146 retval = FloatNDArray (dims, val); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3147 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3148 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3149 case oct_data_conv::dt_double: |
8972
5fa53d1b6247
more indexing optimizations
Jaroslav Hajek <highegg@gmail.com>
parents:
8947
diff
changeset
|
3150 { |
5fa53d1b6247
more indexing optimizations
Jaroslav Hajek <highegg@gmail.com>
parents:
8947
diff
changeset
|
3151 if (val == 1 && dims.length () == 2 && dims (0) == 1) |
5fa53d1b6247
more indexing optimizations
Jaroslav Hajek <highegg@gmail.com>
parents:
8947
diff
changeset
|
3152 retval = Range (1.0, 0.0, dims (1)); // packed form |
5fa53d1b6247
more indexing optimizations
Jaroslav Hajek <highegg@gmail.com>
parents:
8947
diff
changeset
|
3153 else |
5fa53d1b6247
more indexing optimizations
Jaroslav Hajek <highegg@gmail.com>
parents:
8947
diff
changeset
|
3154 retval = NDArray (dims, val); |
5fa53d1b6247
more indexing optimizations
Jaroslav Hajek <highegg@gmail.com>
parents:
8947
diff
changeset
|
3155 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3156 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3157 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3158 case oct_data_conv::dt_logical: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3159 retval = boolNDArray (dims, val); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3160 break; |
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 default: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3163 error ("%s: invalid class name", fcn); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3164 break; |
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 } |
523 | 3167 } |
3168 | |
3169 return retval; | |
3170 } | |
3171 | |
5747 | 3172 static octave_value |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
3173 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
|
3174 const char *fcn) |
7795
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3175 { |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3176 octave_value retval; |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3177 |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3178 int nargin = args.length (); |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3179 |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3180 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
|
3181 |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3182 dim_vector dims (1, 1); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
3183 |
7795
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3184 if (nargin > 0 && args(nargin-1).is_string ()) |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3185 { |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3186 std::string nm = args(nargin-1).string_value (); |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3187 nargin--; |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3188 |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3189 dt = oct_data_conv::string_to_data_type (nm); |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3190 |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3191 if (error_state) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3192 return retval; |
7795
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3193 } |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3194 |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3195 switch (nargin) |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3196 { |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3197 case 0: |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3198 break; |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3199 |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3200 case 1: |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3201 get_dimensions (args(0), fcn, dims); |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3202 break; |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3203 |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3204 default: |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3205 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3206 dims.resize (nargin); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3207 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3208 for (int i = 0; i < nargin; i++) |
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 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
|
3211 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3212 if (error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3213 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3214 error ("%s: expecting scalar integer arguments", fcn); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3215 break; |
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 } |
7795
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3218 } |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3219 break; |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3220 } |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3221 |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3222 if (! error_state) |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3223 { |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3224 dims.chop_trailing_singletons (); |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3225 |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3226 check_dimensions (dims, fcn); |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3227 |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3228 // Note that automatic narrowing will handle conversion from |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3229 // NDArray to scalar. |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3230 |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3231 if (! error_state) |
10315
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 switch (dt) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3234 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3235 case oct_data_conv::dt_single: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3236 retval = FloatNDArray (dims, fval); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3237 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3238 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3239 case oct_data_conv::dt_double: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3240 retval = NDArray (dims, val); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3241 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3242 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3243 default: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3244 error ("%s: invalid class name", fcn); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3245 break; |
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 } |
7795
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3248 } |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3249 |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3250 return retval; |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3251 } |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3252 |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3253 static octave_value |
5747 | 3254 fill_matrix (const octave_value_list& args, double val, const char *fcn) |
3255 { | |
3256 octave_value retval; | |
3257 | |
3258 int nargin = args.length (); | |
3259 | |
3260 oct_data_conv::data_type dt = oct_data_conv::dt_double; | |
3261 | |
3262 dim_vector dims (1, 1); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
3263 |
5747 | 3264 if (nargin > 0 && args(nargin-1).is_string ()) |
3265 { | |
3266 std::string nm = args(nargin-1).string_value (); | |
3267 nargin--; | |
3268 | |
3269 dt = oct_data_conv::string_to_data_type (nm); | |
3270 | |
3271 if (error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3272 return retval; |
5747 | 3273 } |
3274 | |
3275 switch (nargin) | |
3276 { | |
3277 case 0: | |
3278 break; | |
3279 | |
3280 case 1: | |
3281 get_dimensions (args(0), fcn, dims); | |
3282 break; | |
3283 | |
3284 default: | |
3285 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3286 dims.resize (nargin); |
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 (int i = 0; i < nargin; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3289 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3290 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
|
3291 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3292 if (error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3293 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3294 error ("%s: expecting scalar integer arguments", fcn); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3295 break; |
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 } |
5747 | 3298 } |
3299 break; | |
3300 } | |
3301 | |
3302 if (! error_state) | |
3303 { | |
3304 dims.chop_trailing_singletons (); | |
3305 | |
3306 check_dimensions (dims, fcn); | |
3307 | |
3308 // Note that automatic narrowing will handle conversion from | |
3309 // NDArray to scalar. | |
3310 | |
3311 if (! error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3312 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3313 switch (dt) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3314 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3315 case oct_data_conv::dt_single: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3316 retval = FloatNDArray (dims, static_cast <float> (val)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3317 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3318 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3319 case oct_data_conv::dt_double: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3320 retval = NDArray (dims, val); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3321 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3322 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3323 default: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3324 error ("%s: invalid class name", fcn); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3325 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3326 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3327 } |
5747 | 3328 } |
3329 | |
3330 return retval; | |
3331 } | |
3332 | |
3333 static octave_value | |
3334 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
|
3335 const char *fcn) |
5747 | 3336 { |
3337 octave_value retval; | |
3338 | |
3339 int nargin = args.length (); | |
3340 | |
3341 oct_data_conv::data_type dt = oct_data_conv::dt_double; | |
3342 | |
3343 dim_vector dims (1, 1); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
3344 |
5747 | 3345 if (nargin > 0 && args(nargin-1).is_string ()) |
3346 { | |
3347 std::string nm = args(nargin-1).string_value (); | |
3348 nargin--; | |
3349 | |
3350 dt = oct_data_conv::string_to_data_type (nm); | |
3351 | |
3352 if (error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3353 return retval; |
5747 | 3354 } |
3355 | |
3356 switch (nargin) | |
3357 { | |
3358 case 0: | |
3359 break; | |
3360 | |
3361 case 1: | |
3362 get_dimensions (args(0), fcn, dims); | |
3363 break; | |
3364 | |
3365 default: | |
3366 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3367 dims.resize (nargin); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3368 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3369 for (int i = 0; i < nargin; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3370 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3371 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
|
3372 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3373 if (error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3374 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3375 error ("%s: expecting scalar integer arguments", fcn); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3376 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3377 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3378 } |
5747 | 3379 } |
3380 break; | |
3381 } | |
3382 | |
3383 if (! error_state) | |
3384 { | |
3385 dims.chop_trailing_singletons (); | |
3386 | |
3387 check_dimensions (dims, fcn); | |
3388 | |
3389 // Note that automatic narrowing will handle conversion from | |
3390 // NDArray to scalar. | |
3391 | |
3392 if (! error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3393 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3394 switch (dt) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3395 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3396 case oct_data_conv::dt_single: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3397 retval = FloatComplexNDArray (dims, static_cast<FloatComplex> (val)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3398 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3399 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3400 case oct_data_conv::dt_double: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3401 retval = ComplexNDArray (dims, val); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3402 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3403 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3404 default: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3405 error ("%s: invalid class name", fcn); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3406 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3407 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3408 } |
5747 | 3409 } |
3410 | |
3411 return retval; | |
3412 } | |
3413 | |
3414 static octave_value | |
3415 fill_matrix (const octave_value_list& args, bool val, const char *fcn) | |
3416 { | |
3417 octave_value retval; | |
3418 | |
3419 int nargin = args.length (); | |
3420 | |
3421 dim_vector dims (1, 1); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
3422 |
5747 | 3423 switch (nargin) |
3424 { | |
3425 case 0: | |
3426 break; | |
3427 | |
3428 case 1: | |
3429 get_dimensions (args(0), fcn, dims); | |
3430 break; | |
3431 | |
3432 default: | |
3433 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3434 dims.resize (nargin); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3435 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3436 for (int i = 0; i < nargin; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3437 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3438 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
|
3439 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3440 if (error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3441 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3442 error ("%s: expecting scalar integer arguments", fcn); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3443 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3444 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3445 } |
5747 | 3446 } |
3447 break; | |
3448 } | |
3449 | |
3450 if (! error_state) | |
3451 { | |
3452 dims.chop_trailing_singletons (); | |
3453 | |
3454 check_dimensions (dims, fcn); | |
3455 | |
3456 // Note that automatic narrowing will handle conversion from | |
3457 // NDArray to scalar. | |
3458 | |
3459 if (! error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3460 retval = boolNDArray (dims, val); |
5747 | 3461 } |
3462 | |
3463 return retval; | |
3464 } | |
3465 | |
3354 | 3466 DEFUN (ones, args, , |
3369 | 3467 "-*- texinfo -*-\n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
3468 @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
|
3469 @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
|
3470 @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
|
3471 @deftypefnx {Built-in Function} {} ones ([@var{m} @var{n} @dots{}])\n\ |
4948 | 3472 @deftypefnx {Built-in Function} {} ones (@dots{}, @var{class})\n\ |
4481 | 3473 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
|
3474 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
|
3475 @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
|
3476 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
|
3477 the given dimensions.\n\ |
3369 | 3478 \n\ |
3479 If you need to create a matrix whose values are all the same, you should\n\ | |
3480 use an expression like\n\ | |
3481 \n\ | |
3482 @example\n\ | |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
3483 val_matrix = val * ones (m, n)\n\ |
3369 | 3484 @end example\n\ |
4945 | 3485 \n\ |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
3486 The optional argument @var{class} specifies the class of the return array\n\ |
10840 | 3487 and defaults to double. For example:\n\ |
4945 | 3488 \n\ |
3489 @example\n\ | |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
3490 val = ones (m,n, \"uint8\")\n\ |
4945 | 3491 @end example\n\ |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
3492 @seealso{zeros}\n\ |
3369 | 3493 @end deftypefn") |
523 | 3494 { |
5747 | 3495 return fill_matrix (args, 1, "ones"); |
523 | 3496 } |
3497 | |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3498 /* |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3499 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3500 %!assert(ones (3), [1, 1, 1; 1, 1, 1; 1, 1, 1]); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3501 %!assert(ones (2, 3), [1, 1, 1; 1, 1, 1]); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3502 %!assert(ones (3, 2), [1, 1; 1, 1; 1, 1]); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3503 %!assert(size (ones (3, 4, 5)), [3, 4, 5]); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3504 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3505 %!assert(ones (3,'single'), single([1, 1, 1; 1, 1, 1; 1, 1, 1])); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3506 %!assert(ones (2, 3,'single'), single([1, 1, 1; 1, 1, 1])); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3507 %!assert(ones (3, 2,'single'), single([1, 1; 1, 1; 1, 1])); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3508 %!assert(size (ones (3, 4, 5, 'single')), [3, 4, 5]); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3509 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3510 %!assert(ones (3,'int8'), int8([1, 1, 1; 1, 1, 1; 1, 1, 1])); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3511 %!assert(ones (2, 3,'int8'), int8([1, 1, 1; 1, 1, 1])); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3512 %!assert(ones (3, 2,'int8'), int8([1, 1; 1, 1; 1, 1])); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3513 %!assert(size (ones (3, 4, 5, 'int8')), [3, 4, 5]); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3514 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3515 */ |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3516 |
3354 | 3517 DEFUN (zeros, args, , |
3369 | 3518 "-*- texinfo -*-\n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
3519 @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
|
3520 @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
|
3521 @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
|
3522 @deftypefnx {Built-in Function} {} zeros ([@var{m} @var{n} @dots{}])\n\ |
4948 | 3523 @deftypefnx {Built-in Function} {} zeros (@dots{}, @var{class})\n\ |
4481 | 3524 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
|
3525 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
|
3526 @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
|
3527 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
|
3528 the given dimensions.\n\ |
4945 | 3529 \n\ |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
3530 The optional argument @var{class} specifies the class of the return array\n\ |
10840 | 3531 and defaults to double. For example:\n\ |
4945 | 3532 \n\ |
3533 @example\n\ | |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
3534 val = zeros (m,n, \"uint8\")\n\ |
4945 | 3535 @end example\n\ |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
3536 @seealso{ones}\n\ |
3369 | 3537 @end deftypefn") |
523 | 3538 { |
5747 | 3539 return fill_matrix (args, 0, "zeros"); |
3540 } | |
3541 | |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3542 /* |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3543 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3544 %!assert(zeros (3), [0, 0, 0; 0, 0, 0; 0, 0, 0]); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3545 %!assert(zeros (2, 3), [0, 0, 0; 0, 0, 0]); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3546 %!assert(zeros (3, 2), [0, 0; 0, 0; 0, 0]); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3547 %!assert(size (zeros (3, 4, 5)), [3, 4, 5]); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3548 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3549 %!assert(zeros (3,'single'), single([0, 0, 0; 0, 0, 0; 0, 0, 0])); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3550 %!assert(zeros (2, 3,'single'), single([0, 0, 0; 0, 0, 0])); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3551 %!assert(zeros (3, 2,'single'), single([0, 0; 0, 0; 0, 0])); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3552 %!assert(size (zeros (3, 4, 5, 'single')), [3, 4, 5]); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3553 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3554 %!assert(zeros (3,'int8'), int8([0, 0, 0; 0, 0, 0; 0, 0, 0])); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3555 %!assert(zeros (2, 3,'int8'), int8([0, 0, 0; 0, 0, 0])); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3556 %!assert(zeros (3, 2,'int8'), int8([0, 0; 0, 0; 0, 0])); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3557 %!assert(size (zeros (3, 4, 5, 'int8')), [3, 4, 5]); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3558 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3559 */ |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3560 |
5747 | 3561 DEFUN (Inf, args, , |
3562 "-*- texinfo -*-\n\ | |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
3563 @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
|
3564 @deftypefnx {Built-in Function} {} Inf (@var{n})\n\ |
5747 | 3565 @deftypefnx {Built-in Function} {} Inf (@var{n}, @var{m})\n\ |
3566 @deftypefnx {Built-in Function} {} Inf (@var{n}, @var{m}, @var{k}, @dots{})\n\ | |
3567 @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
|
3568 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
|
3569 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
|
3570 \n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
3571 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
|
3572 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
|
3573 produce infinity are division by zero and overflow.\n\ |
10840 | 3574 \n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
3575 @example\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
3576 @group\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
3577 [1/0 e^800]\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
3578 @result{}\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
3579 Inf Inf\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
3580 @end group\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
3581 @end example\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
3582 \n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
3583 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
|
3584 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
|
3585 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
|
3586 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
|
3587 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
|
3588 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
|
3589 either \"double\" or \"single\".\n\ |
9308
f2bf62f62286
Update documentation for NA and isna functions
Rik <rdrider0-list@yahoo.com>
parents:
9198
diff
changeset
|
3590 @seealso{isinf}\n\ |
5747 | 3591 @end deftypefn") |
3592 { | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
3593 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
|
3594 lo_ieee_float_inf_value (), "Inf"); |
5747 | 3595 } |
3596 | |
3597 DEFALIAS (inf, Inf); | |
3598 | |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3599 /* |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3600 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3601 %!assert(inf (3), [Inf, Inf, Inf; Inf, Inf, Inf; Inf, Inf, Inf]); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3602 %!assert(inf (2, 3), [Inf, Inf, Inf; Inf, Inf, Inf]); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3603 %!assert(inf (3, 2), [Inf, Inf; Inf, Inf; Inf, Inf]); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3604 %!assert(size (inf (3, 4, 5)), [3, 4, 5]); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3605 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3606 %!assert(inf (3,'single'), single([Inf, Inf, Inf; Inf, Inf, Inf; Inf, Inf, Inf])); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3607 %!assert(inf (2, 3,'single'), single([Inf, Inf, Inf; Inf, Inf, Inf])); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3608 %!assert(inf (3, 2,'single'), single([Inf, Inf; Inf, Inf; Inf, Inf])); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3609 %!assert(size (inf (3, 4, 5, 'single')), [3, 4, 5]); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3610 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3611 %!error(inf (3,'int8')); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3612 %!error(inf (2, 3,'int8')); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3613 %!error(inf (3, 2,'int8')); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3614 %!error(inf (3, 4, 5, 'int8')); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3615 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3616 */ |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3617 |
5747 | 3618 DEFUN (NaN, args, , |
3619 "-*- texinfo -*-\n\ | |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
3620 @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
|
3621 @deftypefnx {Built-in Function} {} NaN (@var{n})\n\ |
5747 | 3622 @deftypefnx {Built-in Function} {} NaN (@var{n}, @var{m})\n\ |
3623 @deftypefnx {Built-in Function} {} NaN (@var{n}, @var{m}, @var{k}, @dots{})\n\ | |
3624 @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
|
3625 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
|
3626 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
|
3627 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
|
3628 result. Common operations which produce a NaN are arithmetic with infinity\n\ |
5747 | 3629 @tex\n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
3630 ($\\infty - \\infty$), zero divided by zero ($0/0$),\n\ |
5747 | 3631 @end tex\n\ |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
8487
diff
changeset
|
3632 @ifnottex\n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
3633 (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
|
3634 @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
|
3635 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
|
3636 \n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
3637 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
|
3638 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
|
3639 find NaN values, use the @code{isnan} function.\n\ |
5747 | 3640 \n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
3641 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
|
3642 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
|
3643 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
|
3644 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
|
3645 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
|
3646 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
|
3647 either \"double\" or \"single\".\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
3648 @seealso{isnan}\n\ |
5747 | 3649 @end deftypefn") |
3650 { | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
3651 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
|
3652 lo_ieee_float_nan_value (), "NaN"); |
5747 | 3653 } |
3654 | |
3655 DEFALIAS (nan, NaN); | |
3656 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
3657 /* |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3658 %!assert(NaN (3), [NaN, NaN, NaN; NaN, NaN, NaN; NaN, NaN, NaN]); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3659 %!assert(NaN (2, 3), [NaN, NaN, NaN; NaN, NaN, NaN]); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3660 %!assert(NaN (3, 2), [NaN, NaN; NaN, NaN; NaN, NaN]); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3661 %!assert(size (NaN (3, 4, 5)), [3, 4, 5]); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3662 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3663 %!assert(NaN (3,'single'), single([NaN, NaN, NaN; NaN, NaN, NaN; NaN, NaN, NaN])); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3664 %!assert(NaN (2, 3,'single'), single([NaN, NaN, NaN; NaN, NaN, NaN])); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3665 %!assert(NaN (3, 2,'single'), single([NaN, NaN; NaN, NaN; NaN, NaN])); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3666 %!assert(size (NaN (3, 4, 5, 'single')), [3, 4, 5]); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3667 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3668 %!error(NaN (3,'int8')); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3669 %!error(NaN (2, 3,'int8')); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3670 %!error(NaN (3, 2,'int8')); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3671 %!error(NaN (3, 4, 5, 'int8')); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3672 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3673 */ |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
3674 |
5747 | 3675 DEFUN (e, args, , |
3676 "-*- texinfo -*-\n\ | |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
3677 @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
|
3678 @deftypefnx {Built-in Function} {} e (@var{n})\n\ |
5747 | 3679 @deftypefnx {Built-in Function} {} e (@var{n}, @var{m})\n\ |
3680 @deftypefnx {Built-in Function} {} e (@var{n}, @var{m}, @var{k}, @dots{})\n\ | |
3681 @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
|
3682 Return a scalar, matrix, or N-dimensional array whose elements are all equal\n\ |
5747 | 3683 to the base of natural logarithms. The constant\n\ |
3684 @tex\n\ | |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
3685 $e$ satisfies the equation $\\log (e) = 1$.\n\ |
5747 | 3686 @end tex\n\ |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
8487
diff
changeset
|
3687 @ifnottex\n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
3688 @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
|
3689 @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
|
3690 \n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
3691 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
|
3692 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
|
3693 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
|
3694 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
|
3695 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
|
3696 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
|
3697 either \"double\" or \"single\".\n\ |
5747 | 3698 @end deftypefn") |
3699 { | |
3700 #if defined (M_E) | |
3701 double e_val = M_E; | |
3702 #else | |
3703 double e_val = exp (1.0); | |
3704 #endif | |
3705 | |
3706 return fill_matrix (args, e_val, "e"); | |
3707 } | |
3708 | |
3709 DEFUN (eps, args, , | |
3710 "-*- texinfo -*-\n\ | |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
3711 @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
|
3712 @deftypefnx {Built-in Function} {} eps (@var{x})\n\ |
5747 | 3713 @deftypefnx {Built-in Function} {} eps (@var{n}, @var{m})\n\ |
3714 @deftypefnx {Built-in Function} {} eps (@var{n}, @var{m}, @var{k}, @dots{})\n\ | |
3715 @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
|
3716 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
|
3717 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
|
3718 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
|
3719 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
|
3720 floating point arithmetic, @code{eps} is approximately\n\ |
5747 | 3721 @tex\n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
3722 $2.2204\\times10^{-16}$ for double precision and $1.1921\\times10^{-7}$\n\ |
5747 | 3723 @end tex\n\ |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
8487
diff
changeset
|
3724 @ifnottex\n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
3725 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
|
3726 @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
|
3727 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
|
3728 \n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
3729 When called with no arguments, return a scalar with the value\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
3730 @code{eps(1.0)}.\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
3731 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
|
3732 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
|
3733 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
|
3734 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
|
3735 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
|
3736 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
|
3737 either \"double\" or \"single\".\n\ |
5747 | 3738 @end deftypefn") |
3739 { | |
7795
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3740 int nargin = args.length (); |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3741 octave_value retval; |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3742 |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3743 if (nargin == 1 && ! args(0).is_string ()) |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3744 { |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3745 if (args(0).is_single_type ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3746 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3747 float val = args(0).float_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3748 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3749 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3750 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3751 val = ::fabsf(val); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3752 if (xisnan (val) || xisinf (val)) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
3753 retval = fill_matrix (octave_value ("single"), |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
3754 lo_ieee_nan_value (), |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3755 lo_ieee_float_nan_value (), "eps"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3756 else if (val < FLT_MIN) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
3757 retval = fill_matrix (octave_value ("single"), 0e0, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3758 powf (2.0, -149e0), "eps"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3759 else |
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 int expon; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3762 frexpf (val, &expon); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
3763 val = std::pow (static_cast <float> (2.0), |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3764 static_cast <float> (expon - 24)); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
3765 retval = fill_matrix (octave_value ("single"), DBL_EPSILON, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3766 val, "eps"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3767 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3768 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3769 } |
7795
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3770 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3771 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3772 double val = args(0).double_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3773 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3774 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3775 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3776 val = ::fabs(val); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3777 if (xisnan (val) || xisinf (val)) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
3778 retval = fill_matrix (octave_value_list (), |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
3779 lo_ieee_nan_value (), |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3780 lo_ieee_float_nan_value (), "eps"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3781 else if (val < DBL_MIN) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3782 retval = fill_matrix (octave_value_list (), |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3783 pow (2.0, -1074e0), 0e0, "eps"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3784 else |
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 int expon; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3787 frexp (val, &expon); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
3788 val = std::pow (static_cast <double> (2.0), |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3789 static_cast <double> (expon - 53)); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
3790 retval = fill_matrix (octave_value_list (), val, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3791 FLT_EPSILON, "eps"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
3792 } |
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 } |
7795
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3795 } |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3796 else |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3797 retval = fill_matrix (args, DBL_EPSILON, FLT_EPSILON, "eps"); |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3798 |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3799 return retval; |
5747 | 3800 } |
3801 | |
7795
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3802 /* |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3803 |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3804 %!assert(eps(1/2),2^(-53)) |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3805 %!assert(eps(1),2^(-52)) |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3806 %!assert(eps(2),2^(-51)) |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3807 %!assert(eps(realmax),2^971) |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3808 %!assert(eps(0),2^(-1074)) |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3809 %!assert(eps(realmin/2),2^(-1074)) |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3810 %!assert(eps(realmin/16),2^(-1074)) |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3811 %!assert(eps(Inf),NaN) |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3812 %!assert(eps(NaN),NaN) |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3813 %!assert(eps(single(1/2)),single(2^(-24))) |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3814 %!assert(eps(single(1)),single(2^(-23))) |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3815 %!assert(eps(single(2)),single(2^(-22))) |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3816 %!assert(eps(realmax('single')),single(2^104)) |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3817 %!assert(eps(single(0)),single(2^(-149))) |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3818 %!assert(eps(realmin('single')/2),single(2^(-149))) |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3819 %!assert(eps(realmin('single')/16),single(2^(-149))) |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3820 %!assert(eps(single(Inf)),single(NaN)) |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3821 %!assert(eps(single(NaN)),single(NaN)) |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3822 |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3823 */ |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3824 |
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3825 |
5747 | 3826 DEFUN (pi, args, , |
3827 "-*- texinfo -*-\n\ | |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
3828 @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
|
3829 @deftypefnx {Built-in Function} {} pi (@var{n})\n\ |
5747 | 3830 @deftypefnx {Built-in Function} {} pi (@var{n}, @var{m})\n\ |
3831 @deftypefnx {Built-in Function} {} pi (@var{n}, @var{m}, @var{k}, @dots{})\n\ | |
3832 @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
|
3833 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
|
3834 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
|
3835 @tex\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
3836 diameter($\\pi$).\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
3837 @end tex\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
3838 @ifnottex\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
3839 diameter.\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
3840 @end ifnottex\n\ |
5747 | 3841 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
|
3842 \n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
3843 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
|
3844 @tex\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
3845 $\\pi$.\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
3846 @end tex\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
3847 @ifnottex\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
3848 pi.\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
3849 @end ifnottex\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
3850 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
|
3851 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
|
3852 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
|
3853 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
|
3854 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
|
3855 either \"double\" or \"single\".\n\ |
5747 | 3856 @end deftypefn") |
3857 { | |
3858 #if defined (M_PI) | |
3859 double pi_val = M_PI; | |
3860 #else | |
3861 double pi_val = 4.0 * atan (1.0); | |
3862 #endif | |
3863 | |
3864 return fill_matrix (args, pi_val, "pi"); | |
3865 } | |
3866 | |
3867 DEFUN (realmax, args, , | |
3868 "-*- texinfo -*-\n\ | |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
3869 @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
|
3870 @deftypefnx {Built-in Function} {} realmax (@var{n})\n\ |
5747 | 3871 @deftypefnx {Built-in Function} {} realmax (@var{n}, @var{m})\n\ |
3872 @deftypefnx {Built-in Function} {} realmax (@var{n}, @var{m}, @var{k}, @dots{})\n\ | |
3873 @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
|
3874 Return a scalar, matrix or N-dimensional array whose elements are all equal\n\ |
5747 | 3875 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
|
3876 value is system dependent. On machines that support IEEE\n\ |
5747 | 3877 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
|
3878 @tex\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
3879 $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
|
3880 @end tex\n\ |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
8487
diff
changeset
|
3881 @ifnottex\n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
3882 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
|
3883 @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
|
3884 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
|
3885 \n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
3886 When called with no arguments, return a scalar with the value\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
3887 @code{realmax(\"double\")}.\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
3888 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
|
3889 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
|
3890 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
|
3891 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
|
3892 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
|
3893 either \"double\" or \"single\".\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
3894 @seealso{realmin, intmax, bitmax}\n\ |
5747 | 3895 @end deftypefn") |
3896 { | |
7795
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3897 return fill_matrix (args, DBL_MAX, FLT_MAX, "realmax"); |
5747 | 3898 } |
3899 | |
3900 DEFUN (realmin, args, , | |
3901 "-*- texinfo -*-\n\ | |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
3902 @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
|
3903 @deftypefnx {Built-in Function} {} realmin (@var{n})\n\ |
5747 | 3904 @deftypefnx {Built-in Function} {} realmin (@var{n}, @var{m})\n\ |
3905 @deftypefnx {Built-in Function} {} realmin (@var{n}, @var{m}, @var{k}, @dots{})\n\ | |
3906 @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
|
3907 Return a scalar, matrix or N-dimensional array whose elements are all equal\n\ |
5747 | 3908 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
|
3909 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
|
3910 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
|
3911 @tex\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
3912 $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
|
3913 @end tex\n\ |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
8487
diff
changeset
|
3914 @ifnottex\n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
3915 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
|
3916 @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
|
3917 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
|
3918 \n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
3919 When called with no arguments, return a scalar with the value\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
3920 @code{realmin(\"double\")}.\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
3921 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
|
3922 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
|
3923 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
|
3924 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
|
3925 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
|
3926 either \"double\" or \"single\".\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
3927 @seealso{realmax, intmin}\n\ |
5747 | 3928 @end deftypefn") |
3929 { | |
7795
df9519e9990c
Handle single precision eps values
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
3930 return fill_matrix (args, DBL_MIN, FLT_MIN, "realmin"); |
5747 | 3931 } |
3932 | |
3933 DEFUN (I, args, , | |
3934 "-*- texinfo -*-\n\ | |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
3935 @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
|
3936 @deftypefnx {Built-in Function} {} I (@var{n})\n\ |
5747 | 3937 @deftypefnx {Built-in Function} {} I (@var{n}, @var{m})\n\ |
3938 @deftypefnx {Built-in Function} {} I (@var{n}, @var{m}, @var{k}, @dots{})\n\ | |
3939 @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
|
3940 Return a scalar, matrix, or N-dimensional array whose elements are all equal\n\ |
5747 | 3941 to the pure imaginary unit, defined as\n\ |
3942 @tex\n\ | |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
3943 $\\sqrt{-1}$.\n\ |
5747 | 3944 @end tex\n\ |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
8487
diff
changeset
|
3945 @ifnottex\n\ |
9197
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
3946 @code{sqrt (-1)}.\n\ |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
8487
diff
changeset
|
3947 @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
|
3948 I, and its equivalents i, J, and j, are functions so any of the names may\n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
3949 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
|
3950 \n\ |
3c27a0340a64
Update documentation for section 17.8 (Mathematical Constants) of arith.texi
Rik <rdrider0-list@yahoo.com>
parents:
9194
diff
changeset
|
3951 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
|
3952 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
|
3953 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
|
3954 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
|
3955 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
|
3956 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
|
3957 either \"double\" or \"single\".\n\ |
5747 | 3958 @end deftypefn") |
3959 { | |
3960 return fill_matrix (args, Complex (0.0, 1.0), "I"); | |
3961 } | |
3962 | |
3963 DEFALIAS (i, I); | |
3964 DEFALIAS (J, I); | |
3965 DEFALIAS (j, I); | |
3966 | |
3967 DEFUN (NA, args, , | |
3968 "-*- texinfo -*-\n\ | |
9308
f2bf62f62286
Update documentation for NA and isna functions
Rik <rdrider0-list@yahoo.com>
parents:
9198
diff
changeset
|
3969 @deftypefn {Built-in Function} {} NA\n\ |
f2bf62f62286
Update documentation for NA and isna functions
Rik <rdrider0-list@yahoo.com>
parents:
9198
diff
changeset
|
3970 @deftypefnx {Built-in Function} {} NA (@var{n})\n\ |
5747 | 3971 @deftypefnx {Built-in Function} {} NA (@var{n}, @var{m})\n\ |
3972 @deftypefnx {Built-in Function} {} NA (@var{n}, @var{m}, @var{k}, @dots{})\n\ | |
3973 @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
|
3974 Return a scalar, matrix, or N-dimensional array whose elements are all equal\n\ |
5747 | 3975 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
|
3976 \n\ |
f2bf62f62286
Update documentation for NA and isna functions
Rik <rdrider0-list@yahoo.com>
parents:
9198
diff
changeset
|
3977 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
|
3978 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
|
3979 \n\ |
f2bf62f62286
Update documentation for NA and isna functions
Rik <rdrider0-list@yahoo.com>
parents:
9198
diff
changeset
|
3980 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
|
3981 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
|
3982 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
|
3983 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
|
3984 arguments specify additional matrix dimensions.\n\ |
f2bf62f62286
Update documentation for NA and isna functions
Rik <rdrider0-list@yahoo.com>
parents:
9198
diff
changeset
|
3985 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
|
3986 either \"double\" or \"single\".\n\ |
f2bf62f62286
Update documentation for NA and isna functions
Rik <rdrider0-list@yahoo.com>
parents:
9198
diff
changeset
|
3987 @seealso{isna}\n\ |
5747 | 3988 @end deftypefn") |
3989 { | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
3990 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
|
3991 lo_ieee_float_na_value (), "NA"); |
5747 | 3992 } |
3993 | |
7991
139f47cf17ab
Change NA value to support single to double precision conversion
David Bateman <dbateman@free.fr>
parents:
7919
diff
changeset
|
3994 /* |
139f47cf17ab
Change NA value to support single to double precision conversion
David Bateman <dbateman@free.fr>
parents:
7919
diff
changeset
|
3995 |
139f47cf17ab
Change NA value to support single to double precision conversion
David Bateman <dbateman@free.fr>
parents:
7919
diff
changeset
|
3996 %!assert(single(NA('double')),NA('single')) |
139f47cf17ab
Change NA value to support single to double precision conversion
David Bateman <dbateman@free.fr>
parents:
7919
diff
changeset
|
3997 %!assert(double(NA('single')),NA('double')) |
139f47cf17ab
Change NA value to support single to double precision conversion
David Bateman <dbateman@free.fr>
parents:
7919
diff
changeset
|
3998 |
139f47cf17ab
Change NA value to support single to double precision conversion
David Bateman <dbateman@free.fr>
parents:
7919
diff
changeset
|
3999 */ |
139f47cf17ab
Change NA value to support single to double precision conversion
David Bateman <dbateman@free.fr>
parents:
7919
diff
changeset
|
4000 |
5747 | 4001 DEFUN (false, args, , |
4002 "-*- texinfo -*-\n\ | |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
4003 @deftypefn {Built-in Function} {} false (@var{x})\n\ |
5747 | 4004 @deftypefnx {Built-in Function} {} false (@var{n}, @var{m})\n\ |
4005 @deftypefnx {Built-in Function} {} false (@var{n}, @var{m}, @var{k}, @dots{})\n\ | |
4006 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
|
4007 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
|
4008 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
|
4009 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
|
4010 given dimensions.\n\ |
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
4011 @seealso{true}\n\ |
5747 | 4012 @end deftypefn") |
4013 { | |
4014 return fill_matrix (args, false, "false"); | |
4015 } | |
4016 | |
4017 DEFUN (true, args, , | |
4018 "-*- texinfo -*-\n\ | |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
4019 @deftypefn {Built-in Function} {} true (@var{x})\n\ |
5747 | 4020 @deftypefnx {Built-in Function} {} true (@var{n}, @var{m})\n\ |
4021 @deftypefnx {Built-in Function} {} true (@var{n}, @var{m}, @var{k}, @dots{})\n\ | |
4022 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
|
4023 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
|
4024 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
|
4025 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
|
4026 given dimensions.\n\ |
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
4027 @seealso{false}\n\ |
5747 | 4028 @end deftypefn") |
4029 { | |
4030 return fill_matrix (args, true, "true"); | |
3354 | 4031 } |
523 | 4032 |
4946 | 4033 template <class MT> |
4034 octave_value | |
4035 identity_matrix (int nr, int nc) | |
4036 { | |
4037 octave_value retval; | |
4038 | |
9685 | 4039 typename MT::element_type one (1); |
4946 | 4040 |
4041 if (nr == 1 && nc == 1) | |
4042 retval = one; | |
4043 else | |
4044 { | |
4045 dim_vector dims (nr, nc); | |
4046 | |
9685 | 4047 typename MT::element_type zero (0); |
4946 | 4048 |
4049 MT m (dims, zero); | |
4050 | |
4051 if (nr > 0 && nc > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4052 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4053 int n = std::min (nr, nc); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4054 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4055 for (int i = 0; i < n; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4056 m(i,i) = one; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4057 } |
4946 | 4058 |
4059 retval = m; | |
4060 } | |
4061 | |
4062 return retval; | |
4063 } | |
4064 | |
5058 | 4065 #define INSTANTIATE_EYE(T) \ |
4066 template octave_value identity_matrix<T> (int, int) | |
4067 | |
4068 INSTANTIATE_EYE (int8NDArray); | |
4069 INSTANTIATE_EYE (uint8NDArray); | |
4070 INSTANTIATE_EYE (int16NDArray); | |
4071 INSTANTIATE_EYE (uint16NDArray); | |
4072 INSTANTIATE_EYE (int32NDArray); | |
4073 INSTANTIATE_EYE (uint32NDArray); | |
4074 INSTANTIATE_EYE (int64NDArray); | |
4075 INSTANTIATE_EYE (uint64NDArray); | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7743
diff
changeset
|
4076 INSTANTIATE_EYE (FloatNDArray); |
5058 | 4077 INSTANTIATE_EYE (NDArray); |
4078 INSTANTIATE_EYE (boolNDArray); | |
4079 | |
4945 | 4080 static octave_value |
4948 | 4081 identity_matrix (int nr, int nc, oct_data_conv::data_type dt) |
4945 | 4082 { |
4083 octave_value retval; | |
4084 | |
5775 | 4085 // FIXME -- perhaps this should be made extensible by using |
4946 | 4086 // the class name to lookup a function to call to create the new |
4087 // value. | |
4088 | |
4089 if (! error_state) | |
4090 { | |
4091 switch (dt) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4092 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4093 case oct_data_conv::dt_int8: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4094 retval = identity_matrix<int8NDArray> (nr, nc); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4095 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4096 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4097 case oct_data_conv::dt_uint8: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4098 retval = identity_matrix<uint8NDArray> (nr, nc); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4099 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4100 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4101 case oct_data_conv::dt_int16: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4102 retval = identity_matrix<int16NDArray> (nr, nc); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4103 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4104 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4105 case oct_data_conv::dt_uint16: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4106 retval = identity_matrix<uint16NDArray> (nr, nc); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4107 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4108 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4109 case oct_data_conv::dt_int32: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4110 retval = identity_matrix<int32NDArray> (nr, nc); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4111 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4112 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4113 case oct_data_conv::dt_uint32: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4114 retval = identity_matrix<uint32NDArray> (nr, nc); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4115 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4116 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4117 case oct_data_conv::dt_int64: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4118 retval = identity_matrix<int64NDArray> (nr, nc); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4119 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4120 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4121 case oct_data_conv::dt_uint64: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4122 retval = identity_matrix<uint64NDArray> (nr, nc); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4123 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4124 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4125 case oct_data_conv::dt_single: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4126 retval = FloatDiagMatrix (nr, nc, 1.0f); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4127 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4128 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4129 case oct_data_conv::dt_double: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4130 retval = DiagMatrix (nr, nc, 1.0); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4131 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4132 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4133 case oct_data_conv::dt_logical: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4134 retval = identity_matrix<boolNDArray> (nr, nc); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4135 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4136 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4137 default: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4138 error ("eye: invalid class name"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4139 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4140 } |
4945 | 4141 } |
4142 | |
4143 return retval; | |
4144 } | |
4145 | |
4946 | 4146 #undef INT_EYE_MATRIX |
4147 | |
1957 | 4148 DEFUN (eye, args, , |
3369 | 4149 "-*- texinfo -*-\n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
4150 @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
|
4151 @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
|
4152 @deftypefnx {Built-in Function} {} eye ([@var{m} @var{n}])\n\ |
4948 | 4153 @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
|
4154 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
|
4155 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
|
4156 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
|
4157 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
|
4158 @code{eye} uses the values of the elements as the number of rows and columns,\n\ |
10840 | 4159 respectively. For example:\n\ |
3369 | 4160 \n\ |
4161 @example\n\ | |
4162 @group\n\ | |
4163 eye (3)\n\ | |
4164 @result{} 1 0 0\n\ | |
4165 0 1 0\n\ | |
4166 0 0 1\n\ | |
4167 @end group\n\ | |
4168 @end example\n\ | |
4169 \n\ | |
4170 The following expressions all produce the same result:\n\ | |
4171 \n\ | |
4172 @example\n\ | |
4173 @group\n\ | |
4174 eye (2)\n\ | |
4175 @equiv{}\n\ | |
4176 eye (2, 2)\n\ | |
4177 @equiv{}\n\ | |
4178 eye (size ([1, 2; 3, 4])\n\ | |
4179 @end group\n\ | |
4180 @end example\n\ | |
4181 \n\ | |
4945 | 4182 The optional argument @var{class}, allows @code{eye} to return an array of\n\ |
4183 the specified type, like\n\ | |
4184 \n\ | |
4185 @example\n\ | |
4186 val = zeros (n,m, \"uint8\")\n\ | |
4187 @end example\n\ | |
4188 \n\ | |
6556 | 4189 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
|
4190 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
|
4191 These odd definitions are for compatibility with @sc{matlab}.\n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
4192 @seealso{speye}\n\ |
3369 | 4193 @end deftypefn") |
523 | 4194 { |
3354 | 4195 octave_value retval; |
523 | 4196 |
4948 | 4197 int nargin = args.length (); |
4945 | 4198 |
4948 | 4199 oct_data_conv::data_type dt = oct_data_conv::dt_double; |
523 | 4200 |
4945 | 4201 // Check for type information. |
4202 | |
4203 if (nargin > 0 && args(nargin-1).is_string ()) | |
4204 { | |
4948 | 4205 std::string nm = args(nargin-1).string_value (); |
4945 | 4206 nargin--; |
4948 | 4207 |
4208 dt = oct_data_conv::string_to_data_type (nm); | |
4209 | |
4210 if (error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4211 return retval; |
4945 | 4212 } |
4213 | |
523 | 4214 switch (nargin) |
4215 { | |
712 | 4216 case 0: |
4948 | 4217 retval = identity_matrix (1, 1, dt); |
712 | 4218 break; |
777 | 4219 |
610 | 4220 case 1: |
3354 | 4221 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4222 octave_idx_type nr, nc; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4223 get_dimensions (args(0), "eye", nr, nc); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4224 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4225 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4226 retval = identity_matrix (nr, nc, dt); |
3354 | 4227 } |
610 | 4228 break; |
777 | 4229 |
523 | 4230 case 2: |
3354 | 4231 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4232 octave_idx_type nr, nc; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4233 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
|
4234 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4235 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4236 retval = identity_matrix (nr, nc, dt); |
3354 | 4237 } |
523 | 4238 break; |
777 | 4239 |
523 | 4240 default: |
5823 | 4241 print_usage (); |
523 | 4242 break; |
4243 } | |
4244 | |
4245 return retval; | |
4246 } | |
4247 | |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4248 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4249 /* |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4250 |
8459
d17874a6f161
improve indexing of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8458
diff
changeset
|
4251 %!assert (full (eye(3)), [1, 0, 0; 0, 1, 0; 0, 0, 1]); |
d17874a6f161
improve indexing of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8458
diff
changeset
|
4252 %!assert (full (eye(2, 3)), [1, 0, 0; 0, 1, 0]); |
d17874a6f161
improve indexing of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8458
diff
changeset
|
4253 |
d17874a6f161
improve indexing of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8458
diff
changeset
|
4254 %!assert (full (eye(3,'single')), single([1, 0, 0; 0, 1, 0; 0, 0, 1])); |
d17874a6f161
improve indexing of diagonal & permutation matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8458
diff
changeset
|
4255 %!assert (full (eye(2, 3,'single')), single([1, 0, 0; 0, 1, 0])); |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4256 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4257 %!assert (eye(3,'int8'), int8([1, 0, 0; 0, 1, 0; 0, 0, 1])); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4258 %!assert (eye(2, 3,'int8'), int8([1, 0, 0; 0, 1, 0])); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4259 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4260 %!error <Invalid call to eye.*> eye (1, 2, 3); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4261 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4262 */ |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4263 |
9658
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4264 template <class MT> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
4265 static octave_value |
9658
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4266 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
|
4267 octave_idx_type n) |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4268 { |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4269 typedef typename MT::column_vector_type CVT; |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4270 typedef typename MT::element_type T; |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4271 |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4272 octave_value retval; |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4273 |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4274 if (base.is_scalar_type ()) |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4275 { |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4276 T bs = octave_value_extract<T> (base); |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4277 if (limit.is_scalar_type ()) |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4278 { |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4279 T ls = octave_value_extract<T> (limit); |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4280 retval = linspace (bs, ls, n); |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4281 } |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4282 else |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4283 { |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4284 CVT lv = octave_value_extract<CVT> (limit); |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4285 CVT bv (lv.length (), bs); |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4286 retval = linspace (bv, lv, n); |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4287 } |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4288 } |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4289 else |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4290 { |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4291 CVT bv = octave_value_extract<CVT> (base); |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4292 if (limit.is_scalar_type ()) |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4293 { |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4294 T ls = octave_value_extract<T> (limit); |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4295 CVT lv (bv.length (), ls); |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4296 retval = linspace (bv, lv, n); |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4297 } |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4298 else |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4299 { |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4300 CVT lv = octave_value_extract<CVT> (limit); |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4301 retval = linspace (bv, lv, n); |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4302 } |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4303 } |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4304 |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4305 return retval; |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4306 } |
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4307 |
1957 | 4308 DEFUN (linspace, args, , |
3369 | 4309 "-*- texinfo -*-\n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
4310 @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
|
4311 @deftypefnx {Built-in Function} {} linspace (@var{base}, @var{limit}, @var{n})\n\ |
3369 | 4312 Return a row vector with @var{n} linearly spaced elements between\n\ |
6630 | 4313 @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
|
4314 then the endpoints @var{base} and @var{limit} are always included in\n\ |
3369 | 4315 the range. If @var{base} is greater than @var{limit}, the elements are\n\ |
4316 stored in decreasing order. If the number of points is not specified, a\n\ | |
4317 value of 100 is used.\n\ | |
1100 | 4318 \n\ |
9658
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4319 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
|
4320 @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
|
4321 vectors, @code{linspace} returns a matrix.\n\ |
6630 | 4322 \n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
4323 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
|
4324 if fewer than two values are requested.\n\ |
3369 | 4325 @end deftypefn") |
1100 | 4326 { |
3418 | 4327 octave_value retval; |
1100 | 4328 |
4329 int nargin = args.length (); | |
4330 | |
6133 | 4331 octave_idx_type npoints = 100; |
1100 | 4332 |
1940 | 4333 if (nargin != 2 && nargin != 3) |
4334 { | |
5823 | 4335 print_usage (); |
1940 | 4336 return retval; |
4337 } | |
4338 | |
1100 | 4339 if (nargin == 3) |
6133 | 4340 npoints = args(2).idx_type_value (); |
1100 | 4341 |
4342 if (! error_state) | |
4343 { | |
3322 | 4344 octave_value arg_1 = args(0); |
4345 octave_value arg_2 = args(1); | |
1100 | 4346 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7743
diff
changeset
|
4347 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
|
4348 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4349 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
|
4350 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
|
4351 else |
9658
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4352 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
|
4353 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4354 } |
1100 | 4355 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4356 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4357 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
|
4358 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
|
4359 else |
9658
3429c956de6f
extend linspace & fix up liboctave rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
9562
diff
changeset
|
4360 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
|
4361 } |
1100 | 4362 } |
4732 | 4363 else |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11591
diff
changeset
|
4364 error ("linspace: N must be an integer"); |
1100 | 4365 |
4366 return retval; | |
4367 } | |
4368 | |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4369 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4370 /* |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4371 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4372 %!test |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4373 %! 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
|
4374 %! 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
|
4375 %! x3 = 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
|
4376 %! assert((size (x1) == [1, 100] && x1(1) == 1 && x1(100) == 2 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4377 %! && size (x2) == [1, 10] && x2(1) == 1 && x2(10) == 2 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4378 %! && size (x3) == [1, 10] && x3(1) == 1 && x3(10) == -2)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4379 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4380 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4381 % assert(linspace ([1, 2; 3, 4], 5, 6), linspace (1, 5, 6)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4382 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4383 %!error <Invalid call to linspace.*> linspace (); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4384 %!error <Invalid call to linspace.*> linspace (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
|
4385 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4386 %!test |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4387 %! fail("linspace ([1, 2; 3, 4], 5, 6)","warning"); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4388 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4389 */ |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4390 |
5775 | 4391 // FIXME -- should accept dimensions as separate args for N-d |
5734 | 4392 // arrays as well as 1-d and 2-d arrays. |
4393 | |
5731 | 4394 DEFUN (resize, args, , |
4395 "-*- texinfo -*-\n\ | |
10840 | 4396 @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
|
4397 @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
|
4398 @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
|
4399 Resize @var{x} cutting off elements as necessary.\n\ |
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
4400 \n\ |
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
4401 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
|
4402 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
|
4403 otherwise, the element is set to zero.\n\ |
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
4404 \n\ |
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
4405 In other words, the statement\n\ |
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
4406 \n\ |
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
4407 @example\n\ |
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
4408 y = resize (x, dv);\n\ |
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
4409 @end example\n\ |
6174 | 4410 \n\ |
8799
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
4411 @noindent\n\ |
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
4412 is equivalent to the following code:\n\ |
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
4413 \n\ |
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
4414 @example\n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
9041
diff
changeset
|
4415 @group\n\ |
8799
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
4416 y = zeros (dv, class (x));\n\ |
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
4417 sz = min (dv, size (x));\n\ |
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
4418 for i = 1:length (sz), idx@{i@} = 1:sz(i); endfor\n\ |
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
4419 y(idx@{:@}) = x(idx@{:@});\n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
9041
diff
changeset
|
4420 @end group\n\ |
8799
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
4421 @end example\n\ |
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
4422 \n\ |
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
4423 @noindent\n\ |
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
4424 but is performed more efficiently.\n\ |
6174 | 4425 \n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
4426 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
|
4427 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
|
4428 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
|
4429 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
|
4430 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
|
4431 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
|
4432 \n\ |
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
4433 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
|
4434 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
|
4435 Resizing an object to fewer dimensions is not possible.\n\ |
8433
3292bd1bbaa4
Cross reference between postpad and resize
Francesco Potortì <pot@gnu.org>
parents:
8429
diff
changeset
|
4436 @seealso{reshape, postpad}\n\ |
5731 | 4437 @end deftypefn") |
4438 { | |
4439 octave_value retval; | |
4440 int nargin = args.length (); | |
4441 | |
4442 if (nargin == 2) | |
4443 { | |
4444 Array<double> vec = args(1).vector_value (); | |
4445 int ndim = vec.length (); | |
4446 if (ndim == 1) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4447 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4448 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
|
4449 retval = args(0); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4450 retval = retval.resize (dim_vector (m, m), true); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4451 } |
5731 | 4452 else |
10315
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 dim_vector dv; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4455 dv.resize (ndim); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4456 for (int i = 0; i < ndim; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4457 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
|
4458 retval = args(0); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4459 retval = retval.resize (dv, true); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4460 } |
5731 | 4461 } |
8799
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
4462 else if (nargin > 2) |
5731 | 4463 { |
8799
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
4464 dim_vector dv; |
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
4465 dv.resize (nargin - 1); |
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
4466 for (octave_idx_type i = 1; i < nargin; i++) |
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
4467 dv(i-1) = static_cast<octave_idx_type> (args(i).scalar_value ()); |
5731 | 4468 if (!error_state) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4469 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4470 retval = args(0); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4471 retval = retval.resize (dv, true); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4472 } |
8799
f6dc6eb57045
improve resize & resize on assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8780
diff
changeset
|
4473 |
5731 | 4474 } |
4475 else | |
5823 | 4476 print_usage (); |
5731 | 4477 return retval; |
4478 } | |
4479 | |
5775 | 4480 // FIXME -- should use octave_idx_type for dimensions. |
5734 | 4481 |
4567 | 4482 DEFUN (reshape, args, , |
4483 "-*- texinfo -*-\n\ | |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
4484 @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
|
4485 @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
|
4486 @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
|
4487 @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
|
4488 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
|
4489 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
|
4490 matrix are accessed in column-major order (like Fortran arrays are stored).\n\ |
4567 | 4491 \n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
4492 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
|
4493 matrix.\n\ |
4567 | 4494 \n\ |
4495 @example\n\ | |
4496 @group\n\ | |
4497 reshape ([1, 2, 3, 4], 2, 2)\n\ | |
4498 @result{} 1 3\n\ | |
4499 2 4\n\ | |
4500 @end group\n\ | |
4501 @end example\n\ | |
4502 \n\ | |
4503 @noindent\n\ | |
4504 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
|
4505 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
|
4506 in the new matrix (@code{prod ([@var{m} @var{n} @dots{}])}).\n\ |
5013 | 4507 \n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
4508 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
|
4509 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
|
4510 the unspecified dimension.\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
4511 @seealso{resize}\n\ |
4567 | 4512 @end deftypefn") |
4513 { | |
4514 octave_value retval; | |
4515 | |
4516 int nargin = args.length (); | |
4517 | |
10693 | 4518 dim_vector new_dims; |
4567 | 4519 |
4520 if (nargin == 2) | |
10693 | 4521 { |
4522 Array<octave_idx_type> new_size = args(1).octave_idx_type_vector_value (); | |
4523 | |
4524 new_dims = dim_vector::alloc (new_size.length ()); | |
4525 | |
4526 for (octave_idx_type i = 0; i < new_size.length (); i++) | |
4527 { | |
4528 if (new_size(i) < 0) | |
4529 { | |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11591
diff
changeset
|
4530 error ("reshape: SIZE must be non-negative"); |
10693 | 4531 break; |
4532 } | |
4533 else | |
4534 new_dims(i) = new_size(i); | |
4535 } | |
4536 } | |
4567 | 4537 else if (nargin > 2) |
4538 { | |
10693 | 4539 new_dims = dim_vector::alloc (nargin-1); |
5013 | 4540 int empty_dim = -1; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
4541 |
4567 | 4542 for (int i = 1; i < nargin; i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4543 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4544 if (args(i).is_empty ()) |
10693 | 4545 { |
4546 if (empty_dim > 0) | |
4547 { | |
4548 error ("reshape: only a single dimension can be unknown"); | |
4549 break; | |
4550 } | |
4551 else | |
4552 { | |
4553 empty_dim = i; | |
4554 new_dims(i-1) = 1; | |
4555 } | |
4556 } | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4557 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4558 { |
10693 | 4559 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
|
4560 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4561 if (error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4562 break; |
10693 | 4563 else if (new_dims(i-1) < 0) |
4564 { | |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11591
diff
changeset
|
4565 error ("reshape: SIZE must be non-negative"); |
10693 | 4566 break; |
4567 } | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4568 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4569 } |
5013 | 4570 |
4571 if (! error_state && (empty_dim > 0)) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4572 { |
10693 | 4573 octave_idx_type nel = new_dims.numel (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4574 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4575 if (nel == 0) |
10693 | 4576 new_dims(empty_dim-1) = 0; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4577 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4578 { |
10693 | 4579 octave_idx_type a_nel = args(0).numel (); |
4580 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
|
4581 |
10693 | 4582 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
|
4583 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
|
4584 else |
10693 | 4585 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
|
4586 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4587 } |
4567 | 4588 } |
4589 else | |
4590 { | |
5823 | 4591 print_usage (); |
4567 | 4592 return retval; |
4593 } | |
4594 | |
10352 | 4595 if (! error_state) |
4596 retval = args(0).reshape (new_dims); | |
4567 | 4597 |
4598 return retval; | |
4599 } | |
4600 | |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4601 /* |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4602 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4603 %!assert(size (reshape (ones (4, 4), 2, 8)), [2, 8]) |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4604 %!assert(size (reshape (ones (4, 4), 8, 2)), [8, 2]) |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4605 %!assert(size (reshape (ones (15, 4), 1, 60)), [1, 60]) |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4606 %!assert(size (reshape (ones (15, 4), 60, 1)), [60, 1]) |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4607 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4608 %!assert(size (reshape (ones (4, 4, 'single'), 2, 8)), [2, 8]) |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4609 %!assert(size (reshape (ones (4, 4, 'single'), 8, 2)), [8, 2]) |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4610 %!assert(size (reshape (ones (15, 4, 'single'), 1, 60)), [1, 60]) |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4611 %!assert(size (reshape (ones (15, 4, 'single'), 60, 1)), [60, 1]) |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4612 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4613 %!test |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4614 %! s.a = 1; |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4615 %! fail("reshape (s, 2, 3)"); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4616 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4617 %!error <Invalid call to reshape.*> reshape (); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4618 %!error reshape (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
|
4619 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4620 */ |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4621 |
10694
d97165928d05
implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents:
10693
diff
changeset
|
4622 DEFUN (vec, args, , |
d97165928d05
implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents:
10693
diff
changeset
|
4623 "-*- texinfo -*-\n\ |
12578
f5a780d675a1
Clean up operator and function indices in documentation.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
4624 @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
|
4625 @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
|
4626 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
|
4627 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
|
4628 @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
|
4629 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
|
4630 This is equivalent to @code{shiftdim (@var{x}(:), 1-@var{dim})}.\n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
4631 @seealso{vech}\n\ |
10694
d97165928d05
implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents:
10693
diff
changeset
|
4632 @end deftypefn") |
d97165928d05
implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents:
10693
diff
changeset
|
4633 { |
d97165928d05
implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents:
10693
diff
changeset
|
4634 octave_value retval; |
11402
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
4635 int dim = 1; |
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
4636 |
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
4637 int nargin = args.length (); |
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
4638 |
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
4639 if (nargin < 1 || nargin > 2) |
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
4640 print_usage () ; |
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
4641 |
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
4642 if (! error_state && nargin == 2) |
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
4643 { |
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
4644 dim = args(1).idx_type_value (); |
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
4645 |
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
4646 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
|
4647 error ("vec: DIM must be greater than zero"); |
11402
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
4648 } |
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
4649 |
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
4650 if (! error_state) |
10694
d97165928d05
implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents:
10693
diff
changeset
|
4651 { |
d97165928d05
implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents:
10693
diff
changeset
|
4652 octave_value colon (octave_value::magic_colon_t); |
d97165928d05
implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents:
10693
diff
changeset
|
4653 octave_value arg = args(0); |
d97165928d05
implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents:
10693
diff
changeset
|
4654 retval = arg.single_subsref ("(", colon); |
11402
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
4655 |
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
4656 |
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
4657 if (! error_state && dim > 1) |
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
4658 { |
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
4659 dim_vector new_dims = dim_vector::alloc (dim); |
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
4660 |
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
4661 for (int i = 0; i < dim-1; i++) |
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
4662 new_dims(i) = 1; |
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
4663 |
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
4664 new_dims(dim-1) = retval.numel (); |
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
4665 |
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
4666 retval = retval.reshape (new_dims); |
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
4667 } |
10694
d97165928d05
implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents:
10693
diff
changeset
|
4668 } |
d97165928d05
implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents:
10693
diff
changeset
|
4669 |
d97165928d05
implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents:
10693
diff
changeset
|
4670 return retval; |
d97165928d05
implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents:
10693
diff
changeset
|
4671 } |
d97165928d05
implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents:
10693
diff
changeset
|
4672 |
d97165928d05
implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents:
10693
diff
changeset
|
4673 /* |
d97165928d05
implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents:
10693
diff
changeset
|
4674 |
d97165928d05
implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents:
10693
diff
changeset
|
4675 %!assert(vec ([1, 2; 3, 4]), [1; 3; 2; 4]) |
11402
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
4676 %!assert(vec ([1, 3, 2, 4]), [1; 3; 2; 4]); |
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
4677 %!assert(vec ([1, 2, 3, 4], 2), [1, 2, 3, 4]); |
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
4678 %!assert(vec ([1, 2; 3, 4]), vec ([1, 2; 3, 4], 1)); |
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
4679 %!assert(vec ([1, 2; 3, 4], 1), [1; 3; 2; 4]); |
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
4680 %!assert(vec ([1, 2; 3, 4], 2), [1, 3, 2, 4]); |
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
4681 %!assert(vec ([1, 3; 2, 4], 3), reshape ([1, 2, 3, 4], 1, 1, 4)); |
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
4682 %!assert(vec ([1, 3; 2, 4], 3), shiftdim (vec ([1, 3; 2, 4]), -2)); |
10694
d97165928d05
implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents:
10693
diff
changeset
|
4683 |
d97165928d05
implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents:
10693
diff
changeset
|
4684 %!error vec (); |
11402
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
4685 %!error vec (1, 2, 3); |
a9a3ee461b83
Add second argument to Fvec
Judd Storrs <jstorrs@gmail.com>
parents:
11357
diff
changeset
|
4686 %!error vec ([1, 2; 3, 4], 0); |
10694
d97165928d05
implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents:
10693
diff
changeset
|
4687 |
d97165928d05
implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents:
10693
diff
changeset
|
4688 */ |
d97165928d05
implement built-in vec()
Jaroslav Hajek <highegg@gmail.com>
parents:
10693
diff
changeset
|
4689 |
4532 | 4690 DEFUN (squeeze, args, , |
4691 "-*- texinfo -*-\n\ | |
4692 @deftypefn {Built-in Function} {} squeeze (@var{x})\n\ | |
4693 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
|
4694 Note that for compatibility with @sc{matlab}, all objects have\n\ |
7007 | 4695 a minimum of two dimensions and row vectors are left unchanged.\n\ |
4532 | 4696 @end deftypefn") |
4697 { | |
4698 octave_value retval; | |
4699 | |
4700 if (args.length () == 1) | |
4545 | 4701 retval = args(0).squeeze (); |
4532 | 4702 else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
4703 print_usage (); |
4532 | 4704 |
4705 return retval; | |
4706 } | |
4707 | |
8458
d254a21e0120
reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents:
8433
diff
changeset
|
4708 DEFUN (full, args, , |
d254a21e0120
reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents:
8433
diff
changeset
|
4709 "-*- texinfo -*-\n\ |
d254a21e0120
reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents:
8433
diff
changeset
|
4710 @deftypefn {Loadable 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
|
4711 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
|
4712 or a range.\n\ |
8458
d254a21e0120
reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents:
8433
diff
changeset
|
4713 @seealso{sparse}\n\ |
d254a21e0120
reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents:
8433
diff
changeset
|
4714 @end deftypefn") |
d254a21e0120
reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents:
8433
diff
changeset
|
4715 { |
d254a21e0120
reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents:
8433
diff
changeset
|
4716 octave_value retval; |
d254a21e0120
reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents:
8433
diff
changeset
|
4717 |
d254a21e0120
reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents:
8433
diff
changeset
|
4718 if (args.length () == 1) |
d254a21e0120
reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents:
8433
diff
changeset
|
4719 retval = args(0).full_value (); |
d254a21e0120
reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents:
8433
diff
changeset
|
4720 else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
4721 print_usage (); |
8458
d254a21e0120
reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents:
8433
diff
changeset
|
4722 |
d254a21e0120
reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents:
8433
diff
changeset
|
4723 return retval; |
d254a21e0120
reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents:
8433
diff
changeset
|
4724 } |
d254a21e0120
reimplement full as method of octave_base_value
Jaroslav Hajek <highegg@gmail.com>
parents:
8433
diff
changeset
|
4725 |
6945 | 4726 // Compute various norms of the vector X. |
4727 | |
6953 | 4728 DEFUN (norm, args, , |
6508 | 4729 "-*- texinfo -*-\n\ |
12584
7ef7e20057fa
Improve documentation strings in Linear Algebra chapter.
Rik <octave@nomad.inbox5.com>
parents:
12578
diff
changeset
|
4730 @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
|
4731 @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
|
4732 @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
|
4733 Compute the p-norm of the matrix @var{A}. If the second argument is\n\ |
6953 | 4734 missing, @code{p = 2} is assumed.\n\ |
4735 \n\ | |
12584
7ef7e20057fa
Improve documentation strings in Linear Algebra chapter.
Rik <octave@nomad.inbox5.com>
parents:
12578
diff
changeset
|
4736 If @var{A} is a matrix (or sparse matrix):\n\ |
6953 | 4737 \n\ |
4738 @table @asis\n\ | |
4739 @item @var{p} = @code{1}\n\ | |
12584
7ef7e20057fa
Improve documentation strings in Linear Algebra chapter.
Rik <octave@nomad.inbox5.com>
parents:
12578
diff
changeset
|
4740 1-norm, the largest column sum of the absolute values of @var{A}.\n\ |
6953 | 4741 \n\ |
4742 @item @var{p} = @code{2}\n\ | |
12584
7ef7e20057fa
Improve documentation strings in Linear Algebra chapter.
Rik <octave@nomad.inbox5.com>
parents:
12578
diff
changeset
|
4743 Largest singular value of @var{A}.\n\ |
6953 | 4744 \n\ |
7189 | 4745 @item @var{p} = @code{Inf} or @code{\"inf\"}\n\ |
6953 | 4746 @cindex infinity norm\n\ |
12584
7ef7e20057fa
Improve documentation strings in Linear Algebra chapter.
Rik <octave@nomad.inbox5.com>
parents:
12578
diff
changeset
|
4747 Infinity norm, the largest row sum of the absolute values of @var{A}.\n\ |
6953 | 4748 \n\ |
4749 @item @var{p} = @code{\"fro\"}\n\ | |
4750 @cindex Frobenius norm\n\ | |
12584
7ef7e20057fa
Improve documentation strings in Linear Algebra chapter.
Rik <octave@nomad.inbox5.com>
parents:
12578
diff
changeset
|
4751 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
|
4752 \n\ |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
4753 @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
|
4754 @cindex general p-norm\n\ |
8303
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
4755 maximum @code{norm (A*x, p)} such that @code{norm (x, p) == 1}\n\ |
6953 | 4756 @end table\n\ |
4757 \n\ | |
12584
7ef7e20057fa
Improve documentation strings in Linear Algebra chapter.
Rik <octave@nomad.inbox5.com>
parents:
12578
diff
changeset
|
4758 If @var{A} is a vector or a scalar:\n\ |
6953 | 4759 \n\ |
4760 @table @asis\n\ | |
7189 | 4761 @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
|
4762 @code{max (abs (@var{A}))}.\n\ |
6953 | 4763 \n\ |
4764 @item @var{p} = @code{-Inf}\n\ | |
12584
7ef7e20057fa
Improve documentation strings in Linear Algebra chapter.
Rik <octave@nomad.inbox5.com>
parents:
12578
diff
changeset
|
4765 @code{min (abs (@var{A}))}.\n\ |
6953 | 4766 \n\ |
7189 | 4767 @item @var{p} = @code{\"fro\"}\n\ |
12584
7ef7e20057fa
Improve documentation strings in Linear Algebra chapter.
Rik <octave@nomad.inbox5.com>
parents:
12578
diff
changeset
|
4768 Frobenius norm of @var{A}, @code{sqrt (sumsq (abs (A)))}.\n\ |
7189 | 4769 \n\ |
8303
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
4770 @item @var{p} = 0\n\ |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
4771 Hamming norm - the number of nonzero elements.\n\ |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
4772 \n\ |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
4773 @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
|
4774 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
|
4775 \n\ |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
4776 @item other @var{p} @code{@var{p} < 1}\n\ |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
4777 the p-pseudonorm defined as above.\n\ |
6953 | 4778 @end table\n\ |
8303
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
4779 \n\ |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10682
diff
changeset
|
4780 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
|
4781 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
|
4782 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
|
4783 the norms of each column and return a row vector.\n\ |
6953 | 4784 @seealso{cond, svd}\n\ |
6508 | 4785 @end deftypefn") |
4786 { | |
6953 | 4787 octave_value_list retval; |
6508 | 4788 |
4789 int nargin = args.length (); | |
4790 | |
8303
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
4791 if (nargin >= 1 && nargin <= 3) |
6508 | 4792 { |
6953 | 4793 octave_value x_arg = args(0); |
4794 | |
10185
455759a5fcbe
fix norm and svd on empty matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
10182
diff
changeset
|
4795 if (x_arg.ndims () == 2) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4796 { |
8303
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
4797 enum { sfmatrix, sfcols, sfrows, sffrob, sfinf } strflag = sfmatrix; |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
4798 if (nargin > 1 && args(nargin-1).is_string ()) |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
4799 { |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
4800 std::string str = args(nargin-1).string_value (); |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
4801 if (str == "cols" || str == "columns") |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
4802 strflag = sfcols; |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
4803 else if (str == "rows") |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
4804 strflag = sfrows; |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
4805 else if (str == "fro") |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
4806 strflag = sffrob; |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
4807 else if (str == "inf") |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
4808 strflag = sfinf; |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
4809 else |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
4810 error ("norm: unrecognized option: %s", str.c_str ()); |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
4811 // 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
|
4812 nargin --; |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
4813 } |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
4814 else if (nargin > 1 && ! args(1).is_scalar_type ()) |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
4815 gripe_wrong_type_arg ("norm", args(1), true); |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
4816 |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
4817 if (! error_state) |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
4818 { |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
4819 octave_value p_arg = (nargin > 1) ? args(1) : octave_value (2); |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
4820 switch (strflag) |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
4821 { |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
4822 case sfmatrix: |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
4823 retval(0) = xnorm (x_arg, p_arg); |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
4824 break; |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
4825 case sfcols: |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
4826 retval(0) = xcolnorms (x_arg, p_arg); |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
4827 break; |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
4828 case sfrows: |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
4829 retval(0) = xrownorms (x_arg, p_arg); |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
4830 break; |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
4831 case sffrob: |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
4832 retval(0) = xfrobnorm (x_arg); |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
4833 break; |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
4834 case sfinf: |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
4835 retval(0) = xnorm (x_arg, octave_Inf); |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
4836 break; |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
4837 } |
b11c31849b44
improve norm computation capabilities
Jaroslav Hajek <highegg@gmail.com>
parents:
8286
diff
changeset
|
4838 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4839 } |
6508 | 4840 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
4841 error ("norm: only valid for 2-D objects"); |
6508 | 4842 } |
4843 else | |
4844 print_usage (); | |
4845 | |
4846 return retval; | |
4847 } | |
4848 | |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4849 /* |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4850 %!shared x |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4851 %! x = [1, -3, 4, 5, -7]; |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4852 %!assert(norm(x,1), 20); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4853 %!assert(norm(x,2), 10); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4854 %!assert(norm(x,3), 8.24257059961711, -4*eps); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4855 %!assert(norm(x,Inf), 7); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4856 %!assert(norm(x,-Inf), 1); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4857 %!assert(norm(x,"inf"), 7); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4858 %!assert(norm(x,"fro"), 10, -eps); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4859 %!assert(norm(x), 10); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4860 %!assert(norm([1e200, 1]), 1e200); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4861 %!assert(norm([3+4i, 3-4i, sqrt(31)]), 9, -4*eps); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4862 %!shared m |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4863 %! m = magic (4); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4864 %!assert(norm(m,1), 34); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4865 %!assert(norm(m,2), 34, -eps); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4866 %!assert(norm(m,Inf), 34); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4867 %!assert(norm(m,"inf"), 34); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4868 %!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
|
4869 %! 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
|
4870 %! 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
|
4871 %! fhi = 1e+300; |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4872 %!assert (norm(flo*m2,"fro"), sqrt(30)*flo, -eps) |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4873 %!assert (norm(fhi*m2,"fro"), sqrt(30)*fhi, -eps) |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4874 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4875 %!shared x |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4876 %! x = single([1, -3, 4, 5, -7]); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4877 %!assert(norm(x,1), single(20)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4878 %!assert(norm(x,2), single(10)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4879 %!assert(norm(x,3), single(8.24257059961711), -4*eps('single')); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4880 %!assert(norm(x,Inf), single(7)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4881 %!assert(norm(x,-Inf), single(1)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4882 %!assert(norm(x,"inf"), single(7)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4883 %!assert(norm(x,"fro"), single(10), -eps('single')); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4884 %!assert(norm(x), single(10)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4885 %!assert(norm(single([1e200, 1])), single(1e200)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4886 %!assert(norm(single([3+4i, 3-4i, sqrt(31)])), single(9), -4*eps('single')); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4887 %!shared m |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4888 %! m = single(magic (4)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4889 %!assert(norm(m,1), single(34)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4890 %!assert(norm(m,2), single(34), -eps('single')); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4891 %!assert(norm(m,Inf), single(34)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4892 %!assert(norm(m,"inf"), single(34)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4893 %!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
|
4894 %! m2 = single([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
|
4895 %! flo = single(1e-300); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4896 %! fhi = single(1e+300); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4897 %!assert (norm(flo*m2,"fro"), single(sqrt(30)*flo), -eps('single')) |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4898 %!assert (norm(fhi*m2,"fro"), single(sqrt(30)*fhi), -eps('single')) |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4899 */ |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4900 |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
4901 static octave_value |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
4902 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
|
4903 const octave_value_list& args) |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
4904 { |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
4905 octave_value retval; |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
4906 if (args.length () == 1) |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
4907 retval = do_unary_op (op, args(0)); |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
4908 else |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
4909 print_usage (); |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
4910 |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
4911 return retval; |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
4912 } |
6518 | 4913 |
4914 DEFUN (not, args, , | |
4915 "-*- texinfo -*-\n\ | |
4916 @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
|
4917 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
|
4918 @code{! x}.\n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
4919 @seealso{and, or, xor}\n\ |
6518 | 4920 @end deftypefn") |
4921 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
4922 return unary_op_defun_body (octave_value::op_not, args); |
6518 | 4923 } |
4924 | |
4925 DEFUN (uplus, args, , | |
4926 "-*- texinfo -*-\n\ | |
4927 @deftypefn {Built-in Function} {} uplus (@var{x})\n\ | |
11422
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
4928 This function is equivalent to @w{@code{+ x}}.\n\ |
6518 | 4929 @end deftypefn") |
4930 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
4931 return unary_op_defun_body (octave_value::op_uplus, args); |
6518 | 4932 } |
4933 | |
4934 DEFUN (uminus, args, , | |
4935 "-*- texinfo -*-\n\ | |
4936 @deftypefn {Built-in Function} {} uminus (@var{x})\n\ | |
11422
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
4937 This function is equivalent to @w{@code{- x}}.\n\ |
6518 | 4938 @end deftypefn") |
4939 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
4940 return unary_op_defun_body (octave_value::op_uminus, args); |
6518 | 4941 } |
4942 | |
4943 DEFUN (transpose, args, , | |
4944 "-*- texinfo -*-\n\ | |
4945 @deftypefn {Built-in Function} {} transpose (@var{x})\n\ | |
11422
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
4946 Return the transpose of @var{x}. This function is equivalent to @code{x.'}.\n\ |
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
4947 @seealso{ctranspose}\n\ |
6518 | 4948 @end deftypefn") |
4949 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
4950 return unary_op_defun_body (octave_value::op_transpose, args); |
6518 | 4951 } |
4952 | |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4953 /* |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4954 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4955 %!assert (2.', 2); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4956 %!assert (2i.',2i); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4957 %!assert ([1:4].',[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
|
4958 %!assert ([1;2;3;4].',[1:4]); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4959 %!assert ([1,2;3,4].',[1,3;2,4]); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4960 %!assert ([1,2i;3,4].',[1,3;2i,4]); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4961 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4962 %!assert (transpose ([1,2;3,4]),[1,3;2,4]); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4963 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4964 %!assert (single(2).', single(2)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4965 %!assert (single(2i).',single(2i)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4966 %!assert (single([1:4]).',single([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
|
4967 %!assert (single([1;2;3;4]).',single([1:4])); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4968 %!assert (single([1,2;3,4]).',single([1,3;2,4])); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4969 %!assert (single([1,2i;3,4]).',single([1,3;2i,4])); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4970 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4971 %!assert (transpose (single([1,2;3,4])),single([1,3;2,4])); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4972 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4973 */ |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4974 |
6518 | 4975 DEFUN (ctranspose, args, , |
4976 "-*- texinfo -*-\n\ | |
4977 @deftypefn {Built-in Function} {} ctranspose (@var{x})\n\ | |
11422
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
4978 Return the complex conjugate transpose of @var{x}. This function is\n\ |
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
4979 equivalent to @code{x'}.\n\ |
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
4980 @seealso{transpose}\n\ |
6518 | 4981 @end deftypefn") |
4982 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
4983 return unary_op_defun_body (octave_value::op_hermitian, args); |
6518 | 4984 } |
4985 | |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4986 /* |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4987 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4988 %!assert (2', 2); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4989 %!assert (2i',-2i); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4990 %!assert ([1:4]',[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
|
4991 %!assert ([1;2;3;4]',[1:4]); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4992 %!assert ([1,2;3,4]',[1,3;2,4]); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4993 %!assert ([1,2i;3,4]',[1,3;-2i,4]); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4994 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4995 %!assert (ctranspose ([1,2i;3,4]),[1,3;-2i,4]); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4996 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4997 %!assert (single(2)', single(2)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4998 %!assert (single(2i)',single(-2i)); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
4999 %!assert (single([1:4])',single([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
|
5000 %!assert (single([1;2;3;4])',single([1:4])); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5001 %!assert (single([1,2;3,4])',single([1,3;2,4])); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5002 %!assert (single([1,2i;3,4])',single([1,3;-2i,4])); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5003 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5004 %!assert (ctranspose (single([1,2i;3,4])),single([1,3;-2i,4])); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5005 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5006 */ |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5007 |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5008 static octave_value |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5009 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
|
5010 const octave_value_list& args) |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5011 { |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5012 octave_value retval; |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5013 |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5014 if (args.length () == 2) |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5015 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
|
5016 else |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5017 print_usage (); |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5018 |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5019 return retval; |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5020 } |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5021 |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5022 static octave_value |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5023 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
|
5024 octave_value::assign_op aop, |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5025 const octave_value_list& args) |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5026 { |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5027 octave_value retval; |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5028 int nargin = args.length (); |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5029 |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5030 switch (nargin) |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5031 { |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5032 case 0: |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5033 print_usage (); |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5034 break; |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5035 case 1: |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5036 retval = args(0); |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5037 break; |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5038 case 2: |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5039 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
|
5040 break; |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5041 default: |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5042 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
|
5043 for (int i = 2; i < nargin; i++) |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5044 retval.assign (aop, args(i)); |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5045 break; |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5046 } |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5047 |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5048 return retval; |
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5049 } |
9339
c0b104835d0d
allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
5050 |
6518 | 5051 DEFUN (plus, args, , |
5052 "-*- texinfo -*-\n\ | |
10840 | 5053 @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
|
5054 @deftypefnx {Built-in Function} {} plus (@var{x1}, @var{x2}, @dots{})\n\ |
11422
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
5055 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
|
5056 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
|
5057 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
|
5058 \n\ |
c0b104835d0d
allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
5059 @example\n\ |
c0b104835d0d
allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
5060 (@dots{}((x1 + x2) + x3) + @dots{})\n\ |
c0b104835d0d
allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
5061 @end example\n\ |
c0b104835d0d
allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
5062 \n\ |
11422
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
5063 At least one argument is required.\n\ |
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
5064 @seealso{minus}\n\ |
6518 | 5065 @end deftypefn") |
5066 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5067 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
|
5068 octave_value::op_add_eq, args); |
6518 | 5069 } |
5070 | |
5071 DEFUN (minus, args, , | |
5072 "-*- texinfo -*-\n\ | |
5073 @deftypefn {Built-in Function} {} minus (@var{x}, @var{y})\n\ | |
11422
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
5074 This function is equivalent to @w{@code{x - y}}.\n\ |
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
5075 @seealso{plus}\n\ |
6518 | 5076 @end deftypefn") |
5077 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5078 return binary_op_defun_body (octave_value::op_sub, args); |
6518 | 5079 } |
5080 | |
5081 DEFUN (mtimes, args, , | |
5082 "-*- texinfo -*-\n\ | |
10840 | 5083 @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
|
5084 @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
|
5085 Return the matrix multiplication product of inputs.\n\ |
11422
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
5086 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
|
5087 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
|
5088 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
|
5089 \n\ |
c0b104835d0d
allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
5090 @example\n\ |
c0b104835d0d
allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
5091 (@dots{}((x1 * x2) * x3) * @dots{})\n\ |
c0b104835d0d
allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
5092 @end example\n\ |
c0b104835d0d
allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
5093 \n\ |
11575
d6619410e79c
Spellcheck documentation before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents:
11572
diff
changeset
|
5094 At least one argument is required.\n\ |
11422
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
5095 @seealso{times}\n\ |
6518 | 5096 @end deftypefn") |
5097 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5098 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
|
5099 octave_value::op_mul_eq, args); |
6518 | 5100 } |
5101 | |
5102 DEFUN (mrdivide, args, , | |
5103 "-*- texinfo -*-\n\ | |
5104 @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
|
5105 Return the matrix right division of @var{x} and @var{y}.\n\ |
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
5106 This function is equivalent to @w{@code{x / y}}.\n\ |
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
5107 @seealso{mldivide, rdivide}\n\ |
6518 | 5108 @end deftypefn") |
5109 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5110 return binary_op_defun_body (octave_value::op_div, args); |
6518 | 5111 } |
5112 | |
5113 DEFUN (mpower, args, , | |
5114 "-*- texinfo -*-\n\ | |
5115 @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
|
5116 Return the matrix power operation of @var{x} raised to the @var{y} power.\n\ |
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
5117 This function is equivalent to @w{@code{x ^ y}}.\n\ |
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
5118 @seealso{power}\n\ |
6518 | 5119 @end deftypefn") |
5120 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5121 return binary_op_defun_body (octave_value::op_pow, args); |
6518 | 5122 } |
5123 | |
5124 DEFUN (mldivide, args, , | |
5125 "-*- texinfo -*-\n\ | |
5126 @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
|
5127 Return the matrix left division of @var{x} and @var{y}.\n\ |
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
5128 This function is equivalent to @w{@code{x \\ y}}.\n\ |
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
5129 @seealso{mrdivide, ldivide}\n\ |
6518 | 5130 @end deftypefn") |
5131 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5132 return binary_op_defun_body (octave_value::op_ldiv, args); |
6518 | 5133 } |
5134 | |
5135 DEFUN (lt, args, , | |
5136 "-*- texinfo -*-\n\ | |
5137 @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
|
5138 This function is equivalent to @w{@code{x < y}}.\n\ |
6518 | 5139 @end deftypefn") |
5140 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5141 return binary_op_defun_body (octave_value::op_lt, args); |
6518 | 5142 } |
5143 | |
5144 DEFUN (le, args, , | |
5145 "-*- texinfo -*-\n\ | |
5146 @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
|
5147 This function is equivalent to @w{@code{x <= y}}.\n\ |
6518 | 5148 @end deftypefn") |
5149 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5150 return binary_op_defun_body (octave_value::op_le, args); |
6518 | 5151 } |
5152 | |
5153 DEFUN (eq, args, , | |
5154 "-*- texinfo -*-\n\ | |
5155 @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
|
5156 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
|
5157 This function is equivalent to @w{@code{x == y}}.\n\ |
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
5158 @seealso{ne, isequal}\n\ |
6518 | 5159 @end deftypefn") |
5160 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5161 return binary_op_defun_body (octave_value::op_eq, args); |
6518 | 5162 } |
5163 | |
5164 DEFUN (ge, args, , | |
5165 "-*- texinfo -*-\n\ | |
5166 @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
|
5167 This function is equivalent to @w{@code{x >= y}}.\n\ |
6518 | 5168 @end deftypefn") |
5169 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5170 return binary_op_defun_body (octave_value::op_ge, args); |
6518 | 5171 } |
5172 | |
5173 DEFUN (gt, args, , | |
5174 "-*- texinfo -*-\n\ | |
5175 @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
|
5176 This function is equivalent to @w{@code{x > y}}.\n\ |
6518 | 5177 @end deftypefn") |
5178 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5179 return binary_op_defun_body (octave_value::op_gt, args); |
6518 | 5180 } |
5181 | |
5182 DEFUN (ne, args, , | |
5183 "-*- texinfo -*-\n\ | |
5184 @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
|
5185 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
|
5186 This function is equivalent to @w{@code{x != y}}.\n\ |
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
5187 @seealso{eq, isequal}\n\ |
6518 | 5188 @end deftypefn") |
5189 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5190 return binary_op_defun_body (octave_value::op_ne, args); |
6518 | 5191 } |
5192 | |
5193 DEFUN (times, args, , | |
5194 "-*- texinfo -*-\n\ | |
10840 | 5195 @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
|
5196 @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
|
5197 Return the element-by-element multiplication product of inputs.\n\ |
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
5198 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
|
5199 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
|
5200 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
|
5201 \n\ |
c0b104835d0d
allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
5202 @example\n\ |
c0b104835d0d
allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
5203 (@dots{}((x1 .* x2) .* x3) .* @dots{})\n\ |
c0b104835d0d
allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
5204 @end example\n\ |
c0b104835d0d
allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
5205 \n\ |
11422
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
5206 At least one argument is required.\n\ |
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
5207 @seealso{mtimes}\n\ |
6518 | 5208 @end deftypefn") |
5209 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5210 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
|
5211 octave_value::op_el_mul_eq, args); |
6518 | 5212 } |
5213 | |
5214 DEFUN (rdivide, args, , | |
5215 "-*- texinfo -*-\n\ | |
5216 @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
|
5217 Return the element-by-element right division of @var{x} and @var{y}.\n\ |
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
5218 This function is equivalent to @w{@code{x ./ y}}.\n\ |
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
5219 @seealso{ldivide, mrdivide}\n\ |
6518 | 5220 @end deftypefn") |
5221 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5222 return binary_op_defun_body (octave_value::op_el_div, args); |
6518 | 5223 } |
5224 | |
5225 DEFUN (power, args, , | |
5226 "-*- texinfo -*-\n\ | |
5227 @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
|
5228 Return the element-by-element operation of @var{x} raised to the\n\ |
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
5229 @var{y} power.\n\ |
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
5230 This function is equivalent to @w{@code{x .^ y}}.\n\ |
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
5231 @seealso{mpower}\n\ |
6518 | 5232 @end deftypefn") |
5233 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5234 return binary_op_defun_body (octave_value::op_el_pow, args); |
6518 | 5235 } |
5236 | |
5237 DEFUN (ldivide, args, , | |
5238 "-*- texinfo -*-\n\ | |
5239 @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
|
5240 Return the element-by-element left division of @var{x} and @var{y}.\n\ |
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
5241 This function is equivalent to @w{@code{x .\\ y}}.\n\ |
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
5242 @seealso{rdivide, mldivide}\n\ |
6518 | 5243 @end deftypefn") |
5244 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5245 return binary_op_defun_body (octave_value::op_el_ldiv, args); |
6518 | 5246 } |
5247 | |
5248 DEFUN (and, args, , | |
5249 "-*- texinfo -*-\n\ | |
10840 | 5250 @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
|
5251 @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
|
5252 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
|
5253 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
|
5254 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
|
5255 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
|
5256 \n\ |
c0b104835d0d
allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
5257 @example\n\ |
c0b104835d0d
allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
5258 (@dots{}((x1 & x2) & x3) & @dots{})\n\ |
c0b104835d0d
allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
5259 @end example\n\ |
c0b104835d0d
allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
5260 \n\ |
11422
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
5261 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
|
5262 @seealso{or, not, xor}\n\ |
6518 | 5263 @end deftypefn") |
5264 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5265 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
|
5266 octave_value::op_el_and_eq, args); |
6518 | 5267 } |
5268 | |
5269 DEFUN (or, args, , | |
5270 "-*- texinfo -*-\n\ | |
10840 | 5271 @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
|
5272 @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
|
5273 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
|
5274 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
|
5275 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
|
5276 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
|
5277 \n\ |
c0b104835d0d
allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
5278 @example\n\ |
c0b104835d0d
allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
5279 (@dots{}((x1 | x2) | x3) | @dots{})\n\ |
c0b104835d0d
allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
5280 @end example\n\ |
c0b104835d0d
allow multiple arguments in plus,times,mtimes,and,or
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
5281 \n\ |
11422
3cae59b4c0f7
Improve docstrings for functions which emulate operators.
Rik <octave@nomad.inbox5.com>
parents:
11402
diff
changeset
|
5282 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
|
5283 @seealso{and, not, xor}\n\ |
6518 | 5284 @end deftypefn") |
5285 { | |
9555
76ecc571879e
improve unop/binop implementation in data.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
9517
diff
changeset
|
5286 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
|
5287 octave_value::op_el_or_eq, args); |
6518 | 5288 } |
5289 | |
7065 | 5290 static double tic_toc_timestamp = -1.0; |
7045 | 5291 |
5292 DEFUN (tic, args, nargout, | |
5293 "-*- texinfo -*-\n\ | |
10840 | 5294 @deftypefn {Built-in Function} {} tic ()\n\ |
7045 | 5295 @deftypefnx {Built-in Function} {} toc ()\n\ |
5296 Set or check a wall-clock timer. Calling @code{tic} without an\n\ | |
5297 output argument sets the timer. Subsequent calls to @code{toc}\n\ | |
5298 return the number of seconds since the timer was set. For example,\n\ | |
5299 \n\ | |
5300 @example\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
9041
diff
changeset
|
5301 @group\n\ |
7045 | 5302 tic ();\n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
9041
diff
changeset
|
5303 # many computations later@dots{}\n\ |
7045 | 5304 elapsed_time = toc ();\n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
9041
diff
changeset
|
5305 @end group\n\ |
7045 | 5306 @end example\n\ |
5307 \n\ | |
5308 @noindent\n\ | |
5309 will set the variable @code{elapsed_time} to the number of seconds since\n\ | |
5310 the most recent call to the function @code{tic}.\n\ | |
5311 \n\ | |
5312 If called with one output argument then this function returns a scalar\n\ | |
5313 of type @code{uint64} and the wall-clock timer is not started.\n\ | |
5314 \n\ | |
5315 @example\n\ | |
5316 @group\n\ | |
5317 t = tic; sleep (5); (double (tic ()) - double (t)) * 1e-6\n\ | |
5318 @result{} 5\n\ | |
5319 @end group\n\ | |
5320 @end example\n\ | |
5321 \n\ | |
5322 Nested timing with @code{tic} and @code{toc} is not supported.\n\ | |
5323 Therefore @code{toc} will always return the elapsed time from the most\n\ | |
5324 recent call to @code{tic}.\n\ | |
5325 \n\ | |
5326 If you are more interested in the CPU time that your process used, you\n\ | |
5327 should use the @code{cputime} function instead. The @code{tic} and\n\ | |
5328 @code{toc} functions report the actual wall clock time that elapsed\n\ | |
5329 between the calls. This may include time spent processing other jobs or\n\ | |
10840 | 5330 doing nothing at all. For example:\n\ |
7045 | 5331 \n\ |
5332 @example\n\ | |
5333 @group\n\ | |
5334 tic (); sleep (5); toc ()\n\ | |
5335 @result{} 5\n\ | |
5336 t = cputime (); sleep (5); cputime () - t\n\ | |
5337 @result{} 0\n\ | |
5338 @end group\n\ | |
5339 @end example\n\ | |
5340 \n\ | |
5341 @noindent\n\ | |
5342 (This example also illustrates that the CPU timer may have a fairly\n\ | |
5343 coarse resolution.)\n\ | |
5344 @end deftypefn") | |
5345 { | |
5346 octave_value retval; | |
7065 | 5347 |
7045 | 5348 int nargin = args.length (); |
5349 | |
5350 if (nargin != 0) | |
5351 warning ("tic: ignoring extra arguments"); | |
5352 | |
7065 | 5353 octave_time now; |
5354 | |
5355 double tmp = now.double_value (); | |
5356 | |
7045 | 5357 if (nargout > 0) |
7065 | 5358 retval = static_cast<octave_uint64> (1e6 * tmp); |
7045 | 5359 else |
7065 | 5360 tic_toc_timestamp = tmp; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
5361 |
7045 | 5362 return retval; |
5363 } | |
5364 | |
5365 DEFUN (toc, args, nargout, | |
5366 "-*- texinfo -*-\n\ | |
5367 @deftypefn {Built-in Function} {} toc ()\n\ | |
5368 See tic.\n\ | |
5369 @end deftypefn") | |
5370 { | |
5371 octave_value retval; | |
7065 | 5372 |
7045 | 5373 int nargin = args.length (); |
5374 | |
5375 if (nargin != 0) | |
5376 warning ("tic: ignoring extra arguments"); | |
5377 | |
7065 | 5378 if (tic_toc_timestamp < 0) |
7045 | 5379 { |
5380 warning ("toc called before timer set"); | |
5381 if (nargout > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5382 retval = Matrix (); |
7045 | 5383 } |
5384 else | |
7065 | 5385 { |
5386 octave_time now; | |
5387 | |
5388 double tmp = now.double_value () - tic_toc_timestamp; | |
5389 | |
5390 if (nargout > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5391 retval = tmp; |
7065 | 5392 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5393 octave_stdout << "Elapsed time is " << tmp << " seconds.\n"; |
7065 | 5394 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
5395 |
7045 | 5396 return retval; |
5397 } | |
5398 | |
5399 DEFUN (cputime, args, , | |
5400 "-*- texinfo -*-\n\ | |
5401 @deftypefn {Built-in Function} {[@var{total}, @var{user}, @var{system}] =} cputime ();\n\ | |
5402 Return the CPU time used by your Octave session. The first output is\n\ | |
5403 the total time spent executing your process and is equal to the sum of\n\ | |
5404 second and third outputs, which are the number of CPU seconds spent\n\ | |
5405 executing in user mode and the number of CPU seconds spent executing in\n\ | |
5406 system mode, respectively. If your system does not have a way to report\n\ | |
5407 CPU time usage, @code{cputime} returns 0 for each of its output values.\n\ | |
5408 Note that because Octave used some CPU time to start, it is reasonable\n\ | |
5409 to check to see if @code{cputime} works by checking to see if the total\n\ | |
5410 CPU time used is nonzero.\n\ | |
5411 @end deftypefn") | |
5412 { | |
5413 octave_value_list retval; | |
5414 int nargin = args.length (); | |
5415 double usr = 0.0; | |
5416 double sys = 0.0; | |
5417 | |
5418 if (nargin != 0) | |
5419 warning ("tic: ignoring extra arguments"); | |
5420 | |
5421 #if defined (HAVE_GETRUSAGE) | |
5422 | |
5423 struct rusage ru; | |
5424 | |
5425 getrusage (RUSAGE_SELF, &ru); | |
5426 | |
5427 usr = static_cast<double> (ru.ru_utime.tv_sec) + | |
5428 static_cast<double> (ru.ru_utime.tv_usec) * 1e-6; | |
5429 | |
5430 sys = static_cast<double> (ru.ru_stime.tv_sec) + | |
5431 static_cast<double> (ru.ru_stime.tv_usec) * 1e-6; | |
5432 | |
10240
fa7b5751730c
use gnulib time, sys_time, and sys_times modules
John W. Eaton <jwe@octave.org>
parents:
10185
diff
changeset
|
5433 #else |
7045 | 5434 |
5435 struct tms t; | |
5436 | |
5437 times (&t); | |
5438 | |
5439 unsigned long ticks; | |
5440 unsigned long seconds; | |
5441 unsigned long fraction; | |
5442 | |
5443 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
|
5444 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
|
5445 seconds = ticks / CLOCKS_PER_SEC; |
7045 | 5446 |
5447 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
|
5448 static_cast<double>(CLOCKS_PER_SEC); |
7045 | 5449 |
5450 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
|
5451 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
|
5452 seconds = ticks / CLOCKS_PER_SEC; |
7045 | 5453 |
5454 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
|
5455 static_cast<double>(CLOCKS_PER_SEC); |
7045 | 5456 |
5457 #endif | |
5458 | |
5459 retval (2) = sys; | |
5460 retval (1) = usr; | |
5461 retval (0) = sys + usr; | |
5462 | |
5463 return retval; | |
5464 } | |
5465 | |
7433 | 5466 DEFUN (sort, args, nargout, |
5467 "-*- texinfo -*-\n\ | |
10840 | 5468 @deftypefn {Loadable Function} {[@var{s}, @var{i}] =} sort (@var{x})\n\ |
7433 | 5469 @deftypefnx {Loadable Function} {[@var{s}, @var{i}] =} sort (@var{x}, @var{dim})\n\ |
5470 @deftypefnx {Loadable Function} {[@var{s}, @var{i}] =} sort (@var{x}, @var{mode})\n\ | |
5471 @deftypefnx {Loadable Function} {[@var{s}, @var{i}] =} sort (@var{x}, @var{dim}, @var{mode})\n\ | |
5472 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
|
5473 order. For matrices, @code{sort} orders the elements within columns\n\ |
7433 | 5474 \n\ |
10840 | 5475 For example:\n\ |
7433 | 5476 \n\ |
5477 @example\n\ | |
5478 @group\n\ | |
5479 sort ([1, 2; 2, 3; 3, 1])\n\ | |
5480 @result{} 1 1\n\ | |
5481 2 2\n\ | |
5482 3 3\n\ | |
5483 @end group\n\ | |
5484 @end example\n\ | |
5485 \n\ | |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
5486 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
|
5487 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
|
5488 defines the order in which the values will be sorted. Valid values of\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
5489 @code{mode} are `ascend' or `descend'.\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
5490 \n\ |
7433 | 5491 The @code{sort} function may also be used to produce a matrix\n\ |
5492 containing the original row indices of the elements in the sorted\n\ | |
10840 | 5493 matrix. For example:\n\ |
7433 | 5494 \n\ |
5495 @example\n\ | |
5496 @group\n\ | |
5497 [s, i] = sort ([1, 2; 2, 3; 3, 1])\n\ | |
5498 @result{} s = 1 1\n\ | |
5499 2 2\n\ | |
5500 3 3\n\ | |
5501 @result{} i = 1 3\n\ | |
5502 2 1\n\ | |
5503 3 2\n\ | |
5504 @end group\n\ | |
5505 @end example\n\ | |
5506 \n\ | |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
5507 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
|
5508 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
|
5509 \n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
5510 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
|
5511 and for any ties by phase angle (@code{angle (z)}). For example:\n\ |
7433 | 5512 \n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
5513 @example\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
5514 @group\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
5515 sort ([1+i; 1; 1-i])\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
5516 @result{} 1 + 0i\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
5517 1 - 1i\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
5518 1 + 1i\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
5519 @end group\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
5520 @end example\n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
5521 \n\ |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
5522 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
|
5523 to the end of the list.\n\ |
7433 | 5524 \n\ |
5525 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
|
5526 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
|
5527 lowercase 'a') of the strings is used.\n\ |
7433 | 5528 \n\ |
5529 The algorithm used in @code{sort} is optimized for the sorting of partially\n\ | |
5530 ordered lists.\n\ | |
5531 @end deftypefn") | |
5532 { | |
5533 octave_value_list retval; | |
5534 | |
5535 int nargin = args.length (); | |
5536 sortmode smode = ASCENDING; | |
5537 | |
5538 if (nargin < 1 || nargin > 3) | |
5539 { | |
5540 print_usage (); | |
5541 return retval; | |
5542 } | |
5543 | |
5544 bool return_idx = nargout > 1; | |
5545 | |
5546 octave_value arg = args(0); | |
5547 | |
5548 int dim = 0; | |
5549 if (nargin > 1) | |
5550 { | |
5551 if (args(1).is_string ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5552 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5553 std::string mode = args(1).string_value(); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5554 if (mode == "ascend") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5555 smode = ASCENDING; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5556 else if (mode == "descend") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5557 smode = DESCENDING; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5558 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5559 { |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11591
diff
changeset
|
5560 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
|
5561 return retval; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5562 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5563 } |
7433 | 5564 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5565 dim = args(1).nint_value () - 1; |
7433 | 5566 } |
5567 | |
5568 if (nargin > 2) | |
5569 { | |
5570 if (args(1).is_string ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5571 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5572 print_usage (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5573 return retval; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5574 } |
7433 | 5575 |
5576 if (! args(2).is_string ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5577 { |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11591
diff
changeset
|
5578 error ("sort: MODE must be a string"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5579 return retval; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5580 } |
7433 | 5581 std::string mode = args(2).string_value(); |
5582 if (mode == "ascend") | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5583 smode = ASCENDING; |
7433 | 5584 else if (mode == "descend") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5585 smode = DESCENDING; |
7433 | 5586 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5587 { |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11591
diff
changeset
|
5588 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
|
5589 return retval; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5590 } |
7433 | 5591 } |
5592 | |
10285
22a7913bbeb5
optimize return values of find and sort
Jaroslav Hajek <highegg@gmail.com>
parents:
10277
diff
changeset
|
5593 const dim_vector dv = arg.dims (); |
7433 | 5594 if (nargin == 1 || args(1).is_string ()) |
5595 { | |
5596 // Find first non singleton dimension | |
10285
22a7913bbeb5
optimize return values of find and sort
Jaroslav Hajek <highegg@gmail.com>
parents:
10277
diff
changeset
|
5597 dim = dv.first_non_singleton (); |
7433 | 5598 } |
5599 else | |
5600 { | |
10703
5eb420d92307
fix sort and nth_element when trailing singleton dim is specified
Jaroslav Hajek <highegg@gmail.com>
parents:
10695
diff
changeset
|
5601 if (dim < 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5602 { |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11591
diff
changeset
|
5603 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
|
5604 return retval; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5605 } |
7433 | 5606 } |
5607 | |
5608 if (return_idx) | |
5609 { | |
5610 Array<octave_idx_type> sidx; | |
5611 | |
5612 retval (0) = arg.sort (sidx, dim, smode); | |
10285
22a7913bbeb5
optimize return values of find and sort
Jaroslav Hajek <highegg@gmail.com>
parents:
10277
diff
changeset
|
5613 retval (1) = idx_vector (sidx, dv(dim)); // No checking, the extent is known. |
7433 | 5614 } |
5615 else | |
5616 retval(0) = arg.sort (dim, smode); | |
5617 | |
5618 return retval; | |
5619 } | |
5620 | |
5621 /* | |
5622 | |
5623 %% Double | |
5624 %!assert (sort ([NaN, 1, -1, 2, Inf]), [-1, 1, 2, Inf, NaN]) | |
5625 %!assert (sort ([NaN, 1, -1, 2, Inf], 1), [NaN, 1, -1, 2, Inf]) | |
5626 %!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
|
5627 %!assert (sort ([NaN, 1, -1, 2, Inf], 3), [NaN, 1, -1, 2, Inf]) |
7433 | 5628 %!assert (sort ([NaN, 1, -1, 2, Inf], "ascend"), [-1, 1, 2, Inf, NaN]) |
5629 %!assert (sort ([NaN, 1, -1, 2, Inf], 2, "ascend"), [-1, 1, 2, Inf, NaN]) | |
5630 %!assert (sort ([NaN, 1, -1, 2, Inf], "descend"), [NaN, Inf, 2, 1, -1]) | |
5631 %!assert (sort ([NaN, 1, -1, 2, Inf], 2, "descend"), [NaN, Inf, 2, 1, -1]) | |
5632 %!assert (sort ([3, 1, 7, 5; 8, 2, 6, 4]), [3, 1, 6, 4; 8, 2, 7, 5]) | |
5633 %!assert (sort ([3, 1, 7, 5; 8, 2, 6, 4], 1), [3, 1, 6, 4; 8, 2, 7, 5]) | |
5634 %!assert (sort ([3, 1, 7, 5; 8, 2, 6, 4], 2), [1, 3, 5, 7; 2, 4, 6, 8]) | |
5635 %!assert (sort (1), 1) | |
5636 | |
5637 %!test | |
5638 %! [v, i] = sort ([NaN, 1, -1, Inf, 1]); | |
5639 %! assert (v, [-1, 1, 1, Inf, NaN]) | |
5640 %! assert (i, [3, 2, 5, 4, 1]) | |
5641 | |
5642 %% Complex | |
5643 %!assert (sort ([NaN, 1i, -1, 2, Inf]), [1i, -1, 2, Inf, NaN]) | |
5644 %!assert (sort ([NaN, 1i, -1, 2, Inf], 1), [NaN, 1i, -1, 2, Inf]) | |
5645 %!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
|
5646 %!assert (sort ([NaN, 1i, -1, 2, Inf], 3), [NaN, 1i, -1, 2, Inf]) |
7433 | 5647 %!assert (sort ([NaN, 1i, -1, 2, Inf], "ascend"), [1i, -1, 2, Inf, NaN]) |
5648 %!assert (sort ([NaN, 1i, -1, 2, Inf], 2, "ascend"), [1i, -1, 2, Inf, NaN]) | |
5649 %!assert (sort ([NaN, 1i, -1, 2, Inf], "descend"), [NaN, Inf, 2, -1, 1i]) | |
5650 %!assert (sort ([NaN, 1i, -1, 2, Inf], 2, "descend"), [NaN, Inf, 2, -1, 1i]) | |
5651 %!assert (sort ([3, 1i, 7, 5; 8, 2, 6, 4]), [3, 1i, 6, 4; 8, 2, 7, 5]) | |
5652 %!assert (sort ([3, 1i, 7, 5; 8, 2, 6, 4], 1), [3, 1i, 6, 4; 8, 2, 7, 5]) | |
5653 %!assert (sort ([3, 1i, 7, 5; 8, 2, 6, 4], 2), [1i, 3, 5, 7; 2, 4, 6, 8]) | |
5654 %!assert (sort (1i), 1i) | |
5655 | |
5656 %!test | |
5657 %! [v, i] = sort ([NaN, 1i, -1, Inf, 1, 1i]); | |
5658 %! assert (v, [1, 1i, 1i, -1, Inf, NaN]) | |
5659 %! assert (i, [5, 2, 6, 3, 4, 1]) | |
5660 | |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5661 %% Single |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5662 %!assert (sort (single([NaN, 1, -1, 2, Inf])), single([-1, 1, 2, Inf, NaN])) |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5663 %!assert (sort (single([NaN, 1, -1, 2, Inf]), 1), single([NaN, 1, -1, 2, Inf])) |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5664 %!assert (sort (single([NaN, 1, -1, 2, Inf]), 2), single([-1, 1, 2, Inf, NaN])) |
10707
69c5f5ec55d7
fix invalid sort tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10703
diff
changeset
|
5665 %!assert (sort (single([NaN, 1, -1, 2, Inf]), 3), single([NaN, 1, -1, 2, Inf])) |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5666 %!assert (sort (single([NaN, 1, -1, 2, Inf]), "ascend"), single([-1, 1, 2, Inf, NaN])) |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5667 %!assert (sort (single([NaN, 1, -1, 2, Inf]), 2, "ascend"), single([-1, 1, 2, Inf, NaN])) |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5668 %!assert (sort (single([NaN, 1, -1, 2, Inf]), "descend"), single([NaN, Inf, 2, 1, -1])) |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5669 %!assert (sort (single([NaN, 1, -1, 2, Inf]), 2, "descend"), single([NaN, Inf, 2, 1, -1])) |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5670 %!assert (sort (single([3, 1, 7, 5; 8, 2, 6, 4])), single([3, 1, 6, 4; 8, 2, 7, 5])) |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5671 %!assert (sort (single([3, 1, 7, 5; 8, 2, 6, 4]), 1), single([3, 1, 6, 4; 8, 2, 7, 5])) |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5672 %!assert (sort (single([3, 1, 7, 5; 8, 2, 6, 4]), 2), single([1, 3, 5, 7; 2, 4, 6, 8])) |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5673 %!assert (sort (single(1)), single(1)) |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5674 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5675 %!test |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5676 %! [v, i] = sort (single([NaN, 1, -1, Inf, 1])); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5677 %! assert (v, single([-1, 1, 1, Inf, NaN])) |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5678 %! assert (i, [3, 2, 5, 4, 1]) |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5679 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5680 %% Single Complex |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5681 %!assert (sort (single([NaN, 1i, -1, 2, Inf])), single([1i, -1, 2, Inf, NaN])) |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5682 %!assert (sort (single([NaN, 1i, -1, 2, Inf]), 1), single([NaN, 1i, -1, 2, Inf])) |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5683 %!assert (sort (single([NaN, 1i, -1, 2, Inf]), 2), single([1i, -1, 2, Inf, NaN])) |
10707
69c5f5ec55d7
fix invalid sort tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10703
diff
changeset
|
5684 %!assert (sort (single([NaN, 1i, -1, 2, Inf]), 3), single([NaN, 1i, -1, 2, Inf])) |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5685 %!assert (sort (single([NaN, 1i, -1, 2, Inf]), "ascend"), single([1i, -1, 2, Inf, NaN])) |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5686 %!assert (sort (single([NaN, 1i, -1, 2, Inf]), 2, "ascend"), single([1i, -1, 2, Inf, NaN])) |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5687 %!assert (sort (single([NaN, 1i, -1, 2, Inf]), "descend"), single([NaN, Inf, 2, -1, 1i])) |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5688 %!assert (sort (single([NaN, 1i, -1, 2, Inf]), 2, "descend"), single([NaN, Inf, 2, -1, 1i])) |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5689 %!assert (sort (single([3, 1i, 7, 5; 8, 2, 6, 4])), single([3, 1i, 6, 4; 8, 2, 7, 5])) |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5690 %!assert (sort (single([3, 1i, 7, 5; 8, 2, 6, 4]), 1), single([3, 1i, 6, 4; 8, 2, 7, 5])) |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5691 %!assert (sort (single([3, 1i, 7, 5; 8, 2, 6, 4]), 2), single([1i, 3, 5, 7; 2, 4, 6, 8])) |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5692 %!assert (sort (single(1i)),single( 1i)) |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5693 |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5694 %!test |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5695 %! [v, i] = sort (single([NaN, 1i, -1, Inf, 1, 1i])); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5696 %! assert (v, single([1, 1i, 1i, -1, Inf, NaN])) |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5697 %! assert (i, [5, 2, 6, 3, 4, 1]) |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5698 |
7433 | 5699 %% Bool |
5700 %!assert (sort ([true, false, true, false]), [false, false, true, true]) | |
5701 %!assert (sort ([true, false, true, false], 1), [true, false, true, false]) | |
5702 %!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
|
5703 %!assert (sort ([true, false, true, false], 3), [true, false, true, false]) |
7433 | 5704 %!assert (sort ([true, false, true, false], "ascend"), [false, false, true, true]) |
5705 %!assert (sort ([true, false, true, false], 2, "ascend"), [false, false, true, true]) | |
5706 %!assert (sort ([true, false, true, false], "descend"), [true, true, false, false]) | |
5707 %!assert (sort ([true, false, true, false], 2, "descend"), [true, true, false, false]) | |
5708 %!assert (sort (true), true) | |
5709 | |
5710 %!test | |
5711 %! [v, i] = sort ([true, false, true, false]); | |
5712 %! assert (v, [false, false, true, true]) | |
5713 %! assert (i, [2, 4, 1, 3]) | |
5714 | |
5715 %% Sparse Double | |
5716 %!assert (sort (sparse ([0, NaN, 1, 0, -1, 2, Inf])), sparse ([-1, 0, 0, 1, 2, Inf, NaN])) | |
5717 %!assert (sort (sparse ([0, NaN, 1, 0, -1, 2, Inf]), 1), sparse ([0, NaN, 1, 0, -1, 2, Inf])) | |
5718 %!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
|
5719 %!assert (sort (sparse ([0, NaN, 1, 0, -1, 2, Inf]), 3), sparse ([0, NaN, 1, 0, -1, 2, Inf])) |
7433 | 5720 %!assert (sort (sparse ([0, NaN, 1, 0, -1, 2, Inf]), "ascend"), sparse ([-1, 0, 0, 1, 2, Inf, NaN])) |
5721 %!assert (sort (sparse ([0, NaN, 1, 0, -1, 2, Inf]), 2, "ascend"), sparse ([-1, 0, 0, 1, 2, Inf, NaN])) | |
5722 %!assert (sort (sparse ([0, NaN, 1, 0, -1, 2, Inf]), "descend"), sparse ([NaN, Inf, 2, 1, 0, 0, -1])) | |
5723 %!assert (sort (sparse ([0, NaN, 1, 0, -1, 2, Inf]), 2, "descend"), sparse ([NaN, Inf, 2, 1, 0, 0, -1])) | |
5724 | |
5725 %!shared a | |
5726 %! a = randn (10, 10); | |
5727 %! a (a < 0) = 0; | |
5728 %!assert (sort (sparse (a)), sparse (sort (a))) | |
5729 %!assert (sort (sparse (a), 1), sparse (sort (a, 1))) | |
5730 %!assert (sort (sparse (a), 2), sparse (sort (a, 2))) | |
5731 %!test | |
5732 %! [v, i] = sort (a); | |
5733 %! [vs, is] = sort (sparse (a)); | |
5734 %! assert (vs, sparse (v)) | |
5735 %! assert (is, i) | |
5736 | |
5737 %% Sparse Complex | |
5738 %!assert (sort (sparse ([0, NaN, 1i, 0, -1, 2, Inf])), sparse ([0, 0, 1i, -1, 2, Inf, NaN])) | |
5739 %!assert (sort (sparse ([0, NaN, 1i, 0, -1, 2, Inf]), 1), sparse ([0, NaN, 1i, 0, -1, 2, Inf])) | |
5740 %!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
|
5741 %!assert (sort (sparse ([0, NaN, 1i, 0, -1, 2, Inf]), 3), sparse ([0, NaN, 1i, 0, -1, 2, Inf])) |
7433 | 5742 %!assert (sort (sparse ([0, NaN, 1i, 0, -1, 2, Inf]), "ascend"), sparse ([0, 0, 1i, -1, 2, Inf, NaN])) |
5743 %!assert (sort (sparse ([0, NaN, 1i, 0, -1, 2, Inf]), 2, "ascend"), sparse ([0, 0, 1i, -1, 2, Inf, NaN])) | |
5744 %!assert (sort (sparse ([0, NaN, 1i, 0, -1, 2, Inf]), "descend"), sparse ([NaN, Inf, 2, -1, 1i, 0, 0])) | |
5745 %!assert (sort (sparse ([0, NaN, 1i, 0, -1, 2, Inf]), 2, "descend"), sparse ([NaN, Inf, 2, -1, 1i, 0, 0])) | |
5746 | |
5747 %!shared a | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
5748 %! a = randn (10, 10); |
7433 | 5749 %! a (a < 0) = 0; |
5750 %! a = 1i * a; | |
5751 %!assert (sort (sparse (a)), sparse (sort (a))) | |
5752 %!assert (sort (sparse (a), 1), sparse (sort (a, 1))) | |
5753 %!assert (sort (sparse (a), 2), sparse (sort (a, 2))) | |
5754 %!test | |
5755 %! [v, i] = sort (a); | |
5756 %! [vs, is] = sort (sparse (a)); | |
5757 %! assert (vs, sparse (v)) | |
5758 %! assert (is, i) | |
5759 | |
5760 %% Sparse Bool | |
5761 %!assert (sort (sparse ([true, false, true, false])), sparse ([false, false, true, true])) | |
5762 %!assert (sort (sparse([true, false, true, false]), 1), sparse ([true, false, true, false])) | |
5763 %!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
|
5764 %!assert (sort (sparse ([true, false, true, false]), 3), sparse ([true, false, true, false])) |
7433 | 5765 %!assert (sort (sparse ([true, false, true, false]), "ascend"), sparse([false, false, true, true])) |
5766 %!assert (sort (sparse ([true, false, true, false]), 2, "ascend"), sparse([false, false, true, true])) | |
5767 %!assert (sort (sparse ([true, false, true, false]), "descend"), sparse ([true, true, false, false])) | |
5768 %!assert (sort (sparse ([true, false, true, false]), 2, "descend"), sparse([true, true, false, false])) | |
5769 | |
5770 %!test | |
5771 %! [v, i] = sort (sparse([true, false, true, false])); | |
5772 %! assert (v, sparse([false, false, true, true])) | |
5773 %! assert (i, [2, 4, 1, 3]) | |
5774 | |
5775 %% Cell string array | |
5776 %!shared a, b, c | |
5777 %! a = {"Alice", "Cecile", "Eric", "Barry", "David"}; | |
5778 %! b = {"Alice", "Barry", "Cecile", "David", "Eric"}; | |
5779 %! c = {"Eric", "David", "Cecile", "Barry", "Alice"}; | |
5780 %!assert (sort (a), b); | |
5781 %!assert (sort (a, 1), a) | |
5782 %!assert (sort (a, 2), b) | |
10707
69c5f5ec55d7
fix invalid sort tests
Jaroslav Hajek <highegg@gmail.com>
parents:
10703
diff
changeset
|
5783 %!assert (sort (a, 3), a) |
7433 | 5784 %!assert (sort (a, "ascend"), b) |
5785 %!assert (sort (a, 2, "ascend"), b) | |
5786 %!assert (sort (a, "descend"), c) | |
5787 %!assert (sort (a, 2, "descend"), c) | |
5788 | |
5789 %!test | |
5790 %! [v, i] = sort (a); | |
5791 %! assert (i, [1, 4, 2, 5, 3]) | |
5792 | |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5793 %!error <Invalid call to sort.*> sort (); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7795
diff
changeset
|
5794 %!error <Invalid call to sort.*> sort (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
|
5795 |
7433 | 5796 */ |
5797 | |
8812
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
8799
diff
changeset
|
5798 // Sort the rows of the matrix @var{a} according to the order |
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
8799
diff
changeset
|
5799 // specified by @var{mode}, which can either be `ascend' or `descend' |
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
8799
diff
changeset
|
5800 // 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
|
5801 // |
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
8799
diff
changeset
|
5802 // 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
|
5803 |
8733
3ef774603887
rename all uses of sortrows_idx to sort_rows_idx
John W. Eaton <jwe@octave.org>
parents:
8721
diff
changeset
|
5804 DEFUN (__sort_rows_idx__, args, , |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
5805 "-*- texinfo -*-\n\ |
9517
a85dbf7b6ff9
fix some functions help markup
Jaroslav Hajek <highegg@gmail.com>
parents:
9513
diff
changeset
|
5806 @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
|
5807 Undocumented internal function.\n\ |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
5808 @end deftypefn\n") |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
5809 { |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
5810 octave_value retval; |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
5811 |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
5812 int nargin = args.length (); |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
5813 sortmode smode = ASCENDING; |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
5814 |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
5815 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
|
5816 { |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
5817 print_usage (); |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
5818 return retval; |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
5819 } |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
5820 |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
5821 if (nargin > 1) |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
5822 { |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
5823 std::string mode = args(1).string_value(); |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
5824 if (mode == "ascend") |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
5825 smode = ASCENDING; |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
5826 else if (mode == "descend") |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
5827 smode = DESCENDING; |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
5828 else |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
5829 { |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11591
diff
changeset
|
5830 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
|
5831 return retval; |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
5832 } |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
5833 } |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
5834 |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
5835 octave_value arg = args(0); |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
5836 |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
5837 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
|
5838 error ("__sort_rows_idx__: sparse matrices not yet supported"); |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
5839 if (arg.ndims () == 2) |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
5840 { |
8733
3ef774603887
rename all uses of sortrows_idx to sort_rows_idx
John W. Eaton <jwe@octave.org>
parents:
8721
diff
changeset
|
5841 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
|
5842 |
9351
e2344f4af0cb
autocache indices returned from find et al.
Jaroslav Hajek <highegg@gmail.com>
parents:
9339
diff
changeset
|
5843 retval = octave_value (idx, true, true); |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
5844 } |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
5845 else |
8733
3ef774603887
rename all uses of sortrows_idx to sort_rows_idx
John W. Eaton <jwe@octave.org>
parents:
8721
diff
changeset
|
5846 error ("__sort_rows_idx__: needs a 2-dimensional object"); |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
5847 |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
5848 return retval; |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
5849 } |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
5850 |
9765
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
5851 static sortmode |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
5852 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
|
5853 { |
10076
4b270d1540f7
avoid various GCC warnings
John W. Eaton <jwe@octave.org>
parents:
10073
diff
changeset
|
5854 // 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
|
5855 // about possibly using sortmode uninitialized. |
4b270d1540f7
avoid various GCC warnings
John W. Eaton <jwe@octave.org>
parents:
10073
diff
changeset
|
5856 // 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
|
5857 sortmode smode = UNSORTED; |
9765
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
5858 |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
5859 std::string mode = arg.string_value (); |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
5860 |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
5861 if (error_state) |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
5862 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
|
5863 else if (mode == "ascending") |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
5864 smode = ASCENDING; |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
5865 else if (mode == "descending") |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
5866 smode = DESCENDING; |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
5867 else if (mode == "either") |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
5868 smode = UNSORTED; |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
5869 else |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11591
diff
changeset
|
5870 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
|
5871 |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
5872 return smode; |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
5873 } |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
5874 |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
5875 DEFUN (issorted, args, , |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
5876 "-*- texinfo -*-\n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
5877 @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
|
5878 @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
|
5879 @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
|
5880 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
|
5881 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
|
5882 @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
|
5883 @code{sort}.\n\ |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
5884 \n\ |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11422
diff
changeset
|
5885 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
|
5886 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
|
5887 (with no options).\n\ |
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11422
diff
changeset
|
5888 \n\ |
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11422
diff
changeset
|
5889 This function does not support sparse matrices.\n\ |
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11422
diff
changeset
|
5890 @seealso{sort, sortrows}\n\ |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
5891 @end deftypefn\n") |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
5892 { |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
5893 octave_value retval; |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
5894 |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
5895 int nargin = args.length (); |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
5896 |
9765
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
5897 if (nargin < 1 || nargin > 3) |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
5898 { |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
5899 print_usage (); |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
5900 return retval; |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
5901 } |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
5902 |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
5903 bool by_rows = false; |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
5904 |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
5905 sortmode smode = ASCENDING; |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
5906 |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
5907 if (nargin > 1) |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
5908 { |
9765
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
5909 octave_value mode_arg; |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
5910 |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
5911 if (nargin == 3) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5912 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
|
5913 |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
5914 std::string tmp = args(1).string_value (); |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
5915 |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
5916 if (! error_state) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5917 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5918 if (tmp == "rows") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5919 by_rows = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5920 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5921 smode = get_sort_mode_option (args(1), "second"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5922 } |
9765
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
5923 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5924 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
|
5925 |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
5926 if (error_state) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5927 return retval; |
9765
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
5928 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
5929 |
9765
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
5930 octave_value arg = args(0); |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
5931 |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
5932 if (by_rows) |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
5933 { |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
5934 if (arg.is_sparse_type ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5935 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
|
5936 if (arg.ndims () == 2) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5937 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
|
5938 else |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11591
diff
changeset
|
5939 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
|
5940 } |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
5941 else |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
5942 { |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
5943 if (arg.dims ().is_vector ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10303
diff
changeset
|
5944 retval = args(0).is_sorted (smode) != UNSORTED; |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
5945 else |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
5946 error ("issorted: needs a vector"); |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
5947 } |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
5948 |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
5949 return retval; |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
5950 } |
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
5951 |
9765
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
5952 /* |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
5953 %!shared sm, um, sv, uv |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
5954 %! sm = [1, 2; 3, 4]; |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
5955 %! um = [3, 1; 2, 4]; |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
5956 %! sv = [1, 2, 3, 4]; |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
5957 %! uv = [2, 1, 4, 3]; |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
5958 %!assert(issorted (sm, "rows")); |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
5959 %!assert(!issorted (um, "rows")); |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
5960 %!assert(issorted (sv)); |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
5961 %!assert(!issorted (uv)); |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
5962 %!assert(issorted (sv')); |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
5963 %!assert(!issorted (uv')); |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
5964 %!assert(issorted (sm, "rows", "ascending")); |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
5965 %!assert(!issorted (um, "rows", "ascending")); |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
5966 %!assert(issorted (sv, "ascending")); |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
5967 %!assert(!issorted (uv, "ascending")); |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
5968 %!assert(issorted (sv', "ascending")); |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
5969 %!assert(!issorted (uv', "ascending")); |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
5970 %!assert(!issorted (sm, "rows", "descending")); |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
5971 %!assert(issorted (flipud (sm), "rows", "descending")); |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
5972 %!assert(!issorted (sv, "descending")); |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
5973 %!assert(issorted (fliplr (sv), "descending")); |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
5974 %!assert(!issorted (sv', "descending")); |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
5975 %!assert(issorted (fliplr (sv)', "descending")); |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
5976 %!assert(!issorted (um, "rows", "either")); |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
5977 %!assert(!issorted (uv, "either")); |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
5978 %!assert(issorted (sm, "rows", "either")); |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
5979 %!assert(issorted (flipud (sm), "rows", "either")); |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
5980 %!assert(issorted (sv, "either")); |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
5981 %!assert(issorted (fliplr (sv), "either")); |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
5982 %!assert(issorted (sv', "either")); |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
5983 %!assert(issorted (fliplr (sv)', "either")); |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
5984 */ |
7fc1c8c47b86
issorted: new option for sort mode
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
5985 |
9725 | 5986 DEFUN (nth_element, args, , |
5987 "-*- texinfo -*-\n\ | |
10840 | 5988 @deftypefn {Built-in Function} {} nth_element (@var{x}, @var{n})\n\ |
9725 | 5989 @deftypefnx {Built-in Function} {} nth_element (@var{x}, @var{n}, @var{dim})\n\ |
10840 | 5990 Select the n-th smallest element of a vector, using the ordering defined by\n\ |
5991 @code{sort}. In other words, the result is equivalent to\n\ | |
5992 @code{sort(@var{x})(@var{n})}.\n\ | |
9725 | 5993 @var{n} can also be a contiguous range, either ascending @code{l:u}\n\ |
5994 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
|
5995 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
|
5996 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
|
5997 not given.\n\ |
9725 | 5998 \n\ |
10840 | 5999 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
|
6000 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
|
6001 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
|
6002 @w{@code{K = length (@var{n})}}.\n\ |
9725 | 6003 This function is intended for cases where the ratio K/M is small; otherwise,\n\ |
6004 it may be better to use @code{sort}.\n\ | |
6005 @seealso{sort, min, max}\n\ | |
6006 @end deftypefn") | |
6007 { | |
6008 octave_value retval; | |
6009 int nargin = args.length (); | |
6010 | |
6011 if (nargin == 2 || nargin == 3) | |
6012 { | |
6013 octave_value argx = args(0); | |
6014 | |
6015 int dim = -1; | |
6016 if (nargin == 3) | |
6017 { | |
6018 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
|
6019 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
|
6020 error ("nth_element: DIM must be a valid dimension"); |
9725 | 6021 } |
6022 if (dim < 0) | |
6023 dim = argx.dims ().first_non_singleton (); | |
6024 | |
6025 idx_vector n = args(1).index_vector (); | |
6026 | |
6027 if (error_state) | |
6028 return retval; | |
6029 | |
6030 switch (argx.builtin_type ()) | |
6031 { | |
6032 case btyp_double: | |
6033 retval = argx.array_value ().nth_element (n, dim); | |
6034 break; | |
6035 case btyp_float: | |
6036 retval = argx.float_array_value ().nth_element (n, dim); | |
6037 break; | |
6038 case btyp_complex: | |
6039 retval = argx.complex_array_value ().nth_element (n, dim); | |
6040 break; | |
6041 case btyp_float_complex: | |
6042 retval = argx.float_complex_array_value ().nth_element (n, dim); | |
6043 break; | |
6044 #define MAKE_INT_BRANCH(X) \ | |
6045 case btyp_ ## X: \ | |
6046 retval = argx.X ## _array_value ().nth_element (n, dim); \ | |
6047 break | |
6048 | |
6049 MAKE_INT_BRANCH (int8); | |
6050 MAKE_INT_BRANCH (int16); | |
6051 MAKE_INT_BRANCH (int32); | |
6052 MAKE_INT_BRANCH (int64); | |
6053 MAKE_INT_BRANCH (uint8); | |
6054 MAKE_INT_BRANCH (uint16); | |
6055 MAKE_INT_BRANCH (uint32); | |
6056 MAKE_INT_BRANCH (uint64); | |
6057 #undef MAKE_INT_BRANCH | |
6058 default: | |
6059 if (argx.is_cellstr ()) | |
6060 retval = argx.cellstr_value ().nth_element (n, dim); | |
6061 else | |
6062 gripe_wrong_type_arg ("nth_element", argx); | |
6063 } | |
6064 } | |
6065 else | |
6066 print_usage (); | |
6067 | |
6068 return retval; | |
6069 } | |
6070 | |
8934
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6071 template <class NDT> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
6072 static NDT |
8934
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6073 do_accumarray_sum (const idx_vector& idx, const NDT& vals, |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6074 octave_idx_type n = -1) |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6075 { |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6076 typedef typename NDT::element_type T; |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6077 if (n < 0) |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6078 n = idx.extent (0); |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6079 else if (idx.extent (n) > n) |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6080 error ("accumarray: index out of range"); |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6081 |
9858
47c5af1868df
move idx_add methods to MArrayN
Jaroslav Hajek <highegg@gmail.com>
parents:
9856
diff
changeset
|
6082 NDT retval (dim_vector (n, 1), T()); |
8934
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6083 |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6084 if (vals.numel () == 1) |
9858
47c5af1868df
move idx_add methods to MArrayN
Jaroslav Hajek <highegg@gmail.com>
parents:
9856
diff
changeset
|
6085 retval.idx_add (idx, vals (0)); |
47c5af1868df
move idx_add methods to MArrayN
Jaroslav Hajek <highegg@gmail.com>
parents:
9856
diff
changeset
|
6086 else if (vals.numel () == idx.length (n)) |
47c5af1868df
move idx_add methods to MArrayN
Jaroslav Hajek <highegg@gmail.com>
parents:
9856
diff
changeset
|
6087 retval.idx_add (idx, vals); |
8934
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6088 else |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6089 error ("accumarray: dimensions mismatch"); |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6090 |
9858
47c5af1868df
move idx_add methods to MArrayN
Jaroslav Hajek <highegg@gmail.com>
parents:
9856
diff
changeset
|
6091 return retval; |
8934
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6092 } |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6093 |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6094 DEFUN (__accumarray_sum__, args, , |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6095 "-*- texinfo -*-\n\ |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6096 @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
|
6097 Undocumented internal function.\n\ |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6098 @end deftypefn") |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6099 { |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6100 octave_value retval; |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6101 int nargin = args.length (); |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6102 if (nargin >= 2 && nargin <= 3 && args(0).is_numeric_type ()) |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6103 { |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6104 idx_vector idx = args(0).index_vector (); |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6105 octave_idx_type n = -1; |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6106 if (nargin == 3) |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6107 n = args(2).idx_type_value (true); |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6108 |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6109 if (! error_state) |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6110 { |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6111 octave_value vals = args(1); |
9198
3b9aacf07744
optimize accumarray with constant ranges
Jaroslav Hajek <highegg@gmail.com>
parents:
9197
diff
changeset
|
6112 if (vals.is_range ()) |
3b9aacf07744
optimize accumarray with constant ranges
Jaroslav Hajek <highegg@gmail.com>
parents:
9197
diff
changeset
|
6113 { |
3b9aacf07744
optimize accumarray with constant ranges
Jaroslav Hajek <highegg@gmail.com>
parents:
9197
diff
changeset
|
6114 Range r = vals.range_value (); |
3b9aacf07744
optimize accumarray with constant ranges
Jaroslav Hajek <highegg@gmail.com>
parents:
9197
diff
changeset
|
6115 if (r.inc () == 0) |
3b9aacf07744
optimize accumarray with constant ranges
Jaroslav Hajek <highegg@gmail.com>
parents:
9197
diff
changeset
|
6116 vals = r.base (); |
3b9aacf07744
optimize accumarray with constant ranges
Jaroslav Hajek <highegg@gmail.com>
parents:
9197
diff
changeset
|
6117 } |
3b9aacf07744
optimize accumarray with constant ranges
Jaroslav Hajek <highegg@gmail.com>
parents:
9197
diff
changeset
|
6118 |
8934
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6119 if (vals.is_single_type ()) |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6120 { |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6121 if (vals.is_complex_type ()) |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6122 retval = do_accumarray_sum (idx, vals.float_complex_array_value (), n); |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6123 else |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6124 retval = do_accumarray_sum (idx, vals.float_array_value (), n); |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6125 } |
10269
217d36560dfa
small fixes to accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10268
diff
changeset
|
6126 else if (vals.is_numeric_type () || vals.is_bool_type ()) |
8934
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6127 { |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6128 if (vals.is_complex_type ()) |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6129 retval = do_accumarray_sum (idx, vals.complex_array_value (), n); |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6130 else |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6131 retval = do_accumarray_sum (idx, vals.array_value (), n); |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6132 } |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6133 else |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6134 gripe_wrong_type_arg ("accumarray", vals); |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6135 } |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6136 } |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6137 else |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6138 print_usage (); |
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6139 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
6140 return retval; |
8934
c2099a4d12ea
partially optimize accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
6141 } |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6142 |
9473
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6143 template <class NDT> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
6144 static NDT |
10268
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6145 do_accumarray_minmax (const idx_vector& idx, const NDT& vals, |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6146 octave_idx_type n, bool ismin, |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6147 const typename NDT::element_type& zero_val) |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6148 { |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6149 typedef typename NDT::element_type T; |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6150 if (n < 0) |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6151 n = idx.extent (0); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6152 else if (idx.extent (n) > n) |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6153 error ("accumarray: index out of range"); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6154 |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6155 NDT retval (dim_vector (n, 1), zero_val); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6156 |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6157 // Pick minimizer or maximizer. |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
6158 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
|
6159 ismin ? (&MArray<T>::idx_min) : (&MArray<T>::idx_max); |
10268
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6160 |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6161 octave_idx_type l = idx.length (n); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6162 if (vals.numel () == 1) |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6163 (retval.*op) (idx, NDT (dim_vector (l, 1), vals(0))); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6164 else if (vals.numel () == l) |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6165 (retval.*op) (idx, vals); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6166 else |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6167 error ("accumarray: dimensions mismatch"); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6168 |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6169 return retval; |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6170 } |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6171 |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6172 static octave_value_list |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6173 do_accumarray_minmax_fun (const octave_value_list& args, |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6174 bool ismin) |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6175 { |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6176 octave_value retval; |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6177 int nargin = args.length (); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6178 if (nargin >= 3 && nargin <= 4 && args(0).is_numeric_type ()) |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6179 { |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6180 idx_vector idx = args(0).index_vector (); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6181 octave_idx_type n = -1; |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6182 if (nargin == 4) |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6183 n = args(3).idx_type_value (true); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6184 |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6185 if (! error_state) |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6186 { |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6187 octave_value vals = args(1), zero = args (2); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6188 |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6189 switch (vals.builtin_type ()) |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6190 { |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6191 case btyp_double: |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6192 retval = do_accumarray_minmax (idx, vals.array_value (), n, ismin, |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6193 zero.double_value ()); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6194 break; |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6195 case btyp_float: |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6196 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
|
6197 zero.float_value ()); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6198 break; |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6199 case btyp_complex: |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6200 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
|
6201 zero.complex_value ()); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6202 break; |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6203 case btyp_float_complex: |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6204 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
|
6205 zero.float_complex_value ()); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6206 break; |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6207 #define MAKE_INT_BRANCH(X) \ |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6208 case btyp_ ## X: \ |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6209 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
|
6210 zero.X ## _scalar_value ()); \ |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6211 break |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6212 |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6213 MAKE_INT_BRANCH (int8); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6214 MAKE_INT_BRANCH (int16); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6215 MAKE_INT_BRANCH (int32); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6216 MAKE_INT_BRANCH (int64); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6217 MAKE_INT_BRANCH (uint8); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6218 MAKE_INT_BRANCH (uint16); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6219 MAKE_INT_BRANCH (uint32); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6220 MAKE_INT_BRANCH (uint64); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6221 #undef MAKE_INT_BRANCH |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6222 case btyp_bool: |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6223 retval = do_accumarray_minmax (idx, vals.array_value (), n, ismin, |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6224 zero.bool_value ()); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6225 break; |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6226 default: |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6227 gripe_wrong_type_arg ("accumarray", vals); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6228 } |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6229 } |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6230 } |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6231 else |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6232 print_usage (); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6233 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
6234 return retval; |
10268
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6235 } |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6236 |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6237 DEFUN (__accumarray_min__, args, , |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6238 "-*- texinfo -*-\n\ |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6239 @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
|
6240 Undocumented internal function.\n\ |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6241 @end deftypefn") |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6242 { |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6243 return do_accumarray_minmax_fun (args, true); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6244 } |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6245 |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6246 DEFUN (__accumarray_max__, args, , |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6247 "-*- texinfo -*-\n\ |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6248 @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
|
6249 Undocumented internal function.\n\ |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6250 @end deftypefn") |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6251 { |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6252 return do_accumarray_minmax_fun (args, false); |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6253 } |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6254 |
9a16a61ed43d
new optimizations for accumarray
Jaroslav Hajek <highegg@gmail.com>
parents:
10240
diff
changeset
|
6255 template <class NDT> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
6256 static NDT |
10396
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6257 do_accumdim_sum (const idx_vector& idx, const NDT& vals, |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6258 int dim = -1, octave_idx_type n = -1) |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6259 { |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6260 typedef typename NDT::element_type T; |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6261 if (n < 0) |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6262 n = idx.extent (0); |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6263 else if (idx.extent (n) > n) |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6264 error ("accumarray: index out of range"); |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6265 |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6266 dim_vector rdv = vals.dims (); |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6267 if (dim < 0) |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6268 dim = vals.dims ().first_non_singleton (); |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6269 else if (dim >= rdv.length ()) |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6270 rdv.resize (dim+1, 1); |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6271 |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6272 rdv(dim) = n; |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6273 |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6274 NDT retval (rdv, T()); |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6275 |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6276 retval.idx_add_nd (idx, vals, dim); |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6277 return retval; |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6278 } |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6279 |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6280 DEFUN (__accumdim_sum__, args, , |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6281 "-*- texinfo -*-\n\ |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6282 @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
|
6283 Undocumented internal function.\n\ |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6284 @end deftypefn") |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6285 { |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6286 octave_value retval; |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6287 int nargin = args.length (); |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6288 if (nargin >= 2 && nargin <= 4 && args(0).is_numeric_type ()) |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6289 { |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6290 idx_vector idx = args(0).index_vector (); |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6291 int dim = -1; |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6292 if (nargin >= 3) |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6293 dim = args(2).int_value () - 1; |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6294 |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6295 octave_idx_type n = -1; |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6296 if (nargin == 4) |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6297 n = args(3).idx_type_value (true); |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6298 |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6299 if (! error_state) |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6300 { |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6301 octave_value vals = args(1); |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6302 |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6303 if (vals.is_single_type ()) |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6304 { |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6305 if (vals.is_complex_type ()) |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6306 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
|
6307 else |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6308 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
|
6309 } |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6310 else if (vals.is_numeric_type () || vals.is_bool_type ()) |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6311 { |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6312 if (vals.is_complex_type ()) |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6313 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
|
6314 else |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6315 retval = do_accumdim_sum (idx, vals.array_value (), dim, n); |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6316 } |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6317 else |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6318 gripe_wrong_type_arg ("accumdim", vals); |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6319 } |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6320 } |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6321 else |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6322 print_usage (); |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6323 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
6324 return retval; |
10396
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6325 } |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6326 |
a0b51ac0f88a
optimize accumdim with summation
Jaroslav Hajek <highegg@gmail.com>
parents:
10352
diff
changeset
|
6327 template <class NDT> |
9473
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6328 static NDT |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6329 do_merge (const Array<bool>& mask, |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6330 const NDT& tval, const NDT& fval) |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6331 { |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6332 typedef typename NDT::element_type T; |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6333 dim_vector dv = mask.dims (); |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6334 NDT retval (dv); |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6335 |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6336 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
|
6337 |
9473
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6338 if ((! tscl && tval.dims () != dv) |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6339 || (! 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
|
6340 error ("merge: MASK, TVAL, and FVAL dimensions must match"); |
9473
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6341 else |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6342 { |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6343 T *rv = retval.fortran_vec (); |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6344 octave_idx_type n = retval.numel (); |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6345 |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6346 const T *tv = tval.data (), *fv = fval.data (); |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6347 const bool *mv = mask.data (); |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6348 |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6349 if (tscl) |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6350 { |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6351 if (fscl) |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6352 { |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6353 T ts = tv[0], fs = fv[0]; |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6354 for (octave_idx_type i = 0; i < n; i++) |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6355 rv[i] = mv[i] ? ts : fs; |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6356 } |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6357 else |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6358 { |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6359 T ts = tv[0]; |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6360 for (octave_idx_type i = 0; i < n; i++) |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6361 rv[i] = mv[i] ? ts : fv[i]; |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6362 } |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6363 } |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6364 else |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6365 { |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6366 if (fscl) |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6367 { |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6368 T fs = fv[0]; |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6369 for (octave_idx_type i = 0; i < n; i++) |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6370 rv[i] = mv[i] ? tv[i] : fs; |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6371 } |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6372 else |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6373 { |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6374 for (octave_idx_type i = 0; i < n; i++) |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6375 rv[i] = mv[i] ? tv[i] : fv[i]; |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6376 } |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6377 } |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6378 } |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6379 |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6380 return retval; |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6381 } |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6382 |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6383 #define MAKE_INT_BRANCH(INTX) \ |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6384 else if (tval.is_ ## INTX ## _type () && fval.is_ ## INTX ## _type ()) \ |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6385 { \ |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6386 retval = do_merge (mask, \ |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6387 tval.INTX ## _array_value (), \ |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6388 fval.INTX ## _array_value ()); \ |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6389 } |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6390 |
9505
a321a1c227c8
make ifelse an alias or merge
Jaroslav Hajek <highegg@gmail.com>
parents:
9475
diff
changeset
|
6391 DEFUN (merge, args, , |
9473
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6392 "-*- texinfo -*-\n\ |
10840 | 6393 @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
|
6394 @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
|
6395 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
|
6396 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
|
6397 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
|
6398 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
|
6399 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
|
6400 is true, otherwise @var{fval} is returned.\n\ |
9473
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6401 \n\ |
10846
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10840
diff
changeset
|
6402 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
|
6403 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
|
6404 constructed as follows:\n\ |
10840 | 6405 \n\ |
9473
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6406 @example\n\ |
9758
09da0bd91412
Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents:
9736
diff
changeset
|
6407 @group\n\ |
9473
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6408 result(mask) = tval(mask);\n\ |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6409 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
|
6410 @end group\n\ |
9473
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6411 @end example\n\ |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6412 \n\ |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6413 @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
|
6414 it is first converted to logical.\n\ |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6415 @seealso{logical}\n\ |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6416 @end deftypefn") |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6417 { |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6418 int nargin = args.length (); |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6419 octave_value retval; |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6420 |
9856 | 6421 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
|
6422 { |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6423 octave_value mask_val = args(0); |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6424 |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6425 if (mask_val.is_scalar_type ()) |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6426 retval = mask_val.is_true () ? args(1) : args(2); |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6427 else |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6428 { |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6429 boolNDArray mask = mask_val.bool_array_value (); |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6430 octave_value tval = args(1), fval = args(2); |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6431 if (tval.is_double_type () && fval.is_double_type ()) |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6432 { |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6433 if (tval.is_complex_type () || fval.is_complex_type ()) |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6434 retval = do_merge (mask, |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6435 tval.complex_array_value (), |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6436 fval.complex_array_value ()); |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6437 else |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6438 retval = do_merge (mask, |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6439 tval.array_value (), |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6440 fval.array_value ()); |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6441 } |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6442 else if (tval.is_single_type () && fval.is_single_type ()) |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6443 { |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6444 if (tval.is_complex_type () || fval.is_complex_type ()) |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6445 retval = do_merge (mask, |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6446 tval.float_complex_array_value (), |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6447 fval.float_complex_array_value ()); |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6448 else |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6449 retval = do_merge (mask, |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6450 tval.float_array_value (), |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6451 fval.float_array_value ()); |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6452 } |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6453 else if (tval.is_string () && fval.is_string ()) |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6454 { |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6455 bool sq_string = tval.is_sq_string () || fval.is_sq_string (); |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6456 retval = octave_value (do_merge (mask, |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6457 tval.char_array_value (), |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6458 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
|
6459 sq_string ? '\'' : '"'); |
9473
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6460 } |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6461 else if (tval.is_cell () && fval.is_cell ()) |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6462 { |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6463 retval = do_merge (mask, |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6464 tval.cell_value (), |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6465 fval.cell_value ()); |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6466 } |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6467 |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6468 MAKE_INT_BRANCH (int8) |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6469 MAKE_INT_BRANCH (int16) |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6470 MAKE_INT_BRANCH (int32) |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6471 MAKE_INT_BRANCH (int64) |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6472 MAKE_INT_BRANCH (uint8) |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6473 MAKE_INT_BRANCH (uint16) |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6474 MAKE_INT_BRANCH (uint32) |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6475 MAKE_INT_BRANCH (uint64) |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6476 |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6477 else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
6478 error ("merge: cannot merge %s with %s with array mask", |
9473
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6479 tval.class_name ().c_str (), |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6480 fval.class_name ().c_str ()); |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6481 } |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6482 } |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6483 else |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6484 print_usage (); |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6485 |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6486 return retval; |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6487 } |
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6488 |
9505
a321a1c227c8
make ifelse an alias or merge
Jaroslav Hajek <highegg@gmail.com>
parents:
9475
diff
changeset
|
6489 DEFALIAS (ifelse, merge); |
a321a1c227c8
make ifelse an alias or merge
Jaroslav Hajek <highegg@gmail.com>
parents:
9475
diff
changeset
|
6490 |
9473
833109a9f37f
implement merge function
Jaroslav Hajek <highegg@gmail.com>
parents:
9428
diff
changeset
|
6491 #undef MAKE_INT_BRANCH |
8721
e9cb742df9eb
imported patch sort3.diff
Jaroslav Hajek <highegg@gmail.com>
parents:
8527
diff
changeset
|
6492 |
9513
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6493 template <class SparseT> |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6494 static SparseT |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6495 do_sparse_diff (const SparseT& array, octave_idx_type order, |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6496 int dim) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6497 { |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6498 SparseT retval = array; |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6499 if (dim == 1) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6500 { |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6501 octave_idx_type k = retval.columns (); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6502 while (order > 0 && k > 0) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6503 { |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6504 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
|
6505 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
|
6506 assert (retval.columns () == k-1); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6507 order--; |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6508 k--; |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6509 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6510 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6511 else |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6512 { |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6513 octave_idx_type k = retval.rows (); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6514 while (order > 0 && k > 0) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6515 { |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6516 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
|
6517 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
|
6518 assert (retval.rows () == k-1); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6519 order--; |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6520 k--; |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6521 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6522 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6523 |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6524 return retval; |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6525 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6526 |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6527 static octave_value |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6528 do_diff (const octave_value& array, octave_idx_type order, |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6529 int dim = -1) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6530 { |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6531 octave_value retval; |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6532 |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6533 const dim_vector& dv = array.dims (); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6534 if (dim == -1) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6535 { |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6536 dim = array.dims ().first_non_singleton (); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6537 |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6538 // Bother Matlab. This behavior is really wicked. |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6539 if (dv(dim) <= order) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6540 { |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6541 if (dv(dim) == 1) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6542 retval = array.resize (dim_vector (0, 0)); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6543 else |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6544 { |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6545 retval = array; |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6546 while (order > 0) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6547 { |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6548 if (dim == dv.length ()) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6549 { |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6550 retval = do_diff (array, order, dim - 1); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6551 order = 0; |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6552 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6553 else if (dv(dim) == 1) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6554 dim++; |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6555 else |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6556 { |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6557 retval = do_diff (array, dv(dim) - 1, dim); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6558 order -= dv(dim) - 1; |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6559 dim++; |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6560 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6561 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6562 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6563 |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6564 return retval; |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6565 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6566 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6567 |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6568 if (array.is_integer_type ()) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6569 { |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6570 if (array.is_int8_type ()) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6571 retval = array.int8_array_value ().diff (order, dim); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6572 else if (array.is_int16_type ()) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6573 retval = array.int16_array_value ().diff (order, dim); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6574 else if (array.is_int32_type ()) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6575 retval = array.int32_array_value ().diff (order, dim); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6576 else if (array.is_int64_type ()) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6577 retval = array.int64_array_value ().diff (order, dim); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6578 else if (array.is_uint8_type ()) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6579 retval = array.uint8_array_value ().diff (order, dim); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6580 else if (array.is_uint16_type ()) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6581 retval = array.uint16_array_value ().diff (order, dim); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6582 else if (array.is_uint32_type ()) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6583 retval = array.uint32_array_value ().diff (order, dim); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6584 else if (array.is_uint64_type ()) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6585 retval = array.uint64_array_value ().diff (order, dim); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6586 else |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6587 panic_impossible (); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6588 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6589 else if (array.is_sparse_type ()) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6590 { |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6591 if (array.is_complex_type ()) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6592 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
|
6593 else |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6594 retval = do_sparse_diff (array.sparse_matrix_value (), order, dim); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6595 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6596 else if (array.is_single_type ()) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6597 { |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6598 if (array.is_complex_type ()) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6599 retval = array.float_complex_array_value ().diff (order, dim); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6600 else |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6601 retval = array.float_array_value ().diff (order, dim); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6602 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6603 else |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6604 { |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6605 if (array.is_complex_type ()) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6606 retval = array.complex_array_value ().diff (order, dim); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6607 else |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6608 retval = array.array_value ().diff (order, dim); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6609 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6610 |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6611 return retval; |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6612 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6613 |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6614 DEFUN (diff, args, , |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6615 "-*- texinfo -*-\n\ |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
12584
diff
changeset
|
6616 @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
|
6617 @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
|
6618 @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
|
6619 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
|
6620 vector of first differences\n\ |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6621 @tex\n\ |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6622 $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
|
6623 @end tex\n\ |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6624 @ifnottex\n\ |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6625 @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
|
6626 @end ifnottex\n\ |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6627 \n\ |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6628 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
|
6629 differences along the first non-singleton dimension.\n\ |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6630 \n\ |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6631 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
|
6632 @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
|
6633 @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
|
6634 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
|
6635 @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
|
6636 non-singleton dimension.\n\ |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6637 \n\ |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6638 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
|
6639 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
|
6640 @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
|
6641 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
|
6642 an empty matrix is returned.\n\ |
9513
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6643 @end deftypefn") |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6644 { |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6645 int nargin = args.length (); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6646 octave_value retval; |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6647 |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6648 if (nargin < 1 || nargin > 3) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6649 print_usage (); |
10880 | 6650 else if (! (args(0).is_numeric_type () || args(0).is_bool_type ())) |
6651 error ("diff: X must be numeric or logical"); | |
9513
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6652 |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6653 if (! error_state) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6654 { |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6655 int dim = -1; |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6656 octave_idx_type order = 1; |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6657 if (nargin > 1) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6658 { |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6659 if (args(1).is_scalar_type ()) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6660 order = args(1).idx_type_value (true, false); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6661 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
|
6662 error ("order K must be a scalar or []"); |
9513
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6663 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
|
6664 error ("order K must be non-negative"); |
9513
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6665 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6666 |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6667 if (nargin > 2) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6668 { |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6669 dim = args(2).int_value (true, false); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6670 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
|
6671 error ("DIM must be a valid dimension"); |
9513
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6672 else |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6673 dim -= 1; |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6674 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6675 |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6676 if (! error_state) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6677 retval = do_diff (args(0), order, dim); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6678 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6679 |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6680 return retval; |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6681 } |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6682 |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6683 /* |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6684 |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6685 %!assert (diff ([1, 2, 3, 4]), [1, 1, 1]) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6686 %!assert (diff ([1, 3, 7, 19], 2), [2, 8]) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6687 %!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
|
6688 %!assert (diff ([1, 2; 5, 4; 8, 7; 9, 6; 3, 1], 3), [-1, -5; -5, 0]) |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6689 %!assert (isempty (diff (1))); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6690 |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6691 %!error diff ([1, 2; 3, 4], -1); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6692 |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6693 %!error diff ("foo"); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6694 |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6695 %!error diff (); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6696 |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6697 %!error diff (1, 2, 3, 4); |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6698 |
9f870f73ab7d
implement built-in diff
Jaroslav Hajek <highegg@gmail.com>
parents:
9505
diff
changeset
|
6699 */ |
10799
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6700 |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6701 template <class T> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
6702 static Array<T> |
10799
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6703 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
|
6704 { |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6705 Array<T> retval; |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6706 |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6707 assert (rep.ndims () == 2 && rep.rows () == 2); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6708 |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6709 octave_idx_type n = rep.columns (), l = 0; |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6710 for (octave_idx_type i = 0; i < n; i++) |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6711 { |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6712 octave_idx_type k = rep(1, i); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6713 if (k < 0) |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6714 { |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11591
diff
changeset
|
6715 error ("repelems: second row must contain non-negative numbers"); |
10799
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6716 return retval; |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6717 } |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6718 |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6719 l += k; |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6720 } |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6721 |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6722 retval.clear (1, l); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6723 T *dest = retval.fortran_vec (); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6724 l = 0; |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6725 for (octave_idx_type i = 0; i < n; i++) |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6726 { |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6727 octave_idx_type k = rep(1, i); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6728 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
|
6729 dest += k; |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6730 } |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6731 |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6732 return retval; |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6733 } |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6734 |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6735 DEFUN (repelems, args, , |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6736 "-*- texinfo -*-\n\ |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6737 @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
|
6738 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
|
6739 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
|
6740 how often to repeat each element.\n\ |
a40e32927b3a
Improve documentation for new repelems function.
Rik <octave@nomad.inbox5.com>
parents:
10799
diff
changeset
|
6741 \n\ |
a40e32927b3a
Improve documentation for new repelems function.
Rik <octave@nomad.inbox5.com>
parents:
10799
diff
changeset
|
6742 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
|
6743 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
|
6744 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
|
6745 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
|
6746 index. A row vector is always returned.\n\ |
a40e32927b3a
Improve documentation for new repelems function.
Rik <octave@nomad.inbox5.com>
parents:
10799
diff
changeset
|
6747 \n\ |
a40e32927b3a
Improve documentation for new repelems function.
Rik <octave@nomad.inbox5.com>
parents:
10799
diff
changeset
|
6748 Conceptually the result is calculated as follows:\n\ |
10799
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6749 \n\ |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6750 @example\n\ |
10840 | 6751 @group\n\ |
10801
a40e32927b3a
Improve documentation for new repelems function.
Rik <octave@nomad.inbox5.com>
parents:
10799
diff
changeset
|
6752 y = [];\n\ |
a40e32927b3a
Improve documentation for new repelems function.
Rik <octave@nomad.inbox5.com>
parents:
10799
diff
changeset
|
6753 for i = 1:columns (@var{r})\n\ |
a40e32927b3a
Improve documentation for new repelems function.
Rik <octave@nomad.inbox5.com>
parents:
10799
diff
changeset
|
6754 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
|
6755 endfor\n\ |
10840 | 6756 @end group\n\ |
10799
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6757 @end example\n\ |
10801
a40e32927b3a
Improve documentation for new repelems function.
Rik <octave@nomad.inbox5.com>
parents:
10799
diff
changeset
|
6758 @seealso{repmat}\n\ |
10799
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6759 @end deftypefn") |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6760 { |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6761 octave_value retval; |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6762 |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6763 if (args.length () == 2) |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6764 { |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6765 octave_value x = args(0); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6766 |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6767 const Matrix rm = args(1).matrix_value (); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6768 if (error_state) |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6769 return retval; |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6770 else if (rm.rows () != 2 || rm.ndims () != 2) |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6771 { |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11591
diff
changeset
|
6772 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
|
6773 return retval; |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6774 } |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6775 else |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6776 { |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6777 NoAlias< Array<octave_idx_type> > r (rm.dims ()); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6778 |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6779 for (octave_idx_type i = 0; i < rm.numel (); i++) |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6780 { |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6781 octave_idx_type rx = rm(i); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6782 if (static_cast<double> (rx) != rm(i)) |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6783 { |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
11591
diff
changeset
|
6784 error ("repelems: R must be a matrix of integers"); |
10799
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6785 return retval; |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6786 } |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6787 |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6788 r(i) = rx; |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6789 } |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6790 |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6791 switch (x.builtin_type ()) |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6792 { |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6793 #define BTYP_BRANCH(X, EX) \ |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6794 case btyp_ ## X: \ |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6795 retval = do_repelems (x.EX ## _value (), r); \ |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6796 break |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6797 |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6798 BTYP_BRANCH (double, array); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6799 BTYP_BRANCH (float, float_array); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6800 BTYP_BRANCH (complex, complex_array); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6801 BTYP_BRANCH (float_complex, float_complex_array); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6802 BTYP_BRANCH (bool, bool_array); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6803 BTYP_BRANCH (char, char_array); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6804 |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6805 BTYP_BRANCH (int8, int8_array); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6806 BTYP_BRANCH (int16, int16_array); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6807 BTYP_BRANCH (int32, int32_array); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6808 BTYP_BRANCH (int64, int64_array); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6809 BTYP_BRANCH (uint8, uint8_array); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6810 BTYP_BRANCH (uint16, uint16_array); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6811 BTYP_BRANCH (uint32, uint32_array); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6812 BTYP_BRANCH (uint64, uint64_array); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6813 |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6814 BTYP_BRANCH (cell, cell); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6815 //BTYP_BRANCH (struct, map);//FIXME |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6816 #undef BTYP_BRANCH |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6817 |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6818 default: |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6819 gripe_wrong_type_arg ("repelems", x); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6820 } |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6821 } |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6822 } |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6823 else |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6824 print_usage (); |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6825 |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6826 return retval; |
177f1ad7c7c1
new built-in: repelems
Jaroslav Hajek <highegg@gmail.com>
parents:
10785
diff
changeset
|
6827 } |