annotate src/data.cc @ 7743:fbe27e477578

more tests fixed
author John W. Eaton <jwe@octave.org>
date Wed, 30 Apr 2008 14:25:31 -0400
parents 72c0489653ac
children 82be108cc558
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1 /*
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
2
7017
a1dbe9d80eee [project @ 2007-10-12 21:27:11 by jwe]
jwe
parents: 7016
diff changeset
3 Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
a1dbe9d80eee [project @ 2007-10-12 21:27:11 by jwe]
jwe
parents: 7016
diff changeset
4 2003, 2004, 2005, 2006, 2007 John W. Eaton
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
5
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
6 This file is part of Octave.
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
7
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
8 Octave is free software; you can redistribute it and/or modify it
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
9 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7007
diff changeset
10 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7007
diff changeset
11 option) any later version.
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
12
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
13 Octave is distributed in the hope that it will be useful, but WITHOUT
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
16 for more details.
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
17
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7007
diff changeset
19 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7007
diff changeset
20 <http://www.gnu.org/licenses/>.
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
21
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
22 */
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
23
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
24 #ifdef HAVE_CONFIG_H
1192
b6360f2d4fa6 [project @ 1995-03-30 21:38:35 by jwe]
jwe
parents: 1129
diff changeset
25 #include <config.h>
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
26 #endif
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
27
7078
405cf85b435c [project @ 2007-10-30 14:04:59 by jwe]
jwe
parents: 7065
diff changeset
28 #include "systime.h"
405cf85b435c [project @ 2007-10-30 14:04:59 by jwe]
jwe
parents: 7065
diff changeset
29
405cf85b435c [project @ 2007-10-30 14:04:59 by jwe]
jwe
parents: 7065
diff changeset
30 #ifdef HAVE_SYS_TYPES_H
405cf85b435c [project @ 2007-10-30 14:04:59 by jwe]
jwe
parents: 7065
diff changeset
31 #include <sys/types.h>
405cf85b435c [project @ 2007-10-30 14:04:59 by jwe]
jwe
parents: 7065
diff changeset
32 #endif
405cf85b435c [project @ 2007-10-30 14:04:59 by jwe]
jwe
parents: 7065
diff changeset
33
405cf85b435c [project @ 2007-10-30 14:04:59 by jwe]
jwe
parents: 7065
diff changeset
34 #ifdef HAVE_SYS_RESOURCE_H
405cf85b435c [project @ 2007-10-30 14:04:59 by jwe]
jwe
parents: 7065
diff changeset
35 #include <sys/resource.h>
405cf85b435c [project @ 2007-10-30 14:04:59 by jwe]
jwe
parents: 7065
diff changeset
36 #endif
405cf85b435c [project @ 2007-10-30 14:04:59 by jwe]
jwe
parents: 7065
diff changeset
37
2184
dbbbb3559ee8 [project @ 1996-05-14 02:18:22 by jwe]
jwe
parents: 2086
diff changeset
38 #include <cfloat>
dbbbb3559ee8 [project @ 1996-05-14 02:18:22 by jwe]
jwe
parents: 2086
diff changeset
39
1728
42b4f904f1af [project @ 1996-01-09 11:36:01 by jwe]
jwe
parents: 1572
diff changeset
40 #include <string>
42b4f904f1af [project @ 1996-01-09 11:36:01 by jwe]
jwe
parents: 1572
diff changeset
41
2184
dbbbb3559ee8 [project @ 1996-05-14 02:18:22 by jwe]
jwe
parents: 2086
diff changeset
42 #include "lo-ieee.h"
7231
2eb392d058bb [project @ 2007-11-30 18:53:29 by jwe]
jwe
parents: 7189
diff changeset
43 #include "lo-math.h"
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
44 #include "str-vec.h"
4153
6b96ce9f5743 [project @ 2002-11-06 20:38:49 by jwe]
jwe
parents: 4114
diff changeset
45 #include "quit.h"
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
46
6953
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
47 #include "Cell.h"
1352
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1315
diff changeset
48 #include "defun.h"
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1315
diff changeset
49 #include "error.h"
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1315
diff changeset
50 #include "gripes.h"
6953
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
51 #include "oct-map.h"
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
52 #include "oct-obj.h"
2366
c90105b99479 [project @ 1996-10-11 23:22:27 by jwe]
jwe
parents: 2305
diff changeset
53 #include "ov.h"
5476
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
54 #include "ov-complex.h"
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
55 #include "ov-cx-mat.h"
6953
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
56 #include "parse.h"
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
57 #include "pt-mat.h"
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
58 #include "utils.h"
6953
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
59 #include "variables.h"
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
60 #include "pager.h"
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
61
4015
6476dd85a65f [project @ 2002-08-02 07:59:19 by jwe]
jwe
parents: 3972
diff changeset
62 #define ANY_ALL(FCN) \
6476dd85a65f [project @ 2002-08-02 07:59:19 by jwe]
jwe
parents: 3972
diff changeset
63 \
4233
ccfdb55c8156 [project @ 2002-12-20 22:43:54 by jwe]
jwe
parents: 4176
diff changeset
64 octave_value retval; \
4015
6476dd85a65f [project @ 2002-08-02 07:59:19 by jwe]
jwe
parents: 3972
diff changeset
65 \
6476dd85a65f [project @ 2002-08-02 07:59:19 by jwe]
jwe
parents: 3972
diff changeset
66 int nargin = args.length (); \
6476dd85a65f [project @ 2002-08-02 07:59:19 by jwe]
jwe
parents: 3972
diff changeset
67 \
4021
963507f8caf4 [project @ 2002-08-05 22:22:16 by jwe]
jwe
parents: 4015
diff changeset
68 if (nargin == 1 || nargin == 2) \
4015
6476dd85a65f [project @ 2002-08-02 07:59:19 by jwe]
jwe
parents: 3972
diff changeset
69 { \
4021
963507f8caf4 [project @ 2002-08-05 22:22:16 by jwe]
jwe
parents: 4015
diff changeset
70 int dim = (nargin == 1 ? -1 : args(1).int_value (true) - 1); \
963507f8caf4 [project @ 2002-08-05 22:22:16 by jwe]
jwe
parents: 4015
diff changeset
71 \
963507f8caf4 [project @ 2002-08-05 22:22:16 by jwe]
jwe
parents: 4015
diff changeset
72 if (! error_state) \
963507f8caf4 [project @ 2002-08-05 22:22:16 by jwe]
jwe
parents: 4015
diff changeset
73 { \
4556
773a21e4fce8 [project @ 2003-10-28 05:02:10 by jwe]
jwe
parents: 4554
diff changeset
74 if (dim >= -1) \
4015
6476dd85a65f [project @ 2002-08-02 07:59:19 by jwe]
jwe
parents: 3972
diff changeset
75 retval = args(0).FCN (dim); \
4021
963507f8caf4 [project @ 2002-08-05 22:22:16 by jwe]
jwe
parents: 4015
diff changeset
76 else \
963507f8caf4 [project @ 2002-08-05 22:22:16 by jwe]
jwe
parents: 4015
diff changeset
77 error (#FCN ": invalid dimension argument = %d", dim + 1); \
963507f8caf4 [project @ 2002-08-05 22:22:16 by jwe]
jwe
parents: 4015
diff changeset
78 } \
4015
6476dd85a65f [project @ 2002-08-02 07:59:19 by jwe]
jwe
parents: 3972
diff changeset
79 else \
4021
963507f8caf4 [project @ 2002-08-05 22:22:16 by jwe]
jwe
parents: 4015
diff changeset
80 error (#FCN ": expecting dimension argument to be an integer"); \
4015
6476dd85a65f [project @ 2002-08-02 07:59:19 by jwe]
jwe
parents: 3972
diff changeset
81 } \
4021
963507f8caf4 [project @ 2002-08-05 22:22:16 by jwe]
jwe
parents: 4015
diff changeset
82 else \
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
83 print_usage (); \
4015
6476dd85a65f [project @ 2002-08-02 07:59:19 by jwe]
jwe
parents: 3972
diff changeset
84 \
6476dd85a65f [project @ 2002-08-02 07:59:19 by jwe]
jwe
parents: 3972
diff changeset
85 return retval
6476dd85a65f [project @ 2002-08-02 07:59:19 by jwe]
jwe
parents: 3972
diff changeset
86
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1940
diff changeset
87 DEFUN (all, args, ,
3369
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
88 "-*- texinfo -*-\n\
4015
6476dd85a65f [project @ 2002-08-02 07:59:19 by jwe]
jwe
parents: 3972
diff changeset
89 @deftypefn {Built-in Function} {} all (@var{x}, @var{dim})\n\
3369
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
90 The function @code{all} behaves like the function @code{any}, except\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
91 that it returns true only if all the elements of a vector, or all the\n\
4015
6476dd85a65f [project @ 2002-08-02 07:59:19 by jwe]
jwe
parents: 3972
diff changeset
92 elements along dimension @var{dim} of a matrix, are nonzero.\n\
3369
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
93 @end deftypefn")
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
94 {
4015
6476dd85a65f [project @ 2002-08-02 07:59:19 by jwe]
jwe
parents: 3972
diff changeset
95 ANY_ALL (all);
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
96 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
97
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1940
diff changeset
98 DEFUN (any, args, ,
3369
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
99 "-*- texinfo -*-\n\
4015
6476dd85a65f [project @ 2002-08-02 07:59:19 by jwe]
jwe
parents: 3972
diff changeset
100 @deftypefn {Built-in Function} {} any (@var{x}, @var{dim})\n\
3369
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
101 For a vector argument, return 1 if any element of the vector is\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
102 nonzero.\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
103 \n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
104 For a matrix argument, return a row vector of ones and\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
105 zeros with each element indicating whether any of the elements of the\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
106 corresponding column of the matrix are nonzero. For example,\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
107 \n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
108 @example\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
109 @group\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
110 any (eye (2, 4))\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
111 @result{} [ 1, 1, 0, 0 ]\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
112 @end group\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
113 @end example\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
114 \n\
4015
6476dd85a65f [project @ 2002-08-02 07:59:19 by jwe]
jwe
parents: 3972
diff changeset
115 If the optional argument @var{dim} is supplied, work along dimension\n\
6476dd85a65f [project @ 2002-08-02 07:59:19 by jwe]
jwe
parents: 3972
diff changeset
116 @var{dim}. For example,\n\
3369
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
117 \n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
118 @example\n\
4015
6476dd85a65f [project @ 2002-08-02 07:59:19 by jwe]
jwe
parents: 3972
diff changeset
119 @group\n\
6476dd85a65f [project @ 2002-08-02 07:59:19 by jwe]
jwe
parents: 3972
diff changeset
120 any (eye (2, 4), 2)\n\
6476dd85a65f [project @ 2002-08-02 07:59:19 by jwe]
jwe
parents: 3972
diff changeset
121 @result{} [ 1; 1 ]\n\
6476dd85a65f [project @ 2002-08-02 07:59:19 by jwe]
jwe
parents: 3972
diff changeset
122 @end group\n\
3369
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
123 @end example\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
124 @end deftypefn")
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
125 {
4015
6476dd85a65f [project @ 2002-08-02 07:59:19 by jwe]
jwe
parents: 3972
diff changeset
126 ANY_ALL (any);
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
127 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
128
649
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
129 // These mapping functions may also be useful in other places, eh?
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
130
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
131 typedef double (*d_dd_fcn) (double, double);
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
132
7506
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
133 static NDArray
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
134 map_d_m (d_dd_fcn f, double x, const NDArray& y)
649
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
135 {
7506
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
136 NDArray retval (y.dims ());
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
137 double *r_data = retval.fortran_vec ();
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
138
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
139 const double *y_data = y.data ();
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
140
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
141 octave_idx_type nel = y.numel ();
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
142
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
143 for (octave_idx_type i = 0; i < nel; i++)
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
144 {
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
145 OCTAVE_QUIT;
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
146 r_data[i] = f (x, y_data[i]);
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
147 }
649
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
148
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
149 return retval;
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
150 }
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
151
7506
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
152 static NDArray
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
153 map_m_d (d_dd_fcn f, const NDArray& x, double y)
649
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
154 {
7506
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
155 NDArray retval (x.dims ());
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
156 double *r_data = retval.fortran_vec ();
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
157
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
158 const double *x_data = x.data ();
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
159
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
160 octave_idx_type nel = x.numel ();
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
161
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
162 for (octave_idx_type i = 0; i < nel; i++)
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
163 {
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
164 OCTAVE_QUIT;
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
165 r_data[i] = f (x_data[i], y);
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
166 }
649
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
167
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
168 return retval;
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
169 }
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
170
7506
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
171 static NDArray
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
172 map_m_m (d_dd_fcn f, const NDArray& x, const NDArray& y)
649
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
173 {
7506
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
174 assert (x.dims () == y.dims ());
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
175
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
176 NDArray retval (x.dims ());
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
177 double *r_data = retval.fortran_vec ();
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
178
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
179 const double *x_data = x.data ();
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
180 const double *y_data = y.data ();
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
181
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
182 octave_idx_type nel = x.numel ();
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
183
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
184 for (octave_idx_type i = 0; i < nel; i++)
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
185 {
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
186 OCTAVE_QUIT;
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
187 r_data[i] = f (x_data[i], y_data[i]);
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
188 }
649
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
189
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
190 return retval;
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
191 }
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
192
7505
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
193 static SparseMatrix
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
194 map_d_s (d_dd_fcn f, double x, const SparseMatrix& y)
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
195 {
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
196 octave_idx_type nr = y.rows ();
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
197 octave_idx_type nc = y.columns ();
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
198 SparseMatrix retval;
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
199 double f_zero = f (x, 0.);
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
200
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
201 if (f_zero != 0)
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
202 {
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
203 retval = SparseMatrix (nr, nc, f_zero);
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
204
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
205 for (octave_idx_type j = 0; j < nc; j++)
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
206 for (octave_idx_type i = y.cidx (j); i < y.cidx (j+1); i++)
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
207 {
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
208 OCTAVE_QUIT;
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
209 retval.data (y.ridx(i) + j * nr) = f (x, y.data (i));
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
210 }
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
211
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
212 retval.maybe_compress (true);
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
213 }
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
214 else
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
215 {
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
216 octave_idx_type nz = y.nnz ();
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
217 retval = SparseMatrix (nr, nc, nz);
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
218 octave_idx_type ii = 0;
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
219 retval.cidx (ii) = 0;
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
220
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
221 for (octave_idx_type j = 0; j < nc; j++)
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
222 {
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
223 for (octave_idx_type i = y.cidx (j); i < y.cidx (j+1); i++)
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
224 {
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
225 OCTAVE_QUIT;
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
226 double val = f (x, y.data (i));
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
227
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
228 if (val != 0.0)
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
229 {
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
230 retval.data (ii) = val;
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
231 retval.ridx (ii++) = y.ridx (i);
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
232 }
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
233 }
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
234 retval.cidx (j + 1) = ii;
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
235 }
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
236
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
237 retval.maybe_compress (false);
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
238 }
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
239
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
240 return retval;
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
241 }
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
242
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
243 static SparseMatrix
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
244 map_s_d (d_dd_fcn f, const SparseMatrix& x, double y)
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
245 {
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
246 octave_idx_type nr = x.rows ();
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
247 octave_idx_type nc = x.columns ();
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
248 SparseMatrix retval;
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
249 double f_zero = f (0., y);
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
250
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
251 if (f_zero != 0)
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
252 {
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
253 retval = SparseMatrix (nr, nc, f_zero);
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
254
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
255 for (octave_idx_type j = 0; j < nc; j++)
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
256 for (octave_idx_type i = x.cidx (j); i < x.cidx (j+1); i++)
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
257 {
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
258 OCTAVE_QUIT;
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
259 retval.data (x.ridx(i) + j * nr) = f (x.data (i), y);
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
260 }
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
261
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
262 retval.maybe_compress (true);
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
263 }
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
264 else
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
265 {
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
266 octave_idx_type nz = x.nnz ();
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
267 retval = SparseMatrix (nr, nc, nz);
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
268 octave_idx_type ii = 0;
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
269 retval.cidx (ii) = 0;
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
270
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
271 for (octave_idx_type j = 0; j < nc; j++)
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
272 {
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
273 for (octave_idx_type i = x.cidx (j); i < x.cidx (j+1); i++)
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
274 {
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
275 OCTAVE_QUIT;
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
276 double val = f (x.data (i), y);
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
277
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
278 if (val != 0.0)
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
279 {
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
280 retval.data (ii) = val;
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
281 retval.ridx (ii++) = x.ridx (i);
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
282 }
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
283 }
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
284 retval.cidx (j + 1) = ii;
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
285 }
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
286
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
287 retval.maybe_compress (false);
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
288 }
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
289
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
290 return retval;
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
291 }
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
292
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
293 static SparseMatrix
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
294 map_s_s (d_dd_fcn f, const SparseMatrix& x, const SparseMatrix& y)
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
295 {
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
296 octave_idx_type nr = x.rows ();
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
297 octave_idx_type nc = x.columns ();
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
298
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
299 octave_idx_type y_nr = y.rows ();
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
300 octave_idx_type y_nc = y.columns ();
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
301
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
302 assert (nr == y_nr && nc == y_nc);
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
303
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
304 SparseMatrix retval;
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
305 double f_zero = f (0., 0.);
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
306
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
307 if (f_zero != 0)
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
308 {
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
309 retval = SparseMatrix (nr, nc, f_zero);
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
310 octave_idx_type k1 = 0, k2 = 0;
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
311
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
312 for (octave_idx_type j = 0; j < nc; j++)
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
313 {
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
314 while (k1 < x.cidx(j+1) && k2 < y.cidx(j+1))
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
315 {
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
316 OCTAVE_QUIT;
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
317 if (k1 >= x.cidx(j+1))
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
318 {
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
319 retval.data (y.ridx(k2) + j * nr) = f (0.0, y.data (k2));
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
320 k2++;
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
321 }
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
322 else if (k2 >= y.cidx(j+1))
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
323 {
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
324 retval.data (x.ridx(k1) + j * nr) = f (x.data (k1), 0.0);
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
325 k1++;
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
326 }
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
327 else
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
328 {
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
329 octave_idx_type rx = x.ridx(k1);
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
330 octave_idx_type ry = y.ridx(k2);
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
331
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
332 if (rx < ry)
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
333 {
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
334 retval.data (rx + j * nr) = f (x.data (k1), 0.0);
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
335 k1++;
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
336 }
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
337 else if (rx > ry)
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
338 {
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
339 retval.data (ry + j * nr) = f (0.0, y.data (k2));
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
340 k2++;
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
341 }
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
342 else
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
343 {
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
344 retval.data (ry + j * nr) = f (x.data (k1), y.data (k2));
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
345 k1++;
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
346 k2++;
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
347 }
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
348 }
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
349 }
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
350 }
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
351
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
352 retval.maybe_compress (true);
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
353 }
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
354 else
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
355 {
7631
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
356 octave_idx_type nz = x.nnz () + y.nnz ();
7505
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
357 retval = SparseMatrix (nr, nc, nz);
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
358 octave_idx_type ii = 0;
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
359 retval.cidx (ii) = 0;
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
360 octave_idx_type k1 = 0, k2 = 0;
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
361
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
362 for (octave_idx_type j = 0; j < nc; j++)
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
363 {
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
364 while (k1 < x.cidx(j+1) && k2 < y.cidx(j+1))
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
365 {
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
366 OCTAVE_QUIT;
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
367 double val;
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
368 octave_idx_type r;
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
369 if (k1 >= x.cidx(j+1))
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
370 {
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
371 r = y.ridx (k2);
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
372 val = f (0.0, y.data (k2++));
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
373 }
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
374 else if (k2 >= y.cidx(j+1))
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
375 {
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
376 r = x.ridx (k1);
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
377 val = f (x.data (k1++), 0.0);
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
378 }
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
379 else
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
380 {
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
381 octave_idx_type rx = x.ridx(k1);
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
382 octave_idx_type ry = y.ridx(k2);
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
383
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
384 if (rx < ry)
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
385 {
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
386 r = x.ridx (k1);
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
387 val = f (x.data (k1++), 0.0);
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
388 }
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
389 else if (rx > ry)
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
390 {
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
391 r = y.ridx (k2);
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
392 val = f (0.0, y.data (k2++));
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
393 }
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
394 else
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
395 {
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
396 r = y.ridx (k2);
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
397 val = f (x.data (k1++), y.data (k2++));
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
398 }
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
399 }
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
400 if (val != 0.0)
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
401 {
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
402 retval.data (ii) = val;
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
403 retval.ridx (ii++) = r;
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
404 }
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
405 }
7631
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
406 retval.cidx (j + 1) = ii;
7505
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
407 }
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
408
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
409 retval.maybe_compress (false);
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
410 }
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
411
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
412 return retval;
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
413 }
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
414
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1940
diff changeset
415 DEFUN (atan2, args, ,
3428
5b77cf82393c [project @ 2000-01-14 02:54:53 by jwe]
jwe
parents: 3418
diff changeset
416 "-*- texinfo -*-\n\
5b77cf82393c [project @ 2000-01-14 02:54:53 by jwe]
jwe
parents: 3418
diff changeset
417 @deftypefn {Mapping Function} {} atan2 (@var{y}, @var{x})\n\
5b77cf82393c [project @ 2000-01-14 02:54:53 by jwe]
jwe
parents: 3418
diff changeset
418 Compute atan (@var{y} / @var{x}) for corresponding elements of @var{y}\n\
5b77cf82393c [project @ 2000-01-14 02:54:53 by jwe]
jwe
parents: 3418
diff changeset
419 and @var{x}. The result is in range -pi to pi.\n\
3439
3234a698073a [project @ 2000-01-14 09:51:14 by jwe]
jwe
parents: 3428
diff changeset
420 @end deftypefn")
649
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
421 {
4233
ccfdb55c8156 [project @ 2002-12-20 22:43:54 by jwe]
jwe
parents: 4176
diff changeset
422 octave_value retval;
649
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
423
712
36ba0576bd1b [project @ 1994-09-19 14:18:15 by jwe]
jwe
parents: 649
diff changeset
424 int nargin = args.length ();
36ba0576bd1b [project @ 1994-09-19 14:18:15 by jwe]
jwe
parents: 649
diff changeset
425
36ba0576bd1b [project @ 1994-09-19 14:18:15 by jwe]
jwe
parents: 649
diff changeset
426 if (nargin == 2 && args(0).is_defined () && args(1).is_defined ())
649
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
427 {
7506
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
428 if (args(0).is_integer_type () || args(1).is_integer_type ())
7494
bd2bd04e68ca Treat integer types for mod/rem correctly
David Bateman <dbateman@free.fr>
parents: 7433
diff changeset
429 error ("atan2: not defined for integer types");
bd2bd04e68ca Treat integer types for mod/rem correctly
David Bateman <dbateman@free.fr>
parents: 7433
diff changeset
430 else
649
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
431 {
7494
bd2bd04e68ca Treat integer types for mod/rem correctly
David Bateman <dbateman@free.fr>
parents: 7433
diff changeset
432 octave_value arg_y = args(0);
bd2bd04e68ca Treat integer types for mod/rem correctly
David Bateman <dbateman@free.fr>
parents: 7433
diff changeset
433 octave_value arg_x = args(1);
bd2bd04e68ca Treat integer types for mod/rem correctly
David Bateman <dbateman@free.fr>
parents: 7433
diff changeset
434
7506
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
435 dim_vector y_dims = arg_y.dims ();
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
436 dim_vector x_dims = arg_x.dims ();
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
437
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
438 bool y_is_scalar = y_dims.all_ones ();
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
439 bool x_is_scalar = x_dims.all_ones ();
7494
bd2bd04e68ca Treat integer types for mod/rem correctly
David Bateman <dbateman@free.fr>
parents: 7433
diff changeset
440
bd2bd04e68ca Treat integer types for mod/rem correctly
David Bateman <dbateman@free.fr>
parents: 7433
diff changeset
441 if (y_is_scalar && x_is_scalar)
649
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
442 {
7494
bd2bd04e68ca Treat integer types for mod/rem correctly
David Bateman <dbateman@free.fr>
parents: 7433
diff changeset
443 double y = arg_y.double_value ();
649
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
444
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
445 if (! error_state)
7494
bd2bd04e68ca Treat integer types for mod/rem correctly
David Bateman <dbateman@free.fr>
parents: 7433
diff changeset
446 {
bd2bd04e68ca Treat integer types for mod/rem correctly
David Bateman <dbateman@free.fr>
parents: 7433
diff changeset
447 double x = arg_x.double_value ();
bd2bd04e68ca Treat integer types for mod/rem correctly
David Bateman <dbateman@free.fr>
parents: 7433
diff changeset
448
bd2bd04e68ca Treat integer types for mod/rem correctly
David Bateman <dbateman@free.fr>
parents: 7433
diff changeset
449 if (! error_state)
bd2bd04e68ca Treat integer types for mod/rem correctly
David Bateman <dbateman@free.fr>
parents: 7433
diff changeset
450 retval = atan2 (y, x);
bd2bd04e68ca Treat integer types for mod/rem correctly
David Bateman <dbateman@free.fr>
parents: 7433
diff changeset
451 }
649
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
452 }
7494
bd2bd04e68ca Treat integer types for mod/rem correctly
David Bateman <dbateman@free.fr>
parents: 7433
diff changeset
453 else if (y_is_scalar)
649
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
454 {
7494
bd2bd04e68ca Treat integer types for mod/rem correctly
David Bateman <dbateman@free.fr>
parents: 7433
diff changeset
455 double y = arg_y.double_value ();
649
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
456
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
457 if (! error_state)
7494
bd2bd04e68ca Treat integer types for mod/rem correctly
David Bateman <dbateman@free.fr>
parents: 7433
diff changeset
458 {
7515
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
459 // Even if x is sparse return a full matrix here
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
460 NDArray x = arg_x.array_value ();
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
461
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
462 if (! error_state)
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
463 retval = map_d_m (atan2, y, x);
7494
bd2bd04e68ca Treat integer types for mod/rem correctly
David Bateman <dbateman@free.fr>
parents: 7433
diff changeset
464 }
649
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
465 }
7494
bd2bd04e68ca Treat integer types for mod/rem correctly
David Bateman <dbateman@free.fr>
parents: 7433
diff changeset
466 else if (x_is_scalar)
649
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
467 {
7505
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
468 if (arg_y.is_sparse_type ())
7494
bd2bd04e68ca Treat integer types for mod/rem correctly
David Bateman <dbateman@free.fr>
parents: 7433
diff changeset
469 {
7505
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
470 SparseMatrix y = arg_y.sparse_matrix_value ();
7494
bd2bd04e68ca Treat integer types for mod/rem correctly
David Bateman <dbateman@free.fr>
parents: 7433
diff changeset
471
bd2bd04e68ca Treat integer types for mod/rem correctly
David Bateman <dbateman@free.fr>
parents: 7433
diff changeset
472 if (! error_state)
7505
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
473 {
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
474 double x = arg_x.double_value ();
7515
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
475
7505
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
476 if (! error_state)
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
477 retval = map_s_d (atan2, y, x);
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
478 }
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
479 }
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
480 else
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
481 {
7506
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
482 NDArray y = arg_y.array_value ();
7505
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
483
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
484 if (! error_state)
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
485 {
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
486 double x = arg_x.double_value ();
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
487
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
488 if (! error_state)
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
489 retval = map_m_d (atan2, y, x);
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
490 }
7494
bd2bd04e68ca Treat integer types for mod/rem correctly
David Bateman <dbateman@free.fr>
parents: 7433
diff changeset
491 }
649
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
492 }
7506
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
493 else if (y_dims == x_dims)
649
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
494 {
7515
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
495 // Even if y is sparse return a full matrix here
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
496 if (arg_x.is_sparse_type ())
7494
bd2bd04e68ca Treat integer types for mod/rem correctly
David Bateman <dbateman@free.fr>
parents: 7433
diff changeset
497 {
7505
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
498 SparseMatrix y = arg_y.sparse_matrix_value ();
7494
bd2bd04e68ca Treat integer types for mod/rem correctly
David Bateman <dbateman@free.fr>
parents: 7433
diff changeset
499
bd2bd04e68ca Treat integer types for mod/rem correctly
David Bateman <dbateman@free.fr>
parents: 7433
diff changeset
500 if (! error_state)
7505
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
501 {
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
502 SparseMatrix x = arg_x.sparse_matrix_value ();
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
503
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
504 if (! error_state)
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
505 retval = map_s_s (atan2, y, x);
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
506 }
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
507 }
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
508 else
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
509 {
7506
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
510 NDArray y = arg_y.array_value ();
7505
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
511
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
512 if (! error_state)
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
513 {
7506
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
514 NDArray x = arg_x.array_value ();
7505
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
515
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
516 if (! error_state)
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
517 retval = map_m_m (atan2, y, x);
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
518 }
7494
bd2bd04e68ca Treat integer types for mod/rem correctly
David Bateman <dbateman@free.fr>
parents: 7433
diff changeset
519 }
649
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
520 }
7494
bd2bd04e68ca Treat integer types for mod/rem correctly
David Bateman <dbateman@free.fr>
parents: 7433
diff changeset
521 else
bd2bd04e68ca Treat integer types for mod/rem correctly
David Bateman <dbateman@free.fr>
parents: 7433
diff changeset
522 error ("atan2: nonconformant matrices");
649
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
523 }
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
524 }
712
36ba0576bd1b [project @ 1994-09-19 14:18:15 by jwe]
jwe
parents: 649
diff changeset
525 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
526 print_usage ();
649
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
527
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
528 return retval;
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
529 }
1a674dba2e9e [project @ 1994-08-24 15:47:23 by jwe]
jwe
parents: 648
diff changeset
530
7506
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
531 /*
7741
72c0489653ac fix tests
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
532 %!assert (size (atan2 (zeros (0, 2), zeros (0, 2))), [0, 2])
72c0489653ac fix tests
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
533 %!assert (size (atan2 (rand (2, 3, 4), zeros (2, 3, 4))), [2, 3, 4])
72c0489653ac fix tests
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
534 %!assert (size (atan2 (rand (2, 3, 4), 1)), [2, 3, 4])
72c0489653ac fix tests
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
535 %!assert (size (atan2 (1, rand (2, 3, 4))), [2, 3, 4])
72c0489653ac fix tests
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
536 %!assert (size (atan2 (1, 2)), [1, 1])
7506
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
537 */
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
538
7631
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
539 DEFUN (hypot, args, ,
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
540 "-*- texinfo -*-\n\
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
541 @deftypefn {Mapping Function} {} hypot (@var{x}, @var{y})\n\
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
542 Compute square-root of the squares of @var{x} and @var{y}\n\
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
543 element-by-element. This equivalent to @code{sqrt (@var{x}.^ 2 + @var{y}\n\
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
544 .^ 2)}, but calculated in a manner that avoids overflows for large\n\
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
545 values of @var{x} or @var{y}.\n\
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
546 @end deftypefn")
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
547 {
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
548 octave_value retval;
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
549
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
550 int nargin = args.length ();
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
551
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
552 if (nargin == 2 && args(0).is_defined () && args(1).is_defined ())
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
553 {
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
554 if (args(0).is_integer_type () || args(1).is_integer_type ())
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
555 error ("hypot: not defined for integer types");
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
556 else
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
557 {
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
558 octave_value arg_x = args(0);
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
559 octave_value arg_y = args(1);
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
560
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
561 dim_vector x_dims = arg_x.dims ();
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
562 dim_vector y_dims = arg_y.dims ();
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
563
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
564 bool x_is_scalar = x_dims.all_ones ();
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
565 bool y_is_scalar = y_dims.all_ones ();
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
566
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
567 if (y_is_scalar && x_is_scalar)
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
568 {
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
569 double x;
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
570 if (arg_x.is_complex_type ())
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
571 x = abs (arg_x.complex_value ());
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
572 else
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
573 x = arg_x.double_value ();
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
574
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
575 if (! error_state)
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
576 {
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
577 double y;
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
578 if (arg_y.is_complex_type ())
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
579 y = abs (arg_y.complex_value ());
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
580 else
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
581 y = arg_y.double_value ();
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
582
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
583 if (! error_state)
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
584 retval = hypot (x, y);
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
585 }
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
586 }
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
587 else if (y_is_scalar)
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
588 {
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
589 NDArray x;
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
590 if (arg_x.is_complex_type ())
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
591 x = arg_x.complex_array_value ().abs ();
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
592 else
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
593 x = arg_x.array_value ();
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
594
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
595 if (! error_state)
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
596 {
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
597 double y;
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
598 if (arg_y.is_complex_type ())
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
599 y = abs (arg_y.complex_value ());
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
600 else
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
601 y = arg_y.double_value ();
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
602
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
603 if (! error_state)
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
604 retval = map_m_d (hypot, x, y);
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
605 }
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
606 }
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
607 else if (x_is_scalar)
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
608 {
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
609 double x;
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
610 if (arg_x.is_complex_type ())
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
611 x = abs (arg_x.complex_value ());
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
612 else
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
613 x = arg_x.double_value ();
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
614
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
615 if (! error_state)
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
616 {
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
617 NDArray y;
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
618 if (arg_y.is_complex_type ())
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
619 y = arg_y.complex_array_value ().abs ();
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
620 else
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
621 y = arg_y.array_value ();
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
622
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
623 if (! error_state)
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
624 retval = map_d_m (hypot, x, y);
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
625 }
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
626 }
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
627 else if (y_dims == x_dims)
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
628 {
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
629 if (arg_x.is_sparse_type () && arg_y.is_sparse_type ())
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
630 {
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
631 SparseMatrix x;
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
632 if (arg_x.is_complex_type ())
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
633 x = arg_x.sparse_complex_matrix_value ().abs ();
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
634 else
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
635 x = arg_x.sparse_matrix_value ();
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
636
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
637 if (! error_state)
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
638 {
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
639 SparseMatrix y;
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
640 if (arg_y.is_complex_type ())
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
641 y = arg_y.sparse_complex_matrix_value ().abs ();
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
642 else
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
643 y = arg_y.sparse_matrix_value ();
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
644
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
645 if (! error_state)
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
646 retval = map_s_s (hypot, x, y);
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
647 }
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
648 }
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
649 else
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
650 {
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
651 NDArray x;
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
652 if (arg_x.is_complex_type ())
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
653 x = arg_x.complex_array_value ().abs ();
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
654 else
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
655 x = arg_x.array_value ();
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
656
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
657 if (! error_state)
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
658 {
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
659 NDArray y;
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
660 if (arg_y.is_complex_type ())
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
661 y = arg_y.complex_array_value ().abs ();
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
662 else
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
663 y = arg_y.array_value ();
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
664
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
665 if (! error_state)
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
666 retval = map_m_m (hypot, x, y);
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
667 }
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
668 }
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
669 }
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
670 else
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
671 error ("hypot: nonconformant matrices");
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
672 }
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
673 }
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
674 else
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
675 print_usage ();
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
676
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
677 return retval;
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
678 }
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
679
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
680 /*
7741
72c0489653ac fix tests
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
681 %!assert (size (hypot (zeros (0, 2), zeros (0, 2))), [0, 2])
72c0489653ac fix tests
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
682 %!assert (size (hypot (rand (2, 3, 4), zeros (2, 3, 4))), [2, 3, 4])
72c0489653ac fix tests
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
683 %!assert (size (hypot (rand (2, 3, 4), 1)), [2, 3, 4])
72c0489653ac fix tests
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
684 %!assert (size (hypot (1, rand (2, 3, 4))), [2, 3, 4])
72c0489653ac fix tests
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
685 %!assert (size (hypot (1, 2)), [1, 1])
72c0489653ac fix tests
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
686 %!assert (hypot (1:10, 1:10), sqrt(2) * [1:10], 16*eps)
7631
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
687 */
b2a5cda5c549 Add the hypot function
David Bateman <dbateman@free.fr>
parents: 7623
diff changeset
688
7740
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7631
diff changeset
689 template<typename T, typename ET>
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7631
diff changeset
690 void
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7631
diff changeset
691 map_2_xlog2 (const Array<T>& x, Array<T>& f, Array<ET>& e)
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7631
diff changeset
692 {
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7631
diff changeset
693 f = Array<T>(x.dims ());
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7631
diff changeset
694 e = Array<ET>(x.dims ());
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7631
diff changeset
695 for (octave_idx_type i = 0; i < x.numel (); i++)
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7631
diff changeset
696 {
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7631
diff changeset
697 int exp;
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7631
diff changeset
698 f.xelem (i) = xlog2 (x(i), exp);
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7631
diff changeset
699 e.xelem (i) = exp;
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7631
diff changeset
700 }
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7631
diff changeset
701 }
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7631
diff changeset
702
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7631
diff changeset
703 DEFUN (log2, args, nargout,
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7631
diff changeset
704 "-*- texinfo -*-\n\
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7631
diff changeset
705 @deftypefn {Mapping Function} {} log2 (@var{x})\n\
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7631
diff changeset
706 @deftypefnx {Mapping Function} {[@var{f}, @var{e}] = } log2 (@var{x})\n\
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7631
diff changeset
707 Compute the base-2 logarithm for each element of @var{x}.\n\
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7631
diff changeset
708 If called with two output arguments, split @var{x} to\n\
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7631
diff changeset
709 binary mantissa and exponent so that @code{1/2 <= abs(f) < 1} and\n\
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7631
diff changeset
710 @var{e} is an integer. If @code{x = 0}, @code{f = e = 0}.\n\
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7631
diff changeset
711 @seealso{log, log10, log2, exp}\n\
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7631
diff changeset
712 @end deftypefn")
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7631
diff changeset
713 {
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7631
diff changeset
714 octave_value_list retval;
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7631
diff changeset
715
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7631
diff changeset
716 if (args.length () == 1)
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7631
diff changeset
717 {
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7631
diff changeset
718 if (nargout < 2)
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7631
diff changeset
719 retval(0) = args(0).log2 ();
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7631
diff changeset
720 else if (args(0).is_real_type ())
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7631
diff changeset
721 {
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7631
diff changeset
722 NDArray f;
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7631
diff changeset
723 NDArray x = args(0).array_value ();
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7631
diff changeset
724 // FIXME -- should E be an int value?
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7631
diff changeset
725 Matrix e;
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7631
diff changeset
726 map_2_xlog2 (x, f, e);
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7631
diff changeset
727 retval (1) = e;
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7631
diff changeset
728 retval (0) = f;
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7631
diff changeset
729 }
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7631
diff changeset
730 else if (args(0).is_complex_type ())
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7631
diff changeset
731 {
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7631
diff changeset
732 ComplexNDArray f;
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7631
diff changeset
733 ComplexNDArray x = args(0).complex_array_value ();
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7631
diff changeset
734 // FIXME -- should E be an int value?
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7631
diff changeset
735 NDArray e;
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7631
diff changeset
736 map_2_xlog2 (x, f, e);
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7631
diff changeset
737 retval (1) = e;
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7631
diff changeset
738 retval (0) = f;
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7631
diff changeset
739 }
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7631
diff changeset
740 else
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7631
diff changeset
741 gripe_wrong_type_arg ("log2", args(0));
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7631
diff changeset
742 }
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7631
diff changeset
743 else
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7631
diff changeset
744 print_usage ();
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7631
diff changeset
745
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7631
diff changeset
746 return retval;
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7631
diff changeset
747 }
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7631
diff changeset
748
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7631
diff changeset
749 /*
7741
72c0489653ac fix tests
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
750 %!assert(log2 ([1/4, 1/2, 1, 2, 4]), [-2, -1, 0, 1, 2]);
72c0489653ac fix tests
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
751 %!assert(log2(Inf), Inf);
72c0489653ac fix tests
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
752 %!assert(isnan(log2(NaN)));
72c0489653ac fix tests
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
753 %!assert(log2(4*i), 2 + log2(1*i));
72c0489653ac fix tests
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
754 %!assert(log2(complex(0,Inf)), Inf + log2(i));
72c0489653ac fix tests
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
755
7740
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7631
diff changeset
756 %!test
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7631
diff changeset
757 %! [f, e] = log2 ([0,-1; 2,-4; Inf,-Inf]);
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7631
diff changeset
758 %! assert (f, [0,-0.5; 0.5,-0.5; Inf,-Inf]);
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7631
diff changeset
759 %! assert (e, [0,1;2,3;0,0])
7741
72c0489653ac fix tests
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
760
7740
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7631
diff changeset
761 %!test
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7631
diff changeset
762 %! [f, e] = log2 (complex (zeros (3, 2), [0,-1; 2,-4; Inf,-Inf]));
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7631
diff changeset
763 %! assert (f, complex (zeros (3, 2), [0,-0.5; 0.5,-0.5; Inf,-Inf]));
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7631
diff changeset
764 %! assert (e, [0,1; 2,3; 0,0]);
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7631
diff changeset
765 */
39930366b709 implement builtin log2
Jaroslav Hajek <highegg@gmail.com>
parents: 7631
diff changeset
766
4311
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
767 DEFUN (fmod, args, ,
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
768 "-*- texinfo -*-\n\
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
769 @deftypefn {Mapping Function} {} fmod (@var{x}, @var{y})\n\
4685
14a1c9f42f67 [project @ 2004-01-06 17:20:02 by jwe]
jwe
parents: 4593
diff changeset
770 Compute the floating point remainder of dividing @var{x} by @var{y}\n\
14a1c9f42f67 [project @ 2004-01-06 17:20:02 by jwe]
jwe
parents: 4593
diff changeset
771 using the C library function @code{fmod}. The result has the same\n\
7505
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
772 sign as @var{x}. If @var{y} is zero, the result is implementation-defined.\n\
4311
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
773 @end deftypefn")
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
774 {
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
775 octave_value retval;
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
776
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
777 int nargin = args.length ();
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
778
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
779 if (nargin == 2 && args(0).is_defined () && args(1).is_defined ())
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
780 {
7506
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
781 octave_value arg_y = args(0);
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
782 octave_value arg_x = args(1);
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
783
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
784 dim_vector y_dims = arg_y.dims ();
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
785 dim_vector x_dims = arg_x.dims ();
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
786
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
787 bool y_is_scalar = y_dims.all_ones ();
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
788 bool x_is_scalar = x_dims.all_ones ();
4311
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
789
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
790 if (y_is_scalar && x_is_scalar)
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
791 {
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
792 double y = arg_y.double_value ();
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
793
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
794 if (! error_state)
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
795 {
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
796 double x = arg_x.double_value ();
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
797
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
798 if (! error_state)
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
799 retval = fmod (x, y);
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
800 }
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
801 }
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
802 else if (y_is_scalar)
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
803 {
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
804 double y = arg_y.double_value ();
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
805
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
806 if (! error_state)
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
807 {
7505
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
808 if (arg_x.is_sparse_type ())
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
809 {
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
810 SparseMatrix x = arg_x.sparse_matrix_value ();
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
811
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
812 if (! error_state)
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
813 retval = map_s_d (fmod, x, y);
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
814 }
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
815 else
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
816 {
7506
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
817 NDArray x = arg_x.array_value ();
7505
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
818
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
819 if (! error_state)
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
820 retval = map_m_d (fmod, x, y);
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
821 }
4311
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
822 }
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
823 }
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
824 else if (x_is_scalar)
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
825 {
7505
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
826 if (arg_y.is_sparse_type ())
4311
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
827 {
7505
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
828 SparseMatrix y = arg_y.sparse_matrix_value ();
4311
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
829
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
830 if (! error_state)
7505
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
831 {
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
832 double x = arg_x.double_value ();
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
833
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
834 if (! error_state)
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
835 retval = map_d_s (fmod, x, y);
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
836 }
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
837 }
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
838 else
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
839 {
7506
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
840 NDArray y = arg_y.array_value ();
7505
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
841
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
842 if (! error_state)
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
843 {
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
844 double x = arg_x.double_value ();
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
845
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
846 if (! error_state)
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
847 retval = map_d_m (fmod, x, y);
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
848 }
4311
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
849 }
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
850 }
7506
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
851 else if (y_dims == x_dims)
4311
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
852 {
7505
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
853 if (arg_y.is_sparse_type () || arg_x.is_sparse_type ())
4311
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
854 {
7505
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
855 SparseMatrix y = arg_y.sparse_matrix_value ();
4311
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
856
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
857 if (! error_state)
7505
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
858 {
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
859 SparseMatrix x = arg_x.sparse_matrix_value ();
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
860
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
861 if (! error_state)
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
862 retval = map_s_s (fmod, x, y);
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
863 }
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
864 }
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
865 else
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
866 {
7506
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
867 NDArray y = arg_y.array_value ();
7505
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
868
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
869 if (! error_state)
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
870 {
7506
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
871 NDArray x = arg_x.array_value ();
7505
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
872
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
873 if (! error_state)
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
874 retval = map_m_m (fmod, x, y);
f5005d9510f4 Remove dispatched sparse functions and treat in the generic versions of the functions
David Bateman <dbateman@free.fr>
parents: 7494
diff changeset
875 }
4311
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
876 }
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
877 }
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
878 else
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
879 error ("fmod: nonconformant matrices");
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
880 }
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
881 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
882 print_usage ();
4311
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
883
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
884 return retval;
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
885 }
a9e0bff33b02 [project @ 2003-01-30 04:11:58 by jwe]
jwe
parents: 4303
diff changeset
886
7506
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
887 /*
7741
72c0489653ac fix tests
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
888 %!assert (size (fmod (zeros (0, 2), zeros (0, 2))), [0, 2])
72c0489653ac fix tests
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
889 %!assert (size (fmod (rand (2, 3, 4), zeros (2, 3, 4))), [2, 3, 4])
7743
fbe27e477578 more tests fixed
John W. Eaton <jwe@octave.org>
parents: 7741
diff changeset
890 %!assert (size (fmod (rand (2, 3, 4), 1)), [2, 3, 4])
fbe27e477578 more tests fixed
John W. Eaton <jwe@octave.org>
parents: 7741
diff changeset
891 %!assert (size (fmod (1, rand (2, 3, 4))), [2, 3, 4])
fbe27e477578 more tests fixed
John W. Eaton <jwe@octave.org>
parents: 7741
diff changeset
892 %!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
893 */
798b0a00e80c atan2, fmod: accept N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7505
diff changeset
894
7112
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
895 #define NATIVE_REDUCTION_1(FCN, TYPE, DIM) \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
896 (arg.is_ ## TYPE ## _type ()) \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
897 { \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
898 TYPE ## NDArray tmp = arg. TYPE ##_array_value (); \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
899 \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
900 if (! error_state) \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
901 retval = tmp.FCN (DIM); \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
902 }
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
903
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
904 #define NATIVE_REDUCTION(FCN) \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
905 \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
906 octave_value retval; \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
907 \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
908 int nargin = args.length (); \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
909 \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
910 bool isnative = false; \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
911 \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
912 if (nargin > 1 && args(nargin - 1).is_string ()) \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
913 { \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
914 std::string str = args(nargin - 1).string_value (); \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
915 \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
916 if (! error_state) \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
917 { \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
918 if (str == "native") \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
919 isnative = true; \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
920 else if (str != "double") /* Ignore double as no single type */ \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
921 error ("sum: unrecognized string argument"); \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
922 nargin --; \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
923 } \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
924 } \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
925 \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
926 if (nargin == 1 || nargin == 2) \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
927 { \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
928 octave_value arg = args(0); \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
929 \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
930 int dim = (nargin == 1 ? -1 : args(1).int_value (true) - 1); \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
931 \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
932 if (! error_state) \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
933 { \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
934 if (dim >= -1) \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
935 { \
7515
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
936 if (arg.is_sparse_type ()) \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
937 { \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
938 if (arg.is_real_type ()) \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
939 { \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
940 SparseMatrix tmp = arg.sparse_matrix_value (); \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
941 \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
942 if (! error_state) \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
943 retval = tmp.FCN (dim); \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
944 } \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
945 else \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
946 { \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
947 SparseComplexMatrix tmp = arg.sparse_complex_matrix_value (); \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
948 \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
949 if (! error_state) \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
950 retval = tmp.FCN (dim); \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
951 } \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
952 } \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
953 else \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
954 { \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
955 if (isnative) \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
956 { \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
957 if NATIVE_REDUCTION_1 (FCN, uint8, dim) \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
958 else if NATIVE_REDUCTION_1 (FCN, uint16, dim) \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
959 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
960 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
961 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
962 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
963 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
964 else if NATIVE_REDUCTION_1 (FCN, int64, dim) \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
965 else if NATIVE_REDUCTION_1 (FCN, bool, dim) \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
966 else if (arg.is_char_matrix ()) \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
967 { \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
968 error (#FCN, ": invalid char type"); \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
969 } \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
970 else if (arg.is_complex_type ()) \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
971 { \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
972 ComplexNDArray tmp = arg.complex_array_value (); \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
973 \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
974 if (! error_state) \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
975 retval = tmp.FCN (dim); \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
976 } \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
977 else if (arg.is_real_type ()) \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
978 { \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
979 NDArray tmp = arg.array_value (); \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
980 \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
981 if (! error_state) \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
982 retval = tmp.FCN (dim); \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
983 } \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
984 else \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
985 { \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
986 gripe_wrong_type_arg (#FCN, arg); \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
987 return retval; \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
988 } \
7112
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
989 } \
7515
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
990 else if (arg.is_real_type ()) \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
991 { \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
992 NDArray tmp = arg.array_value (); \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
993 \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
994 if (! error_state) \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
995 retval = tmp.FCN (dim); \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
996 } \
7112
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
997 else if (arg.is_complex_type ()) \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
998 { \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
999 ComplexNDArray tmp = arg.complex_array_value (); \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
1000 \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
1001 if (! error_state) \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
1002 retval = tmp.FCN (dim); \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
1003 } \
7515
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
1004 else \
7112
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
1005 { \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
1006 gripe_wrong_type_arg (#FCN, arg); \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
1007 return retval; \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
1008 } \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
1009 } \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
1010 } \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
1011 else \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
1012 error (#FCN ": invalid dimension argument = %d", dim + 1); \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
1013 } \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
1014 \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
1015 } \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
1016 else \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
1017 print_usage (); \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
1018 \
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
1019 return retval
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
1020
3723
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
1021 #define DATA_REDUCTION(FCN) \
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
1022 \
4233
ccfdb55c8156 [project @ 2002-12-20 22:43:54 by jwe]
jwe
parents: 4176
diff changeset
1023 octave_value retval; \
3723
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
1024 \
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
1025 int nargin = args.length (); \
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
1026 \
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
1027 if (nargin == 1 || nargin == 2) \
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
1028 { \
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
1029 octave_value arg = args(0); \
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
1030 \
3864
e78705239df5 [project @ 2001-11-16 12:56:20 by jwe]
jwe
parents: 3797
diff changeset
1031 int dim = (nargin == 1 ? -1 : args(1).int_value (true) - 1); \
3723
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
1032 \
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
1033 if (! error_state) \
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
1034 { \
4556
773a21e4fce8 [project @ 2003-10-28 05:02:10 by jwe]
jwe
parents: 4554
diff changeset
1035 if (dim >= -1) \
3723
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
1036 { \
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
1037 if (arg.is_real_type ()) \
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
1038 { \
7515
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
1039 if (arg.is_sparse_type ()) \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
1040 { \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
1041 SparseMatrix tmp = arg.sparse_matrix_value (); \
3723
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
1042 \
7515
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
1043 if (! error_state) \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
1044 retval = tmp.FCN (dim); \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
1045 } \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
1046 else \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
1047 { \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
1048 NDArray tmp = arg.array_value (); \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
1049 \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
1050 if (! error_state) \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
1051 retval = tmp.FCN (dim); \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
1052 } \
3723
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
1053 } \
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
1054 else if (arg.is_complex_type ()) \
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
1055 { \
7515
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
1056 if (arg.is_sparse_type ()) \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
1057 { \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
1058 SparseComplexMatrix tmp = arg.sparse_complex_matrix_value (); \
3723
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
1059 \
7515
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
1060 if (! error_state) \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
1061 retval = tmp.FCN (dim); \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
1062 } \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
1063 else \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
1064 { \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
1065 ComplexNDArray tmp = arg.complex_array_value (); \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
1066 \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
1067 if (! error_state) \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
1068 retval = tmp.FCN (dim); \
f3c00dc0912b Eliminate the rest of the dispatched sparse functions
David Bateman <dbateman@free.fr>
parents: 7506
diff changeset
1069 } \
3723
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
1070 } \
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
1071 else \
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
1072 { \
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
1073 gripe_wrong_type_arg (#FCN, arg); \
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
1074 return retval; \
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
1075 } \
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
1076 } \
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
1077 else \
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
1078 error (#FCN ": invalid dimension argument = %d", dim + 1); \
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
1079 } \
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
1080 } \
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
1081 else \
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
1082 print_usage (); \
3723
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
1083 \
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
1084 return retval
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
1085
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1940
diff changeset
1086 DEFUN (cumprod, args, ,
3428
5b77cf82393c [project @ 2000-01-14 02:54:53 by jwe]
jwe
parents: 3418
diff changeset
1087 "-*- texinfo -*-\n\
3723
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
1088 @deftypefn {Built-in Function} {} cumprod (@var{x}, @var{dim})\n\
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
1089 Cumulative product of elements along dimension @var{dim}. If\n\
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
1090 @var{dim} is omitted, it defaults to 1 (column-wise cumulative\n\
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
1091 products).\n\
5061
4689ee5e88ec [project @ 2004-11-03 21:23:42 by jwe]
jwe
parents: 5058
diff changeset
1092 \n\
4689ee5e88ec [project @ 2004-11-03 21:23:42 by jwe]
jwe
parents: 5058
diff changeset
1093 As a special case, if @var{x} is a vector and @var{dim} is omitted,\n\
4689ee5e88ec [project @ 2004-11-03 21:23:42 by jwe]
jwe
parents: 5058
diff changeset
1094 return the cumulative product of the elements as a vector with the\n\
4689ee5e88ec [project @ 2004-11-03 21:23:42 by jwe]
jwe
parents: 5058
diff changeset
1095 same orientation as @var{x}.\n\
3428
5b77cf82393c [project @ 2000-01-14 02:54:53 by jwe]
jwe
parents: 3418
diff changeset
1096 @end deftypefn")
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1097 {
3723
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
1098 DATA_REDUCTION (cumprod);
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1099 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1100
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1940
diff changeset
1101 DEFUN (cumsum, args, ,
3428
5b77cf82393c [project @ 2000-01-14 02:54:53 by jwe]
jwe
parents: 3418
diff changeset
1102 "-*- texinfo -*-\n\
3723
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
1103 @deftypefn {Built-in Function} {} cumsum (@var{x}, @var{dim})\n\
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
1104 Cumulative sum of elements along dimension @var{dim}. If @var{dim}\n\
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
1105 is omitted, it defaults to 1 (column-wise cumulative sums).\n\
5061
4689ee5e88ec [project @ 2004-11-03 21:23:42 by jwe]
jwe
parents: 5058
diff changeset
1106 \n\
4689ee5e88ec [project @ 2004-11-03 21:23:42 by jwe]
jwe
parents: 5058
diff changeset
1107 As a special case, if @var{x} is a vector and @var{dim} is omitted,\n\
4689ee5e88ec [project @ 2004-11-03 21:23:42 by jwe]
jwe
parents: 5058
diff changeset
1108 return the cumulative sum of the elements as a vector with the\n\
4689ee5e88ec [project @ 2004-11-03 21:23:42 by jwe]
jwe
parents: 5058
diff changeset
1109 same orientation as @var{x}.\n\
3428
5b77cf82393c [project @ 2000-01-14 02:54:53 by jwe]
jwe
parents: 3418
diff changeset
1110 @end deftypefn")
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1111 {
3723
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
1112 DATA_REDUCTION (cumsum);
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1113 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1114
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1940
diff changeset
1115 DEFUN (diag, args, ,
3369
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
1116 "-*- texinfo -*-\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
1117 @deftypefn {Built-in Function} {} diag (@var{v}, @var{k})\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
1118 Return a diagonal matrix with vector @var{v} on diagonal @var{k}. The\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
1119 second argument is optional. If it is positive, the vector is placed on\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
1120 the @var{k}-th super-diagonal. If it is negative, it is placed on the\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
1121 @var{-k}-th sub-diagonal. The default value of @var{k} is 0, and the\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
1122 vector is placed on the main diagonal. For example,\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
1123 \n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
1124 @example\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
1125 @group\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
1126 diag ([1, 2, 3], 1)\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
1127 @result{} 0 1 0 0\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
1128 0 0 2 0\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
1129 0 0 0 3\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
1130 0 0 0 0\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
1131 @end group\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
1132 @end example\n\
6772
315bc7c8f9b5 [project @ 2007-07-10 09:51:39 by dbateman]
dbateman
parents: 6688
diff changeset
1133 \n\
315bc7c8f9b5 [project @ 2007-07-10 09:51:39 by dbateman]
dbateman
parents: 6688
diff changeset
1134 @noindent\n\
315bc7c8f9b5 [project @ 2007-07-10 09:51:39 by dbateman]
dbateman
parents: 6688
diff changeset
1135 Given a matrix argument, instead of a vector, @code{diag} extracts the\n\
6774
3b09c87d5165 [project @ 2007-07-13 13:27:36 by dbateman]
dbateman
parents: 6772
diff changeset
1136 @var{k}-th diagonal of the matrix.\n\
3369
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
1137 @end deftypefn")
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1138 {
4233
ccfdb55c8156 [project @ 2002-12-20 22:43:54 by jwe]
jwe
parents: 4176
diff changeset
1139 octave_value retval;
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1140
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1141 int nargin = args.length ();
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1142
712
36ba0576bd1b [project @ 1994-09-19 14:18:15 by jwe]
jwe
parents: 649
diff changeset
1143 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
1144 retval = args(0).diag();
712
36ba0576bd1b [project @ 1994-09-19 14:18:15 by jwe]
jwe
parents: 649
diff changeset
1145 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
1146 {
36594d5bbe13 Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents: 7618
diff changeset
1147 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
1148
36594d5bbe13 Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents: 7618
diff changeset
1149 if (error_state)
36594d5bbe13 Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents: 7618
diff changeset
1150 error ("diag: invalid second argument");
36594d5bbe13 Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents: 7618
diff changeset
1151 else
36594d5bbe13 Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents: 7618
diff changeset
1152 retval = args(0).diag(k);
36594d5bbe13 Move diag function into the octave_value class
David Bateman <dbateman@free.fr>
parents: 7618
diff changeset
1153 }
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1154 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
1155 print_usage ();
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1156
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1157 return retval;
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1158 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1159
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1940
diff changeset
1160 DEFUN (prod, args, ,
3428
5b77cf82393c [project @ 2000-01-14 02:54:53 by jwe]
jwe
parents: 3418
diff changeset
1161 "-*- texinfo -*-\n\
3723
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
1162 @deftypefn {Built-in Function} {} prod (@var{x}, @var{dim})\n\
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
1163 Product of elements along dimension @var{dim}. If @var{dim} is\n\
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
1164 omitted, it defaults to 1 (column-wise products).\n\
5061
4689ee5e88ec [project @ 2004-11-03 21:23:42 by jwe]
jwe
parents: 5058
diff changeset
1165 \n\
4689ee5e88ec [project @ 2004-11-03 21:23:42 by jwe]
jwe
parents: 5058
diff changeset
1166 As a special case, if @var{x} is a vector and @var{dim} is omitted,\n\
4689ee5e88ec [project @ 2004-11-03 21:23:42 by jwe]
jwe
parents: 5058
diff changeset
1167 return the product of the elements.\n\
3428
5b77cf82393c [project @ 2000-01-14 02:54:53 by jwe]
jwe
parents: 3418
diff changeset
1168 @end deftypefn")
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1169 {
3723
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
1170 DATA_REDUCTION (prod);
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1171 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1172
4824
4829055e154f [project @ 2004-03-08 18:16:04 by jwe]
jwe
parents: 4806
diff changeset
1173 static octave_value
4829055e154f [project @ 2004-03-08 18:16:04 by jwe]
jwe
parents: 4806
diff changeset
1174 do_cat (const octave_value_list& args, std::string fname)
4806
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1175 {
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1176 octave_value retval;
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1177
4824
4829055e154f [project @ 2004-03-08 18:16:04 by jwe]
jwe
parents: 4806
diff changeset
1178 int n_args = args.length ();
4806
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1179
5714
24f6a13878c2 [project @ 2006-03-23 21:46:09 by jwe]
jwe
parents: 5677
diff changeset
1180 if (n_args == 1)
24f6a13878c2 [project @ 2006-03-23 21:46:09 by jwe]
jwe
parents: 5677
diff changeset
1181 retval = Matrix ();
24f6a13878c2 [project @ 2006-03-23 21:46:09 by jwe]
jwe
parents: 5677
diff changeset
1182 else if (n_args == 2)
24f6a13878c2 [project @ 2006-03-23 21:46:09 by jwe]
jwe
parents: 5677
diff changeset
1183 retval = args(1);
5507
273612001e3a [project @ 2005-10-26 08:01:24 by dbateman]
dbateman
parents: 5476
diff changeset
1184 else if (n_args > 2)
4824
4829055e154f [project @ 2004-03-08 18:16:04 by jwe]
jwe
parents: 4806
diff changeset
1185 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
1186 octave_idx_type dim = args(0).int_value () - 1;
4806
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1187
4824
4829055e154f [project @ 2004-03-08 18:16:04 by jwe]
jwe
parents: 4806
diff changeset
1188 if (error_state)
4806
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1189 {
4824
4829055e154f [project @ 2004-03-08 18:16:04 by jwe]
jwe
parents: 4806
diff changeset
1190 error ("cat: expecting first argument to be a integer");
4806
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1191 return retval;
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1192 }
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1193
4824
4829055e154f [project @ 2004-03-08 18:16:04 by jwe]
jwe
parents: 4806
diff changeset
1194 if (dim >= 0)
4829055e154f [project @ 2004-03-08 18:16:04 by jwe]
jwe
parents: 4806
diff changeset
1195 {
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4911
diff changeset
1196
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4911
diff changeset
1197 dim_vector dv = args(1).dims ();
4824
4829055e154f [project @ 2004-03-08 18:16:04 by jwe]
jwe
parents: 4806
diff changeset
1198
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4911
diff changeset
1199 for (int i = 2; i < args.length (); i++)
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4911
diff changeset
1200 {
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4911
diff changeset
1201 // add_dims constructs a dimension vector which holds the
4824
4829055e154f [project @ 2004-03-08 18:16:04 by jwe]
jwe
parents: 4806
diff changeset
1202 // dimensions of the final array after concatenation.
4806
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1203
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4911
diff changeset
1204 if (! dv.concat (args(i).dims (), dim))
4806
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1205 {
4824
4829055e154f [project @ 2004-03-08 18:16:04 by jwe]
jwe
parents: 4806
diff changeset
1206 // Dimensions do not match.
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4911
diff changeset
1207 error ("cat: dimension mismatch");
4806
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1208 return retval;
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1209 }
4824
4829055e154f [project @ 2004-03-08 18:16:04 by jwe]
jwe
parents: 4806
diff changeset
1210 }
4829055e154f [project @ 2004-03-08 18:16:04 by jwe]
jwe
parents: 4806
diff changeset
1211
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4911
diff changeset
1212 // The lines below might seem crazy, since we take a copy
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4911
diff changeset
1213 // of the first argument, resize it to be empty and then resize
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4911
diff changeset
1214 // it to be full. This is done since it means that there is no
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4911
diff changeset
1215 // recopying of data, as would happen if we used a single resize.
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4911
diff changeset
1216 // It should be noted that resize operation is also significantly
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4911
diff changeset
1217 // slower than the do_cat_op function, so it makes sense to have an
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4911
diff changeset
1218 // empty matrix and copy all data.
4824
4829055e154f [project @ 2004-03-08 18:16:04 by jwe]
jwe
parents: 4806
diff changeset
1219 //
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4911
diff changeset
1220 // We might also start with a empty octave_value using
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4911
diff changeset
1221 // tmp = octave_value_typeinfo::lookup_type (args(1).type_name());
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4911
diff changeset
1222 // and then directly resize. However, for some types there might be
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4911
diff changeset
1223 // some additional setup needed, and so this should be avoided.
5533
667ad2becb63 [project @ 2005-11-10 21:40:48 by jwe]
jwe
parents: 5507
diff changeset
1224
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4911
diff changeset
1225 octave_value tmp;
5533
667ad2becb63 [project @ 2005-11-10 21:40:48 by jwe]
jwe
parents: 5507
diff changeset
1226
6399
e4d3e9bddff3 [project @ 2007-03-08 21:12:59 by dbateman]
dbateman
parents: 6230
diff changeset
1227 int i;
e4d3e9bddff3 [project @ 2007-03-08 21:12:59 by dbateman]
dbateman
parents: 6230
diff changeset
1228 for (i = 1; i < n_args; i++)
5533
667ad2becb63 [project @ 2005-11-10 21:40:48 by jwe]
jwe
parents: 5507
diff changeset
1229 {
667ad2becb63 [project @ 2005-11-10 21:40:48 by jwe]
jwe
parents: 5507
diff changeset
1230 if (! args (i).all_zero_dims ())
667ad2becb63 [project @ 2005-11-10 21:40:48 by jwe]
jwe
parents: 5507
diff changeset
1231 {
667ad2becb63 [project @ 2005-11-10 21:40:48 by jwe]
jwe
parents: 5507
diff changeset
1232 tmp = args (i);
667ad2becb63 [project @ 2005-11-10 21:40:48 by jwe]
jwe
parents: 5507
diff changeset
1233 break;
667ad2becb63 [project @ 2005-11-10 21:40:48 by jwe]
jwe
parents: 5507
diff changeset
1234 }
667ad2becb63 [project @ 2005-11-10 21:40:48 by jwe]
jwe
parents: 5507
diff changeset
1235 }
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents: 5148
diff changeset
1236
6401
f8cbc0871ed6 [project @ 2007-03-09 15:34:45 by dbateman]
dbateman
parents: 6399
diff changeset
1237 if (i == n_args)
f8cbc0871ed6 [project @ 2007-03-09 15:34:45 by dbateman]
dbateman
parents: 6399
diff changeset
1238 retval = Matrix ();
f8cbc0871ed6 [project @ 2007-03-09 15:34:45 by dbateman]
dbateman
parents: 6399
diff changeset
1239 else
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4911
diff changeset
1240 {
6401
f8cbc0871ed6 [project @ 2007-03-09 15:34:45 by dbateman]
dbateman
parents: 6399
diff changeset
1241 tmp = tmp.resize (dim_vector (0,0)).resize (dv);
4824
4829055e154f [project @ 2004-03-08 18:16:04 by jwe]
jwe
parents: 4806
diff changeset
1242
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4911
diff changeset
1243 if (error_state)
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4911
diff changeset
1244 return retval;
4806
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1245
6883
037c8b622a01 [project @ 2007-09-10 20:13:27 by jwe]
jwe
parents: 6867
diff changeset
1246 int dv_len = dv.length ();
037c8b622a01 [project @ 2007-09-10 20:13:27 by jwe]
jwe
parents: 6867
diff changeset
1247 Array<octave_idx_type> ra_idx (dv_len, 0);
6401
f8cbc0871ed6 [project @ 2007-03-09 15:34:45 by dbateman]
dbateman
parents: 6399
diff changeset
1248
f8cbc0871ed6 [project @ 2007-03-09 15:34:45 by dbateman]
dbateman
parents: 6399
diff changeset
1249 for (int j = i; j < n_args; j++)
f8cbc0871ed6 [project @ 2007-03-09 15:34:45 by dbateman]
dbateman
parents: 6399
diff changeset
1250 {
6887
86e6cf1f998a [project @ 2007-09-11 08:02:09 by dbateman]
dbateman
parents: 6883
diff changeset
1251 if (args (j). dims (). any_zero ())
6883
037c8b622a01 [project @ 2007-09-10 20:13:27 by jwe]
jwe
parents: 6867
diff changeset
1252 continue;
037c8b622a01 [project @ 2007-09-10 20:13:27 by jwe]
jwe
parents: 6867
diff changeset
1253
6401
f8cbc0871ed6 [project @ 2007-03-09 15:34:45 by dbateman]
dbateman
parents: 6399
diff changeset
1254 tmp = do_cat_op (tmp, args (j), ra_idx);
f8cbc0871ed6 [project @ 2007-03-09 15:34:45 by dbateman]
dbateman
parents: 6399
diff changeset
1255
f8cbc0871ed6 [project @ 2007-03-09 15:34:45 by dbateman]
dbateman
parents: 6399
diff changeset
1256 if (error_state)
f8cbc0871ed6 [project @ 2007-03-09 15:34:45 by dbateman]
dbateman
parents: 6399
diff changeset
1257 return retval;
f8cbc0871ed6 [project @ 2007-03-09 15:34:45 by dbateman]
dbateman
parents: 6399
diff changeset
1258
f8cbc0871ed6 [project @ 2007-03-09 15:34:45 by dbateman]
dbateman
parents: 6399
diff changeset
1259 dim_vector dv_tmp = args (j).dims ();
f8cbc0871ed6 [project @ 2007-03-09 15:34:45 by dbateman]
dbateman
parents: 6399
diff changeset
1260
6883
037c8b622a01 [project @ 2007-09-10 20:13:27 by jwe]
jwe
parents: 6867
diff changeset
1261 if (dim >= dv_len)
037c8b622a01 [project @ 2007-09-10 20:13:27 by jwe]
jwe
parents: 6867
diff changeset
1262 {
037c8b622a01 [project @ 2007-09-10 20:13:27 by jwe]
jwe
parents: 6867
diff changeset
1263 if (j > i)
037c8b622a01 [project @ 2007-09-10 20:13:27 by jwe]
jwe
parents: 6867
diff changeset
1264 error ("%s: indexing error", fname.c_str ());
037c8b622a01 [project @ 2007-09-10 20:13:27 by jwe]
jwe
parents: 6867
diff changeset
1265 break;
037c8b622a01 [project @ 2007-09-10 20:13:27 by jwe]
jwe
parents: 6867
diff changeset
1266 }
037c8b622a01 [project @ 2007-09-10 20:13:27 by jwe]
jwe
parents: 6867
diff changeset
1267 else
037c8b622a01 [project @ 2007-09-10 20:13:27 by jwe]
jwe
parents: 6867
diff changeset
1268 ra_idx (dim) += (dim < dv_tmp.length () ?
037c8b622a01 [project @ 2007-09-10 20:13:27 by jwe]
jwe
parents: 6867
diff changeset
1269 dv_tmp (dim) : 1);
6401
f8cbc0871ed6 [project @ 2007-03-09 15:34:45 by dbateman]
dbateman
parents: 6399
diff changeset
1270 }
f8cbc0871ed6 [project @ 2007-03-09 15:34:45 by dbateman]
dbateman
parents: 6399
diff changeset
1271
f8cbc0871ed6 [project @ 2007-03-09 15:34:45 by dbateman]
dbateman
parents: 6399
diff changeset
1272 retval = tmp;
4915
c638c144d4da [project @ 2004-07-23 19:01:22 by jwe]
jwe
parents: 4911
diff changeset
1273 }
4806
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1274 }
5533
667ad2becb63 [project @ 2005-11-10 21:40:48 by jwe]
jwe
parents: 5507
diff changeset
1275 else
667ad2becb63 [project @ 2005-11-10 21:40:48 by jwe]
jwe
parents: 5507
diff changeset
1276 error ("%s: invalid dimension argument", fname.c_str ());
4806
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1277 }
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1278 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
1279 print_usage ();
4806
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1280
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1281 return retval;
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1282 }
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1283
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1284 DEFUN (horzcat, args, ,
4824
4829055e154f [project @ 2004-03-08 18:16:04 by jwe]
jwe
parents: 4806
diff changeset
1285 "-*- texinfo -*-\n\
4806
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1286 @deftypefn {Built-in Function} {} horzcat (@var{array1}, @var{array2}, @dots{}, @var{arrayN})\n\
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1287 Return the horizontal concatenation of N-d array objects, @var{array1},\n\
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1288 @var{array2}, @dots{}, @var{arrayN} along dimension 2.\n\
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5607
diff changeset
1289 @seealso{cat, vertcat}\n\
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5607
diff changeset
1290 @end deftypefn")
4806
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1291 {
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1292 octave_value_list args_tmp = args;
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1293
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1294 int dim = 2;
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1295
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1296 octave_value d (dim);
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1297
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1298 args_tmp.prepend (d);
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1299
4824
4829055e154f [project @ 2004-03-08 18:16:04 by jwe]
jwe
parents: 4806
diff changeset
1300 return do_cat (args_tmp, "horzcat");
4806
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1301 }
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1302
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1303 DEFUN (vertcat, args, ,
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1304 "-*- texinfo -*-\n\
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1305 @deftypefn {Built-in Function} {} vertcat (@var{array1}, @var{array2}, @dots{}, @var{arrayN})\n\
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1306 Return the vertical concatenation of N-d array objects, @var{array1},\n\
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1307 @var{array2}, @dots{}, @var{arrayN} along dimension 1.\n\
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5607
diff changeset
1308 @seealso{cat, horzcat}\n\
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5607
diff changeset
1309 @end deftypefn")
4806
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1310 {
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1311 octave_value_list args_tmp = args;
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1312
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1313 int dim = 1;
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1314
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1315 octave_value d (dim);
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1316
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1317 args_tmp.prepend (d);
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1318
4824
4829055e154f [project @ 2004-03-08 18:16:04 by jwe]
jwe
parents: 4806
diff changeset
1319 return do_cat (args_tmp, "vertcat");
4806
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1320 }
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1321
4758
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
1322 DEFUN (cat, args, ,
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
1323 "-*- texinfo -*-\n\
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
1324 @deftypefn {Built-in Function} {} cat (@var{dim}, @var{array1}, @var{array2}, @dots{}, @var{arrayN})\n\
4806
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1325 Return the concatenation of N-d array objects, @var{array1},\n\
d3bd9c04147f [project @ 2004-03-02 05:12:32 by jwe]
jwe
parents: 4768
diff changeset
1326 @var{array2}, @dots{}, @var{arrayN} along dimension @var{dim}.\n\
4758
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
1327 \n\
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
1328 @example\n\
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
1329 @group\n\
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
1330 A = ones (2, 2);\n\
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
1331 B = zeros (2, 2);\n\
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
1332 cat (2, A, B)\n\
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
1333 @result{} ans =\n\
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
1334 \n\
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
1335 1 1 0 0\n\
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
1336 1 1 0 0\n\
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
1337 @end group\n\
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
1338 @end example\n\
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
1339 \n\
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
1340 Alternatively, we can concatenate @var{A} and @var{B} along the\n\
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
1341 second dimension the following way:\n\
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
1342 \n\
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
1343 @example\n\
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
1344 @group\n\
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
1345 [A, B].\n\
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
1346 @end group\n\
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
1347 @end example\n\
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
1348 \n\
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
1349 @var{dim} can be larger than the dimensions of the N-d array objects\n\
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
1350 and the result will thus have @var{dim} dimensions as the\n\
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
1351 following example shows:\n\
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
1352 @example\n\
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
1353 @group\n\
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
1354 cat (4, ones(2, 2), zeros (2, 2))\n\
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
1355 @result{} ans =\n\
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
1356 \n\
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
1357 ans(:,:,1,1) =\n\
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
1358 \n\
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
1359 1 1\n\
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
1360 1 1\n\
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
1361 \n\
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
1362 ans(:,:,1,2) =\n\
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
1363 0 0\n\
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
1364 0 0\n\
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
1365 @end group\n\
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
1366 @end example\n\
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5607
diff changeset
1367 @seealso{horzcat, vertcat}\n\
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5607
diff changeset
1368 @end deftypefn")
4758
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
1369 {
4824
4829055e154f [project @ 2004-03-08 18:16:04 by jwe]
jwe
parents: 4806
diff changeset
1370 return do_cat (args, "cat");
4758
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
1371 }
a308566c8b42 [project @ 2004-02-13 23:01:34 by jwe]
jwe
parents: 4741
diff changeset
1372
4593
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
1373 static octave_value
6959
47f4f4e88166 [project @ 2007-10-04 20:43:32 by jwe]
jwe
parents: 6953
diff changeset
1374 do_permute (const octave_value_list& args, bool inv)
4593
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
1375 {
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
1376 octave_value retval;
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
1377
5148
9eab94f5fadf [project @ 2005-02-18 19:04:34 by jwe]
jwe
parents: 5061
diff changeset
1378 if (args.length () == 2 && args(1).length () >= args(1).ndims ())
4593
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
1379 {
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
1380 Array<int> vec = args(1).int_vector_value ();
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
1381
5775
ace8d8d26933 [project @ 2006-04-24 19:13:06 by jwe]
jwe
parents: 5747
diff changeset
1382 // FIXME -- maybe we should create an idx_vector object
5148
9eab94f5fadf [project @ 2005-02-18 19:04:34 by jwe]
jwe
parents: 5061
diff changeset
1383 // here and pass that to permute?
9eab94f5fadf [project @ 2005-02-18 19:04:34 by jwe]
jwe
parents: 5061
diff changeset
1384
9eab94f5fadf [project @ 2005-02-18 19:04:34 by jwe]
jwe
parents: 5061
diff changeset
1385 int n = vec.length ();
9eab94f5fadf [project @ 2005-02-18 19:04:34 by jwe]
jwe
parents: 5061
diff changeset
1386
9eab94f5fadf [project @ 2005-02-18 19:04:34 by jwe]
jwe
parents: 5061
diff changeset
1387 for (int i = 0; i < n; i++)
9eab94f5fadf [project @ 2005-02-18 19:04:34 by jwe]
jwe
parents: 5061
diff changeset
1388 vec(i)--;
9eab94f5fadf [project @ 2005-02-18 19:04:34 by jwe]
jwe
parents: 5061
diff changeset
1389
4593
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
1390 octave_value ret = args(0).permute (vec, inv);
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
1391
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
1392 if (! error_state)
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
1393 retval = ret;
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
1394 }
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
1395 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
1396 print_usage ();
4593
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
1397
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
1398 return retval;
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
1399 }
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
1400
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
1401 DEFUN (permute, args, ,
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
1402 "-*- texinfo -*-\n\
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
1403 @deftypefn {Built-in Function} {} permute (@var{a}, @var{perm})\n\
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
1404 Return the generalized transpose for an N-d array object @var{a}.\n\
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
1405 The permutation vector @var{perm} must contain the elements\n\
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
1406 @code{1:ndims(a)} (in any order, but each element must appear just once).\n\
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5607
diff changeset
1407 @seealso{ipermute}\n\
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5607
diff changeset
1408 @end deftypefn")
4593
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
1409 {
6959
47f4f4e88166 [project @ 2007-10-04 20:43:32 by jwe]
jwe
parents: 6953
diff changeset
1410 return do_permute (args, false);
4593
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
1411 }
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
1412
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
1413 DEFUN (ipermute, args, ,
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
1414 "-*- texinfo -*-\n\
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
1415 @deftypefn {Built-in Function} {} ipermute (@var{a}, @var{iperm})\n\
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
1416 The inverse of the @code{permute} function. The expression\n\
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
1417 \n\
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
1418 @example\n\
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
1419 ipermute (permute (a, perm), perm)\n\
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
1420 @end example\n\
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
1421 returns the original array @var{a}.\n\
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5607
diff changeset
1422 @seealso{permute}\n\
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5607
diff changeset
1423 @end deftypefn")
4593
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
1424 {
6959
47f4f4e88166 [project @ 2007-10-04 20:43:32 by jwe]
jwe
parents: 6953
diff changeset
1425 return do_permute (args, true);
4593
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
1426 }
77566be8b9e9 [project @ 2003-11-11 17:25:42 by jwe]
jwe
parents: 4569
diff changeset
1427
3195
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3186
diff changeset
1428 DEFUN (length, args, ,
3373
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3369
diff changeset
1429 "-*- texinfo -*-\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3369
diff changeset
1430 @deftypefn {Built-in Function} {} length (@var{a})\n\
4176
b8ec44432831 [project @ 2002-11-13 02:49:14 by jwe]
jwe
parents: 4153
diff changeset
1431 Return the `length' of the object @var{a}. For matrix objects, the\n\
3373
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3369
diff changeset
1432 length is the number of rows or columns, whichever is greater (this\n\
6556
8810bbf321ce [project @ 2007-04-20 18:39:40 by jwe]
jwe
parents: 6518
diff changeset
1433 odd definition is used for compatibility with @sc{Matlab}).\n\
3373
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3369
diff changeset
1434 @end deftypefn")
3195
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3186
diff changeset
1435 {
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3186
diff changeset
1436 octave_value retval;
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3186
diff changeset
1437
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3186
diff changeset
1438 if (args.length () == 1)
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3186
diff changeset
1439 {
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3186
diff changeset
1440 int len = args(0).length ();
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3186
diff changeset
1441
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3186
diff changeset
1442 if (! error_state)
4233
ccfdb55c8156 [project @ 2002-12-20 22:43:54 by jwe]
jwe
parents: 4176
diff changeset
1443 retval = len;
3195
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3186
diff changeset
1444 }
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3186
diff changeset
1445 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
1446 print_usage ();
3195
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3186
diff changeset
1447
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3186
diff changeset
1448 return retval;
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3186
diff changeset
1449 }
7a5a5da64756 [project @ 1998-10-28 22:54:04 by jwe]
jwe
parents: 3186
diff changeset
1450
4554
78e34346f6fd [project @ 2003-10-27 22:01:49 by jwe]
jwe
parents: 4545
diff changeset
1451 DEFUN (ndims, args, ,
78e34346f6fd [project @ 2003-10-27 22:01:49 by jwe]
jwe
parents: 4545
diff changeset
1452 "-*- texinfo -*-\n\
78e34346f6fd [project @ 2003-10-27 22:01:49 by jwe]
jwe
parents: 4545
diff changeset
1453 @deftypefn {Built-in Function} {} ndims (@var{a})\n\
78e34346f6fd [project @ 2003-10-27 22:01:49 by jwe]
jwe
parents: 4545
diff changeset
1454 Returns the number of dimensions of array @var{a}.\n\
78e34346f6fd [project @ 2003-10-27 22:01:49 by jwe]
jwe
parents: 4545
diff changeset
1455 For any array, the result will always be larger than or equal to 2.\n\
78e34346f6fd [project @ 2003-10-27 22:01:49 by jwe]
jwe
parents: 4545
diff changeset
1456 Trailing singleton dimensions are not counted.\n\
78e34346f6fd [project @ 2003-10-27 22:01:49 by jwe]
jwe
parents: 4545
diff changeset
1457 @end deftypefn")
78e34346f6fd [project @ 2003-10-27 22:01:49 by jwe]
jwe
parents: 4545
diff changeset
1458 {
78e34346f6fd [project @ 2003-10-27 22:01:49 by jwe]
jwe
parents: 4545
diff changeset
1459 octave_value retval;
78e34346f6fd [project @ 2003-10-27 22:01:49 by jwe]
jwe
parents: 4545
diff changeset
1460
78e34346f6fd [project @ 2003-10-27 22:01:49 by jwe]
jwe
parents: 4545
diff changeset
1461 if (args.length () == 1)
78e34346f6fd [project @ 2003-10-27 22:01:49 by jwe]
jwe
parents: 4545
diff changeset
1462 {
78e34346f6fd [project @ 2003-10-27 22:01:49 by jwe]
jwe
parents: 4545
diff changeset
1463 int n_dims = args(0).ndims ();
78e34346f6fd [project @ 2003-10-27 22:01:49 by jwe]
jwe
parents: 4545
diff changeset
1464
78e34346f6fd [project @ 2003-10-27 22:01:49 by jwe]
jwe
parents: 4545
diff changeset
1465 if (! error_state)
78e34346f6fd [project @ 2003-10-27 22:01:49 by jwe]
jwe
parents: 4545
diff changeset
1466 retval = n_dims;
78e34346f6fd [project @ 2003-10-27 22:01:49 by jwe]
jwe
parents: 4545
diff changeset
1467 }
78e34346f6fd [project @ 2003-10-27 22:01:49 by jwe]
jwe
parents: 4545
diff changeset
1468 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
1469 print_usage ();
4554
78e34346f6fd [project @ 2003-10-27 22:01:49 by jwe]
jwe
parents: 4545
diff changeset
1470
78e34346f6fd [project @ 2003-10-27 22:01:49 by jwe]
jwe
parents: 4545
diff changeset
1471 return retval;
78e34346f6fd [project @ 2003-10-27 22:01:49 by jwe]
jwe
parents: 4545
diff changeset
1472 }
78e34346f6fd [project @ 2003-10-27 22:01:49 by jwe]
jwe
parents: 4545
diff changeset
1473
4559
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4556
diff changeset
1474 DEFUN (numel, args, ,
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4556
diff changeset
1475 "-*- texinfo -*-\n\
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4556
diff changeset
1476 @deftypefn {Built-in Function} {} numel (@var{a})\n\
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4556
diff changeset
1477 Returns the number of elements in the object @var{a}.\n\
5724
82247c2a7520 [project @ 2006-03-30 21:34:52 by jwe]
jwe
parents: 5714
diff changeset
1478 @seealso{size}\n\
4559
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4556
diff changeset
1479 @end deftypefn")
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4556
diff changeset
1480 {
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4556
diff changeset
1481 octave_value retval;
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4556
diff changeset
1482
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4556
diff changeset
1483 if (args.length () == 1)
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4556
diff changeset
1484 {
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4556
diff changeset
1485 int numel = args(0).numel ();
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4556
diff changeset
1486
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4556
diff changeset
1487 if (! error_state)
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4556
diff changeset
1488 {
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4556
diff changeset
1489 if (numel < 0)
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4556
diff changeset
1490 numel = 0;
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4556
diff changeset
1491
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4556
diff changeset
1492 retval = numel;
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4556
diff changeset
1493 }
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4556
diff changeset
1494 }
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4556
diff changeset
1495 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
1496 print_usage ();
4559
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4556
diff changeset
1497
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4556
diff changeset
1498 return retval;
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4556
diff changeset
1499 }
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4556
diff changeset
1500
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1940
diff changeset
1501 DEFUN (size, args, nargout,
3373
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3369
diff changeset
1502 "-*- texinfo -*-\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3369
diff changeset
1503 @deftypefn {Built-in Function} {} size (@var{a}, @var{n})\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3369
diff changeset
1504 Return the number rows and columns of @var{a}.\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3369
diff changeset
1505 \n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3369
diff changeset
1506 With one input argument and one output argument, the result is returned\n\
4741
e44d0ac643a5 [project @ 2004-02-05 21:57:50 by jwe]
jwe
parents: 4739
diff changeset
1507 in a row vector. If there are multiple output arguments, the number of\n\
e44d0ac643a5 [project @ 2004-02-05 21:57:50 by jwe]
jwe
parents: 4739
diff changeset
1508 rows is assigned to the first, and the number of columns to the second,\n\
e44d0ac643a5 [project @ 2004-02-05 21:57:50 by jwe]
jwe
parents: 4739
diff changeset
1509 etc. For example,\n\
3373
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3369
diff changeset
1510 \n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3369
diff changeset
1511 @example\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3369
diff changeset
1512 @group\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3369
diff changeset
1513 size ([1, 2; 3, 4; 5, 6])\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3369
diff changeset
1514 @result{} [ 3, 2 ]\n\
1031
59f5eb2d5eb3 [project @ 1995-01-15 21:11:11 by jwe]
jwe
parents: 1009
diff changeset
1515 \n\
3373
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3369
diff changeset
1516 [nr, nc] = size ([1, 2; 3, 4; 5, 6])\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3369
diff changeset
1517 @result{} nr = 3\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3369
diff changeset
1518 @result{} nc = 2\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3369
diff changeset
1519 @end group\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3369
diff changeset
1520 @end example\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3369
diff changeset
1521 \n\
4741
e44d0ac643a5 [project @ 2004-02-05 21:57:50 by jwe]
jwe
parents: 4739
diff changeset
1522 If given a second argument, @code{size} will return the size of the\n\
e44d0ac643a5 [project @ 2004-02-05 21:57:50 by jwe]
jwe
parents: 4739
diff changeset
1523 corresponding dimension. For example\n\
1031
59f5eb2d5eb3 [project @ 1995-01-15 21:11:11 by jwe]
jwe
parents: 1009
diff changeset
1524 \n\
3373
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3369
diff changeset
1525 @example\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3369
diff changeset
1526 size ([1, 2; 3, 4; 5, 6], 2)\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3369
diff changeset
1527 @result{} 2\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3369
diff changeset
1528 @end example\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3369
diff changeset
1529 \n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3369
diff changeset
1530 @noindent\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3369
diff changeset
1531 returns the number of columns in the given matrix.\n\
5724
82247c2a7520 [project @ 2006-03-30 21:34:52 by jwe]
jwe
parents: 5714
diff changeset
1532 @seealso{numel}\n\
3373
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3369
diff changeset
1533 @end deftypefn")
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1534 {
2086
bfb775fb6fe8 [project @ 1996-04-25 05:55:19 by jwe]
jwe
parents: 1996
diff changeset
1535 octave_value_list retval;
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1536
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1537 int nargin = args.length ();
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1538
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4512
diff changeset
1539 if (nargin == 1)
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1540 {
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4512
diff changeset
1541 dim_vector dimensions = args(0).dims ();
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4512
diff changeset
1542
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4512
diff changeset
1543 int ndims = dimensions.length ();
1031
59f5eb2d5eb3 [project @ 1995-01-15 21:11:11 by jwe]
jwe
parents: 1009
diff changeset
1544
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4512
diff changeset
1545 Matrix m (1, ndims);
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4512
diff changeset
1546
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4512
diff changeset
1547 if (nargout > 1)
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1548 {
5991
265723390e7b [project @ 2006-09-15 17:30:23 by jwe]
jwe
parents: 5823
diff changeset
1549 for (int i = nargout-1; i >= ndims; i--)
265723390e7b [project @ 2006-09-15 17:30:23 by jwe]
jwe
parents: 5823
diff changeset
1550 retval(i) = 1;
265723390e7b [project @ 2006-09-15 17:30:23 by jwe]
jwe
parents: 5823
diff changeset
1551
6197
c67c11e22828 [project @ 2006-12-04 16:08:30 by dbateman]
dbateman
parents: 6175
diff changeset
1552 if (ndims > nargout)
c67c11e22828 [project @ 2006-12-04 16:08:30 by dbateman]
dbateman
parents: 6175
diff changeset
1553 {
c67c11e22828 [project @ 2006-12-04 16:08:30 by dbateman]
dbateman
parents: 6175
diff changeset
1554 octave_idx_type d = 1;
c67c11e22828 [project @ 2006-12-04 16:08:30 by dbateman]
dbateman
parents: 6175
diff changeset
1555
c67c11e22828 [project @ 2006-12-04 16:08:30 by dbateman]
dbateman
parents: 6175
diff changeset
1556 while (ndims >= nargout)
c67c11e22828 [project @ 2006-12-04 16:08:30 by dbateman]
dbateman
parents: 6175
diff changeset
1557 d *= dimensions(--ndims);
c67c11e22828 [project @ 2006-12-04 16:08:30 by dbateman]
dbateman
parents: 6175
diff changeset
1558
c67c11e22828 [project @ 2006-12-04 16:08:30 by dbateman]
dbateman
parents: 6175
diff changeset
1559 retval(ndims) = d;
c67c11e22828 [project @ 2006-12-04 16:08:30 by dbateman]
dbateman
parents: 6175
diff changeset
1560 }
c67c11e22828 [project @ 2006-12-04 16:08:30 by dbateman]
dbateman
parents: 6175
diff changeset
1561
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4512
diff changeset
1562 while (ndims--)
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4512
diff changeset
1563 retval(ndims) = dimensions(ndims);
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1564 }
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4512
diff changeset
1565 else
712
36ba0576bd1b [project @ 1994-09-19 14:18:15 by jwe]
jwe
parents: 649
diff changeset
1566 {
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4512
diff changeset
1567 for (int i = 0; i < ndims; i++)
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4512
diff changeset
1568 m(0, i) = dimensions(i);
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4512
diff changeset
1569
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4512
diff changeset
1570 retval(0) = m;
712
36ba0576bd1b [project @ 1994-09-19 14:18:15 by jwe]
jwe
parents: 649
diff changeset
1571 }
1031
59f5eb2d5eb3 [project @ 1995-01-15 21:11:11 by jwe]
jwe
parents: 1009
diff changeset
1572 }
59f5eb2d5eb3 [project @ 1995-01-15 21:11:11 by jwe]
jwe
parents: 1009
diff changeset
1573 else if (nargin == 2 && nargout < 2)
59f5eb2d5eb3 [project @ 1995-01-15 21:11:11 by jwe]
jwe
parents: 1009
diff changeset
1574 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
1575 octave_idx_type nd = args(1).int_value (true);
1031
59f5eb2d5eb3 [project @ 1995-01-15 21:11:11 by jwe]
jwe
parents: 1009
diff changeset
1576
59f5eb2d5eb3 [project @ 1995-01-15 21:11:11 by jwe]
jwe
parents: 1009
diff changeset
1577 if (error_state)
59f5eb2d5eb3 [project @ 1995-01-15 21:11:11 by jwe]
jwe
parents: 1009
diff changeset
1578 error ("size: expecting scalar as second argument");
712
36ba0576bd1b [project @ 1994-09-19 14:18:15 by jwe]
jwe
parents: 649
diff changeset
1579 else
1031
59f5eb2d5eb3 [project @ 1995-01-15 21:11:11 by jwe]
jwe
parents: 1009
diff changeset
1580 {
4741
e44d0ac643a5 [project @ 2004-02-05 21:57:50 by jwe]
jwe
parents: 4739
diff changeset
1581 dim_vector dv = args(0).dims ();
e44d0ac643a5 [project @ 2004-02-05 21:57:50 by jwe]
jwe
parents: 4739
diff changeset
1582
4911
14027e0bafa4 [project @ 2004-07-22 19:58:06 by jwe]
jwe
parents: 4845
diff changeset
1583 if (nd > 0)
14027e0bafa4 [project @ 2004-07-22 19:58:06 by jwe]
jwe
parents: 4845
diff changeset
1584 {
14027e0bafa4 [project @ 2004-07-22 19:58:06 by jwe]
jwe
parents: 4845
diff changeset
1585 if (nd <= dv.length ())
14027e0bafa4 [project @ 2004-07-22 19:58:06 by jwe]
jwe
parents: 4845
diff changeset
1586 retval(0) = dv(nd-1);
14027e0bafa4 [project @ 2004-07-22 19:58:06 by jwe]
jwe
parents: 4845
diff changeset
1587 else
14027e0bafa4 [project @ 2004-07-22 19:58:06 by jwe]
jwe
parents: 4845
diff changeset
1588 retval(0) = 1;
14027e0bafa4 [project @ 2004-07-22 19:58:06 by jwe]
jwe
parents: 4845
diff changeset
1589 }
1031
59f5eb2d5eb3 [project @ 1995-01-15 21:11:11 by jwe]
jwe
parents: 1009
diff changeset
1590 else
4741
e44d0ac643a5 [project @ 2004-02-05 21:57:50 by jwe]
jwe
parents: 4739
diff changeset
1591 error ("size: requested dimension (= %d) out of range", nd);
1031
59f5eb2d5eb3 [project @ 1995-01-15 21:11:11 by jwe]
jwe
parents: 1009
diff changeset
1592 }
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1593 }
712
36ba0576bd1b [project @ 1994-09-19 14:18:15 by jwe]
jwe
parents: 649
diff changeset
1594 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
1595 print_usage ();
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1596
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1597 return retval;
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1598 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1599
6156
a46f14cdbecd [project @ 2006-11-13 19:20:23 by jwe]
jwe
parents: 6133
diff changeset
1600 DEFUN (size_equal, args, ,
a46f14cdbecd [project @ 2006-11-13 19:20:23 by jwe]
jwe
parents: 6133
diff changeset
1601 "-*- texinfo -*-\n\
6561
dc83c15d7149 [project @ 2007-04-23 16:58:17 by jwe]
jwe
parents: 6556
diff changeset
1602 @deftypefn {Built-in Function} {} size_equal (@var{a}, @var{b}, @dots{})\n\
dc83c15d7149 [project @ 2007-04-23 16:58:17 by jwe]
jwe
parents: 6556
diff changeset
1603 Return true if the dimensions of all arguments agree.\n\
6156
a46f14cdbecd [project @ 2006-11-13 19:20:23 by jwe]
jwe
parents: 6133
diff changeset
1604 Trailing singleton dimensions are ignored.\n\
a46f14cdbecd [project @ 2006-11-13 19:20:23 by jwe]
jwe
parents: 6133
diff changeset
1605 @seealso{size, numel}\n\
a46f14cdbecd [project @ 2006-11-13 19:20:23 by jwe]
jwe
parents: 6133
diff changeset
1606 @end deftypefn")
a46f14cdbecd [project @ 2006-11-13 19:20:23 by jwe]
jwe
parents: 6133
diff changeset
1607 {
a46f14cdbecd [project @ 2006-11-13 19:20:23 by jwe]
jwe
parents: 6133
diff changeset
1608 octave_value retval;
a46f14cdbecd [project @ 2006-11-13 19:20:23 by jwe]
jwe
parents: 6133
diff changeset
1609
6561
dc83c15d7149 [project @ 2007-04-23 16:58:17 by jwe]
jwe
parents: 6556
diff changeset
1610 int nargin = args.length ();
dc83c15d7149 [project @ 2007-04-23 16:58:17 by jwe]
jwe
parents: 6556
diff changeset
1611
dc83c15d7149 [project @ 2007-04-23 16:58:17 by jwe]
jwe
parents: 6556
diff changeset
1612 if (nargin >= 2)
6156
a46f14cdbecd [project @ 2006-11-13 19:20:23 by jwe]
jwe
parents: 6133
diff changeset
1613 {
6561
dc83c15d7149 [project @ 2007-04-23 16:58:17 by jwe]
jwe
parents: 6556
diff changeset
1614 retval = true;
dc83c15d7149 [project @ 2007-04-23 16:58:17 by jwe]
jwe
parents: 6556
diff changeset
1615
6156
a46f14cdbecd [project @ 2006-11-13 19:20:23 by jwe]
jwe
parents: 6133
diff changeset
1616 dim_vector a_dims = args(0).dims ();
a46f14cdbecd [project @ 2006-11-13 19:20:23 by jwe]
jwe
parents: 6133
diff changeset
1617 a_dims.chop_trailing_singletons ();
6561
dc83c15d7149 [project @ 2007-04-23 16:58:17 by jwe]
jwe
parents: 6556
diff changeset
1618
dc83c15d7149 [project @ 2007-04-23 16:58:17 by jwe]
jwe
parents: 6556
diff changeset
1619 for (int i = 1; i < nargin; ++i)
dc83c15d7149 [project @ 2007-04-23 16:58:17 by jwe]
jwe
parents: 6556
diff changeset
1620 {
dc83c15d7149 [project @ 2007-04-23 16:58:17 by jwe]
jwe
parents: 6556
diff changeset
1621 dim_vector b_dims = args(i).dims ();
dc83c15d7149 [project @ 2007-04-23 16:58:17 by jwe]
jwe
parents: 6556
diff changeset
1622 b_dims.chop_trailing_singletons ();
dc83c15d7149 [project @ 2007-04-23 16:58:17 by jwe]
jwe
parents: 6556
diff changeset
1623
dc83c15d7149 [project @ 2007-04-23 16:58:17 by jwe]
jwe
parents: 6556
diff changeset
1624 if (a_dims != b_dims)
dc83c15d7149 [project @ 2007-04-23 16:58:17 by jwe]
jwe
parents: 6556
diff changeset
1625 {
dc83c15d7149 [project @ 2007-04-23 16:58:17 by jwe]
jwe
parents: 6556
diff changeset
1626 retval = false;
dc83c15d7149 [project @ 2007-04-23 16:58:17 by jwe]
jwe
parents: 6556
diff changeset
1627 break;
dc83c15d7149 [project @ 2007-04-23 16:58:17 by jwe]
jwe
parents: 6556
diff changeset
1628 }
dc83c15d7149 [project @ 2007-04-23 16:58:17 by jwe]
jwe
parents: 6556
diff changeset
1629 }
6156
a46f14cdbecd [project @ 2006-11-13 19:20:23 by jwe]
jwe
parents: 6133
diff changeset
1630 }
a46f14cdbecd [project @ 2006-11-13 19:20:23 by jwe]
jwe
parents: 6133
diff changeset
1631 else
a46f14cdbecd [project @ 2006-11-13 19:20:23 by jwe]
jwe
parents: 6133
diff changeset
1632 print_usage ();
a46f14cdbecd [project @ 2006-11-13 19:20:23 by jwe]
jwe
parents: 6133
diff changeset
1633
a46f14cdbecd [project @ 2006-11-13 19:20:23 by jwe]
jwe
parents: 6133
diff changeset
1634 return retval;
a46f14cdbecd [project @ 2006-11-13 19:20:23 by jwe]
jwe
parents: 6133
diff changeset
1635 }
a46f14cdbecd [project @ 2006-11-13 19:20:23 by jwe]
jwe
parents: 6133
diff changeset
1636
5602
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5533
diff changeset
1637 DEFUN (nnz, args, ,
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5533
diff changeset
1638 "-*- texinfo -*-\n\
6156
a46f14cdbecd [project @ 2006-11-13 19:20:23 by jwe]
jwe
parents: 6133
diff changeset
1639 @deftypefn {Built-in Function} {@var{scalar} =} nnz (@var{a})\n\
a46f14cdbecd [project @ 2006-11-13 19:20:23 by jwe]
jwe
parents: 6133
diff changeset
1640 Returns the number of non zero elements in @var{a}.\n\
5602
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5533
diff changeset
1641 @seealso{sparse}\n\
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5533
diff changeset
1642 @end deftypefn")
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5533
diff changeset
1643 {
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5533
diff changeset
1644 octave_value retval;
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5533
diff changeset
1645
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5533
diff changeset
1646 if (args.length () == 1)
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5533
diff changeset
1647 retval = args(0).nnz ();
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5533
diff changeset
1648 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
1649 print_usage ();
5602
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5533
diff changeset
1650
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5533
diff changeset
1651 return retval;
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5533
diff changeset
1652 }
dfa2da0563e5 [project @ 2006-01-31 03:43:40 by jwe]
jwe
parents: 5533
diff changeset
1653
5604
2857357f9d3c [project @ 2006-01-31 18:22:59 by jwe]
jwe
parents: 5602
diff changeset
1654 DEFUN (nzmax, args, ,
2857357f9d3c [project @ 2006-01-31 18:22:59 by jwe]
jwe
parents: 5602
diff changeset
1655 "-*- texinfo -*-\n\
6156
a46f14cdbecd [project @ 2006-11-13 19:20:23 by jwe]
jwe
parents: 6133
diff changeset
1656 @deftypefn {Built-in Function} {@var{scalar} =} nzmax (@var{SM})\n\
5604
2857357f9d3c [project @ 2006-01-31 18:22:59 by jwe]
jwe
parents: 5602
diff changeset
1657 Return the amount of storage allocated to the sparse matrix @var{SM}.\n\
7001
8b0cfeb06365 [project @ 2007-10-10 18:02:59 by jwe]
jwe
parents: 6999
diff changeset
1658 Note that Octave tends to crop unused memory at the first opportunity\n\
5604
2857357f9d3c [project @ 2006-01-31 18:22:59 by jwe]
jwe
parents: 5602
diff changeset
1659 for sparse objects. There are some cases of user created sparse objects\n\
2857357f9d3c [project @ 2006-01-31 18:22:59 by jwe]
jwe
parents: 5602
diff changeset
1660 where the value returned by @dfn{nzmaz} will not be the same as @dfn{nnz},\n\
2857357f9d3c [project @ 2006-01-31 18:22:59 by jwe]
jwe
parents: 5602
diff changeset
1661 but in general they will give the same result.\n\
2857357f9d3c [project @ 2006-01-31 18:22:59 by jwe]
jwe
parents: 5602
diff changeset
1662 @seealso{sparse, spalloc}\n\
2857357f9d3c [project @ 2006-01-31 18:22:59 by jwe]
jwe
parents: 5602
diff changeset
1663 @end deftypefn")
2857357f9d3c [project @ 2006-01-31 18:22:59 by jwe]
jwe
parents: 5602
diff changeset
1664 {
2857357f9d3c [project @ 2006-01-31 18:22:59 by jwe]
jwe
parents: 5602
diff changeset
1665 octave_value retval;
2857357f9d3c [project @ 2006-01-31 18:22:59 by jwe]
jwe
parents: 5602
diff changeset
1666
2857357f9d3c [project @ 2006-01-31 18:22:59 by jwe]
jwe
parents: 5602
diff changeset
1667 if (args.length() == 1)
2857357f9d3c [project @ 2006-01-31 18:22:59 by jwe]
jwe
parents: 5602
diff changeset
1668 retval = args(0).nzmax ();
2857357f9d3c [project @ 2006-01-31 18:22:59 by jwe]
jwe
parents: 5602
diff changeset
1669 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
1670 print_usage ();
5604
2857357f9d3c [project @ 2006-01-31 18:22:59 by jwe]
jwe
parents: 5602
diff changeset
1671
2857357f9d3c [project @ 2006-01-31 18:22:59 by jwe]
jwe
parents: 5602
diff changeset
1672 return retval;
2857357f9d3c [project @ 2006-01-31 18:22:59 by jwe]
jwe
parents: 5602
diff changeset
1673 }
2857357f9d3c [project @ 2006-01-31 18:22:59 by jwe]
jwe
parents: 5602
diff changeset
1674
5677
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
1675 DEFUN (rows, args, ,
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
1676 "-*- texinfo -*-\n\
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
1677 @deftypefn {Built-in Function} {} rows (@var{a})\n\
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
1678 Return the number of rows of @var{a}.\n\
5724
82247c2a7520 [project @ 2006-03-30 21:34:52 by jwe]
jwe
parents: 5714
diff changeset
1679 @seealso{size, numel, columns, length, isscalar, isvector, ismatrix}\n\
5677
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
1680 @end deftypefn")
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
1681 {
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
1682 octave_value retval;
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
1683
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
1684 if (args.length () == 1)
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
1685 retval = args(0).rows ();
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
1686 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
1687 print_usage ();
5677
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
1688
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
1689 return retval;
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
1690 }
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
1691
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
1692 DEFUN (columns, args, ,
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
1693 "-*- texinfo -*-\n\
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
1694 @deftypefn {Built-in Function} {} columns (@var{a})\n\
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
1695 Return the number of columns of @var{a}.\n\
5724
82247c2a7520 [project @ 2006-03-30 21:34:52 by jwe]
jwe
parents: 5714
diff changeset
1696 @seealso{size, numel, rows, length, isscalar, isvector, and ismatrix}\n\
5677
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
1697 @end deftypefn")
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
1698 {
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
1699 octave_value retval;
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
1700
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
1701 if (args.length () == 1)
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
1702 retval = args(0).columns ();
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
1703 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
1704 print_usage ();
5677
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
1705
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
1706 return retval;
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
1707 }
a8f6903535c9 [project @ 2006-03-16 05:54:20 by jwe]
jwe
parents: 5642
diff changeset
1708
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1940
diff changeset
1709 DEFUN (sum, args, ,
3428
5b77cf82393c [project @ 2000-01-14 02:54:53 by jwe]
jwe
parents: 3418
diff changeset
1710 "-*- texinfo -*-\n\
3723
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
1711 @deftypefn {Built-in Function} {} sum (@var{x}, @var{dim})\n\
7112
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
1712 @deftypefnx {Built-in Function} {} sum (@dots{}, 'native')\n\
3723
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
1713 Sum of elements along dimension @var{dim}. If @var{dim} is\n\
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
1714 omitted, it defaults to 1 (column-wise sum).\n\
5061
4689ee5e88ec [project @ 2004-11-03 21:23:42 by jwe]
jwe
parents: 5058
diff changeset
1715 \n\
4689ee5e88ec [project @ 2004-11-03 21:23:42 by jwe]
jwe
parents: 5058
diff changeset
1716 As a special case, if @var{x} is a vector and @var{dim} is omitted,\n\
4689ee5e88ec [project @ 2004-11-03 21:23:42 by jwe]
jwe
parents: 5058
diff changeset
1717 return the sum of the elements.\n\
7112
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
1718 \n\
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
1719 If the optional argument 'native' is given, then the sum is performed\n\
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
1720 in the same type as the original argument, rather than in the default\n\
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
1721 double type. For example\n\
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
1722 \n\
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
1723 @example\n\
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
1724 sum ([true, true])\n\
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
1725 @result{} 2\n\
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
1726 sum ([true, true], 'native')\n\
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
1727 @result{} true\n\
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
1728 @end example\n\
3428
5b77cf82393c [project @ 2000-01-14 02:54:53 by jwe]
jwe
parents: 3418
diff changeset
1729 @end deftypefn")
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1730 {
7112
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
1731 NATIVE_REDUCTION (sum);
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1732 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1733
7112
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
1734 /*
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
1735
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
1736 %!assert (sum([true,true]), 2)
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
1737 %!assert (sum([true,true],'native'), true)
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
1738 %!assert (sum(int8([127,10,-20])), 117);
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
1739 %!assert (sum(int8([127,10,-20]),'native'), int8(107));
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
1740
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
1741 */
f90a8188c9c2 [project @ 2007-11-07 00:24:11 by dbateman]
dbateman
parents: 7103
diff changeset
1742
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1940
diff changeset
1743 DEFUN (sumsq, args, ,
3428
5b77cf82393c [project @ 2000-01-14 02:54:53 by jwe]
jwe
parents: 3418
diff changeset
1744 "-*- texinfo -*-\n\
3723
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
1745 @deftypefn {Built-in Function} {} sumsq (@var{x}, @var{dim})\n\
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
1746 Sum of squares of elements along dimension @var{dim}. If @var{dim}\n\
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
1747 is omitted, it defaults to 1 (column-wise sum of squares).\n\
3095
528f4270e904 [project @ 1997-11-14 03:58:45 by jwe]
jwe
parents: 3014
diff changeset
1748 \n\
5061
4689ee5e88ec [project @ 2004-11-03 21:23:42 by jwe]
jwe
parents: 5058
diff changeset
1749 As a special case, if @var{x} is a vector and @var{dim} is omitted,\n\
4689ee5e88ec [project @ 2004-11-03 21:23:42 by jwe]
jwe
parents: 5058
diff changeset
1750 return the sum of squares of the elements.\n\
4689ee5e88ec [project @ 2004-11-03 21:23:42 by jwe]
jwe
parents: 5058
diff changeset
1751 \n\
4689ee5e88ec [project @ 2004-11-03 21:23:42 by jwe]
jwe
parents: 5058
diff changeset
1752 This function is conceptually equivalent to computing\n\
3723
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
1753 @example\n\
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
1754 sum (x .* conj (x), dim)\n\
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
1755 @end example\n\
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
1756 but it uses less memory and avoids calling conj if @var{x} is real.\n\
3428
5b77cf82393c [project @ 2000-01-14 02:54:53 by jwe]
jwe
parents: 3418
diff changeset
1757 @end deftypefn")
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1758 {
3723
4c3774db5b3c [project @ 2000-10-12 05:10:08 by jwe]
jwe
parents: 3665
diff changeset
1759 DATA_REDUCTION (sumsq);
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1760 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
1761
6688
b26a8e0e42cd [project @ 2007-06-04 06:25:21 by jwe]
jwe
parents: 6671
diff changeset
1762 DEFUN (islogical, args, ,
3428
5b77cf82393c [project @ 2000-01-14 02:54:53 by jwe]
jwe
parents: 3418
diff changeset
1763 "-*- texinfo -*-\n\
7144
30c0533e39ae [project @ 2007-11-09 17:37:24 by jwe]
jwe
parents: 7112
diff changeset
1764 @deftypefn {Built-in Function} {} islogical (@var{x})\n\
6688
b26a8e0e42cd [project @ 2007-06-04 06:25:21 by jwe]
jwe
parents: 6671
diff changeset
1765 Return true if @var{x} is a logical object.\n\
3439
3234a698073a [project @ 2000-01-14 09:51:14 by jwe]
jwe
parents: 3428
diff changeset
1766 @end deftypefn")
3209
fbb332b96e4f [project @ 1998-11-03 20:48:54 by jwe]
jwe
parents: 3206
diff changeset
1767 {
fbb332b96e4f [project @ 1998-11-03 20:48:54 by jwe]
jwe
parents: 3206
diff changeset
1768 octave_value retval;
fbb332b96e4f [project @ 1998-11-03 20:48:54 by jwe]
jwe
parents: 3206
diff changeset
1769
fbb332b96e4f [project @ 1998-11-03 20:48:54 by jwe]
jwe
parents: 3206
diff changeset
1770 if (args.length () == 1)
3258
4964d5391acc [project @ 1999-07-21 21:51:33 by jwe]
jwe
parents: 3238
diff changeset
1771 retval = args(0).is_bool_type ();
3209
fbb332b96e4f [project @ 1998-11-03 20:48:54 by jwe]
jwe
parents: 3206
diff changeset
1772 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
1773 print_usage ();
3209
fbb332b96e4f [project @ 1998-11-03 20:48:54 by jwe]
jwe
parents: 3206
diff changeset
1774
fbb332b96e4f [project @ 1998-11-03 20:48:54 by jwe]
jwe
parents: 3206
diff changeset
1775 return retval;
fbb332b96e4f [project @ 1998-11-03 20:48:54 by jwe]
jwe
parents: 3206
diff changeset
1776 }
fbb332b96e4f [project @ 1998-11-03 20:48:54 by jwe]
jwe
parents: 3206
diff changeset
1777
6688
b26a8e0e42cd [project @ 2007-06-04 06:25:21 by jwe]
jwe
parents: 6671
diff changeset
1778 DEFALIAS (isbool, islogical);
3209
fbb332b96e4f [project @ 1998-11-03 20:48:54 by jwe]
jwe
parents: 3206
diff changeset
1779
6223
a6cc01dd09f9 [project @ 2007-01-03 20:59:28 by jwe]
jwe
parents: 6197
diff changeset
1780 DEFUN (isinteger, args, ,
a6cc01dd09f9 [project @ 2007-01-03 20:59:28 by jwe]
jwe
parents: 6197
diff changeset
1781 "-*- texinfo -*-\n\
6230
06bee64edc08 [project @ 2007-01-08 16:59:35 by jwe]
jwe
parents: 6223
diff changeset
1782 @deftypefn {Built-in Function} {} isinteger (@var{x})\n\
6223
a6cc01dd09f9 [project @ 2007-01-03 20:59:28 by jwe]
jwe
parents: 6197
diff changeset
1783 Return true if @var{x} is an integer object (int8, uint8, int16, etc.).\n\
a6cc01dd09f9 [project @ 2007-01-03 20:59:28 by jwe]
jwe
parents: 6197
diff changeset
1784 Note that @code{isinteger (14)} is false because numeric constants in\n\
a6cc01dd09f9 [project @ 2007-01-03 20:59:28 by jwe]
jwe
parents: 6197
diff changeset
1785 are double precision floating point values.\n\
a6cc01dd09f9 [project @ 2007-01-03 20:59:28 by jwe]
jwe
parents: 6197
diff changeset
1786 @seealso{isreal, isnumeric, class, isa}\n\
a6cc01dd09f9 [project @ 2007-01-03 20:59:28 by jwe]
jwe
parents: 6197
diff changeset
1787 @end deftypefn")
a6cc01dd09f9 [project @ 2007-01-03 20:59:28 by jwe]
jwe
parents: 6197
diff changeset
1788 {
a6cc01dd09f9 [project @ 2007-01-03 20:59:28 by jwe]
jwe
parents: 6197
diff changeset
1789 octave_value retval;
a6cc01dd09f9 [project @ 2007-01-03 20:59:28 by jwe]
jwe
parents: 6197
diff changeset
1790
a6cc01dd09f9 [project @ 2007-01-03 20:59:28 by jwe]
jwe
parents: 6197
diff changeset
1791 if (args.length () == 1)
a6cc01dd09f9 [project @ 2007-01-03 20:59:28 by jwe]
jwe
parents: 6197
diff changeset
1792 retval = args(0).is_integer_type ();
a6cc01dd09f9 [project @ 2007-01-03 20:59:28 by jwe]
jwe
parents: 6197
diff changeset
1793 else
a6cc01dd09f9 [project @ 2007-01-03 20:59:28 by jwe]
jwe
parents: 6197
diff changeset
1794 print_usage ();
a6cc01dd09f9 [project @ 2007-01-03 20:59:28 by jwe]
jwe
parents: 6197
diff changeset
1795
a6cc01dd09f9 [project @ 2007-01-03 20:59:28 by jwe]
jwe
parents: 6197
diff changeset
1796 return retval;
a6cc01dd09f9 [project @ 2007-01-03 20:59:28 by jwe]
jwe
parents: 6197
diff changeset
1797 }
a6cc01dd09f9 [project @ 2007-01-03 20:59:28 by jwe]
jwe
parents: 6197
diff changeset
1798
4028
ef75c970c8f5 [project @ 2002-08-09 07:19:02 by jwe]
jwe
parents: 4025
diff changeset
1799 DEFUN (iscomplex, args, ,
3428
5b77cf82393c [project @ 2000-01-14 02:54:53 by jwe]
jwe
parents: 3418
diff changeset
1800 "-*- texinfo -*-\n\
4028
ef75c970c8f5 [project @ 2002-08-09 07:19:02 by jwe]
jwe
parents: 4025
diff changeset
1801 @deftypefn {Built-in Function} {} iscomplex (@var{x})\n\
3428
5b77cf82393c [project @ 2000-01-14 02:54:53 by jwe]
jwe
parents: 3418
diff changeset
1802 Return true if @var{x} is a complex-valued numeric object.\n\
5b77cf82393c [project @ 2000-01-14 02:54:53 by jwe]
jwe
parents: 3418
diff changeset
1803 @end deftypefn")
3186
edaa9a2d3d9c [project @ 1998-10-02 19:12:19 by jwe]
jwe
parents: 3174
diff changeset
1804 {
edaa9a2d3d9c [project @ 1998-10-02 19:12:19 by jwe]
jwe
parents: 3174
diff changeset
1805 octave_value retval;
edaa9a2d3d9c [project @ 1998-10-02 19:12:19 by jwe]
jwe
parents: 3174
diff changeset
1806
edaa9a2d3d9c [project @ 1998-10-02 19:12:19 by jwe]
jwe
parents: 3174
diff changeset
1807 if (args.length () == 1)
3258
4964d5391acc [project @ 1999-07-21 21:51:33 by jwe]
jwe
parents: 3238
diff changeset
1808 retval = args(0).is_complex_type ();
3186
edaa9a2d3d9c [project @ 1998-10-02 19:12:19 by jwe]
jwe
parents: 3174
diff changeset
1809 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
1810 print_usage ();
3186
edaa9a2d3d9c [project @ 1998-10-02 19:12:19 by jwe]
jwe
parents: 3174
diff changeset
1811
edaa9a2d3d9c [project @ 1998-10-02 19:12:19 by jwe]
jwe
parents: 3174
diff changeset
1812 return retval;
edaa9a2d3d9c [project @ 1998-10-02 19:12:19 by jwe]
jwe
parents: 3174
diff changeset
1813 }
edaa9a2d3d9c [project @ 1998-10-02 19:12:19 by jwe]
jwe
parents: 3174
diff changeset
1814
7576
7ebdc99a0bab new isfloat function
John W. Eaton <jwe@octave.org>
parents: 7515
diff changeset
1815 DEFUN (isfloat, args, ,
7ebdc99a0bab new isfloat function
John W. Eaton <jwe@octave.org>
parents: 7515
diff changeset
1816 "-*- texinfo -*-\n\
7ebdc99a0bab new isfloat function
John W. Eaton <jwe@octave.org>
parents: 7515
diff changeset
1817 @deftypefn {Built-in Function} {} isfloat (@var{x})\n\
7ebdc99a0bab new isfloat function
John W. Eaton <jwe@octave.org>
parents: 7515
diff changeset
1818 Return true if @var{x} is a floating-point numeric object.\n\
7ebdc99a0bab new isfloat function
John W. Eaton <jwe@octave.org>
parents: 7515
diff changeset
1819 @end deftypefn")
7ebdc99a0bab new isfloat function
John W. Eaton <jwe@octave.org>
parents: 7515
diff changeset
1820 {
7ebdc99a0bab new isfloat function
John W. Eaton <jwe@octave.org>
parents: 7515
diff changeset
1821 octave_value retval;
7ebdc99a0bab new isfloat function
John W. Eaton <jwe@octave.org>
parents: 7515
diff changeset
1822
7ebdc99a0bab new isfloat function
John W. Eaton <jwe@octave.org>
parents: 7515
diff changeset
1823 if (args.length () == 1)
7ebdc99a0bab new isfloat function
John W. Eaton <jwe@octave.org>
parents: 7515
diff changeset
1824 retval = args(0).is_float_type ();
7ebdc99a0bab new isfloat function
John W. Eaton <jwe@octave.org>
parents: 7515
diff changeset
1825 else
7ebdc99a0bab new isfloat function
John W. Eaton <jwe@octave.org>
parents: 7515
diff changeset
1826 print_usage ();
7ebdc99a0bab new isfloat function
John W. Eaton <jwe@octave.org>
parents: 7515
diff changeset
1827
7ebdc99a0bab new isfloat function
John W. Eaton <jwe@octave.org>
parents: 7515
diff changeset
1828 return retval;
7ebdc99a0bab new isfloat function
John W. Eaton <jwe@octave.org>
parents: 7515
diff changeset
1829 }
7ebdc99a0bab new isfloat function
John W. Eaton <jwe@octave.org>
parents: 7515
diff changeset
1830
5775
ace8d8d26933 [project @ 2006-04-24 19:13:06 by jwe]
jwe
parents: 5747
diff changeset
1831 // FIXME -- perhaps this should be implemented with an
5476
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1832 // octave_value member function?
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1833
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1834 DEFUN (complex, args, ,
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1835 "-*- texinfo -*-\n\
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1836 @deftypefn {Built-in Function} {} complex (@var{val})\n\
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1837 @deftypefnx {Built-in Function} {} complex (@var{re}, @var{im})\n\
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1838 Convert @var{x} to a complex value.\n\
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1839 @end deftypefn")
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1840 {
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1841 octave_value retval;
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1842
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1843 int nargin = args.length ();
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1844
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1845 if (nargin == 1)
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1846 {
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1847 octave_value arg = args(0);
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1848
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1849 if (arg.is_complex_type ())
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1850 retval = arg;
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1851 else
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1852 {
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1853 if (arg.numel () == 1)
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1854 {
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1855 Complex val = arg.complex_value ();
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1856
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1857 if (! error_state)
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1858 retval = octave_value (new octave_complex (val));
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1859 }
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1860 else
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1861 {
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1862 ComplexNDArray val = arg.complex_array_value ();
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1863
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1864 if (! error_state)
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1865 retval = octave_value (new octave_complex_matrix (val));
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1866 }
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1867
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1868 if (error_state)
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1869 error ("complex: invalid conversion");
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1870 }
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1871 }
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1872 else if (nargin == 2)
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1873 {
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1874 octave_value re = args(0);
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1875 octave_value im = args(1);
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1876
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1877 if (re.numel () == 1)
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1878 {
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1879 double re_val = re.double_value ();
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1880
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1881 if (im.numel () == 1)
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1882 {
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1883 double im_val = im.double_value ();
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1884
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1885 if (! error_state)
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1886 retval = octave_value (new octave_complex (Complex (re_val, im_val)));
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1887 }
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1888 else
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1889 {
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1890 const NDArray im_val = im.array_value ();
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1891
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1892 if (! error_state)
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1893 {
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1894 ComplexNDArray result (im_val.dims (), Complex ());
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1895
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1896 for (octave_idx_type i = 0; i < im_val.numel (); i++)
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1897 result.xelem (i) = Complex (re_val, im_val(i));
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1898
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1899 retval = octave_value (new octave_complex_matrix (result));
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1900 }
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1901 }
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1902 }
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1903 else
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1904 {
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1905 const NDArray re_val = re.array_value ();
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1906
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1907 if (im.numel () == 1)
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1908 {
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1909 double im_val = im.double_value ();
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1910
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1911 if (! error_state)
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1912 {
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1913 ComplexNDArray result (re_val.dims (), Complex ());
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1914
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1915 for (octave_idx_type i = 0; i < re_val.numel (); i++)
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1916 result.xelem (i) = Complex (re_val(i), im_val);
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1917
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1918 retval = octave_value (new octave_complex_matrix (result));
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1919 }
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1920 }
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1921 else
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1922 {
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1923 const NDArray im_val = im.array_value ();
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1924
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1925 if (! error_state)
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1926 {
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1927 if (re_val.dims () == im_val.dims ())
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1928 {
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1929 ComplexNDArray result (re_val.dims (), Complex ());
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1930
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1931 for (octave_idx_type i = 0; i < re_val.numel (); i++)
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1932 result.xelem (i) = Complex (re_val(i), im_val(i));
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1933
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1934 retval = octave_value (new octave_complex_matrix (result));
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1935 }
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1936 else
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1937 error ("complex: dimension mismatch");
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1938 }
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1939 }
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1940 }
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1941
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1942 if (error_state)
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1943 error ("complex: invalid conversion");
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1944 }
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1945 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
1946 print_usage ();
5476
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1947
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1948 return retval;
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1949 }
941f0fc6b596 [project @ 2005-09-29 22:46:07 by jwe]
jwe
parents: 5333
diff changeset
1950
3258
4964d5391acc [project @ 1999-07-21 21:51:33 by jwe]
jwe
parents: 3238
diff changeset
1951 DEFUN (isreal, args, ,
3428
5b77cf82393c [project @ 2000-01-14 02:54:53 by jwe]
jwe
parents: 3418
diff changeset
1952 "-*- texinfo -*-\n\
5b77cf82393c [project @ 2000-01-14 02:54:53 by jwe]
jwe
parents: 3418
diff changeset
1953 @deftypefn {Built-in Function} {} isreal (@var{x})\n\
5b77cf82393c [project @ 2000-01-14 02:54:53 by jwe]
jwe
parents: 3418
diff changeset
1954 Return true if @var{x} is a real-valued numeric object.\n\
5b77cf82393c [project @ 2000-01-14 02:54:53 by jwe]
jwe
parents: 3418
diff changeset
1955 @end deftypefn")
3258
4964d5391acc [project @ 1999-07-21 21:51:33 by jwe]
jwe
parents: 3238
diff changeset
1956 {
4964d5391acc [project @ 1999-07-21 21:51:33 by jwe]
jwe
parents: 3238
diff changeset
1957 octave_value retval;
4964d5391acc [project @ 1999-07-21 21:51:33 by jwe]
jwe
parents: 3238
diff changeset
1958
4964d5391acc [project @ 1999-07-21 21:51:33 by jwe]
jwe
parents: 3238
diff changeset
1959 if (args.length () == 1)
4964d5391acc [project @ 1999-07-21 21:51:33 by jwe]
jwe
parents: 3238
diff changeset
1960 retval = args(0).is_real_type ();
4964d5391acc [project @ 1999-07-21 21:51:33 by jwe]
jwe
parents: 3238
diff changeset
1961 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
1962 print_usage ();
3258
4964d5391acc [project @ 1999-07-21 21:51:33 by jwe]
jwe
parents: 3238
diff changeset
1963
4964d5391acc [project @ 1999-07-21 21:51:33 by jwe]
jwe
parents: 3238
diff changeset
1964 return retval;
4964d5391acc [project @ 1999-07-21 21:51:33 by jwe]
jwe
parents: 3238
diff changeset
1965 }
4964d5391acc [project @ 1999-07-21 21:51:33 by jwe]
jwe
parents: 3238
diff changeset
1966
3202
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3195
diff changeset
1967 DEFUN (isempty, args, ,
3373
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3369
diff changeset
1968 "-*- texinfo -*-\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3369
diff changeset
1969 @deftypefn {Built-in Function} {} isempty (@var{a})\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3369
diff changeset
1970 Return 1 if @var{a} is an empty matrix (either the number of rows, or\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3369
diff changeset
1971 the number of columns, or both are zero). Otherwise, return 0.\n\
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3369
diff changeset
1972 @end deftypefn")
3202
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3195
diff changeset
1973 {
4233
ccfdb55c8156 [project @ 2002-12-20 22:43:54 by jwe]
jwe
parents: 4176
diff changeset
1974 octave_value retval = false;
3202
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3195
diff changeset
1975
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3195
diff changeset
1976 if (args.length () == 1)
4559
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4556
diff changeset
1977 retval = args(0).is_empty ();
3202
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3195
diff changeset
1978 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
1979 print_usage ();
3202
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3195
diff changeset
1980
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3195
diff changeset
1981 return retval;
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3195
diff changeset
1982 }
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3195
diff changeset
1983
3206
d0d2b69dc6c2 [project @ 1998-11-03 02:43:31 by jwe]
jwe
parents: 3204
diff changeset
1984 DEFUN (isnumeric, args, ,
3428
5b77cf82393c [project @ 2000-01-14 02:54:53 by jwe]
jwe
parents: 3418
diff changeset
1985 "-*- texinfo -*-\n\
5b77cf82393c [project @ 2000-01-14 02:54:53 by jwe]
jwe
parents: 3418
diff changeset
1986 @deftypefn {Built-in Function} {} isnumeric (@var{x})\n\
5b77cf82393c [project @ 2000-01-14 02:54:53 by jwe]
jwe
parents: 3418
diff changeset
1987 Return nonzero if @var{x} is a numeric object.\n\
5b77cf82393c [project @ 2000-01-14 02:54:53 by jwe]
jwe
parents: 3418
diff changeset
1988 @end deftypefn")
3206
d0d2b69dc6c2 [project @ 1998-11-03 02:43:31 by jwe]
jwe
parents: 3204
diff changeset
1989 {
d0d2b69dc6c2 [project @ 1998-11-03 02:43:31 by jwe]
jwe
parents: 3204
diff changeset
1990 octave_value retval;
d0d2b69dc6c2 [project @ 1998-11-03 02:43:31 by jwe]
jwe
parents: 3204
diff changeset
1991
d0d2b69dc6c2 [project @ 1998-11-03 02:43:31 by jwe]
jwe
parents: 3204
diff changeset
1992 if (args.length () == 1)
3258
4964d5391acc [project @ 1999-07-21 21:51:33 by jwe]
jwe
parents: 3238
diff changeset
1993 retval = args(0).is_numeric_type ();
3206
d0d2b69dc6c2 [project @ 1998-11-03 02:43:31 by jwe]
jwe
parents: 3204
diff changeset
1994 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
1995 print_usage ();
3206
d0d2b69dc6c2 [project @ 1998-11-03 02:43:31 by jwe]
jwe
parents: 3204
diff changeset
1996
d0d2b69dc6c2 [project @ 1998-11-03 02:43:31 by jwe]
jwe
parents: 3204
diff changeset
1997 return retval;
d0d2b69dc6c2 [project @ 1998-11-03 02:43:31 by jwe]
jwe
parents: 3204
diff changeset
1998 }
d0d2b69dc6c2 [project @ 1998-11-03 02:43:31 by jwe]
jwe
parents: 3204
diff changeset
1999
4028
ef75c970c8f5 [project @ 2002-08-09 07:19:02 by jwe]
jwe
parents: 4025
diff changeset
2000 DEFUN (islist, args, ,
3526
cc21933776a1 [project @ 2000-02-02 10:53:27 by jwe]
jwe
parents: 3523
diff changeset
2001 "-*- texinfo -*-\n\
4028
ef75c970c8f5 [project @ 2002-08-09 07:19:02 by jwe]
jwe
parents: 4025
diff changeset
2002 @deftypefn {Built-in Function} {} islist (@var{x})\n\
3428
5b77cf82393c [project @ 2000-01-14 02:54:53 by jwe]
jwe
parents: 3418
diff changeset
2003 Return nonzero if @var{x} is a list.\n\
5b77cf82393c [project @ 2000-01-14 02:54:53 by jwe]
jwe
parents: 3418
diff changeset
2004 @end deftypefn")
3204
81738e630f57 [project @ 1998-10-30 23:28:29 by jwe]
jwe
parents: 3202
diff changeset
2005 {
81738e630f57 [project @ 1998-10-30 23:28:29 by jwe]
jwe
parents: 3202
diff changeset
2006 octave_value retval;
81738e630f57 [project @ 1998-10-30 23:28:29 by jwe]
jwe
parents: 3202
diff changeset
2007
81738e630f57 [project @ 1998-10-30 23:28:29 by jwe]
jwe
parents: 3202
diff changeset
2008 if (args.length () == 1)
3258
4964d5391acc [project @ 1999-07-21 21:51:33 by jwe]
jwe
parents: 3238
diff changeset
2009 retval = args(0).is_list ();
3204
81738e630f57 [project @ 1998-10-30 23:28:29 by jwe]
jwe
parents: 3202
diff changeset
2010 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
2011 print_usage ();
3204
81738e630f57 [project @ 1998-10-30 23:28:29 by jwe]
jwe
parents: 3202
diff changeset
2012
81738e630f57 [project @ 1998-10-30 23:28:29 by jwe]
jwe
parents: 3202
diff changeset
2013 return retval;
81738e630f57 [project @ 1998-10-30 23:28:29 by jwe]
jwe
parents: 3202
diff changeset
2014 }
81738e630f57 [project @ 1998-10-30 23:28:29 by jwe]
jwe
parents: 3202
diff changeset
2015
4028
ef75c970c8f5 [project @ 2002-08-09 07:19:02 by jwe]
jwe
parents: 4025
diff changeset
2016 DEFUN (ismatrix, args, ,
3321
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 3307
diff changeset
2017 "-*- texinfo -*-\n\
4028
ef75c970c8f5 [project @ 2002-08-09 07:19:02 by jwe]
jwe
parents: 4025
diff changeset
2018 @deftypefn {Built-in Function} {} ismatrix (@var{a})\n\
3321
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 3307
diff changeset
2019 Return 1 if @var{a} is a matrix. Otherwise, return 0.\n\
3333
15cddaacbc2d [project @ 1999-11-03 19:53:59 by jwe]
jwe
parents: 3322
diff changeset
2020 @end deftypefn")
3202
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3195
diff changeset
2021 {
4233
ccfdb55c8156 [project @ 2002-12-20 22:43:54 by jwe]
jwe
parents: 4176
diff changeset
2022 octave_value retval = false;
3202
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3195
diff changeset
2023
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3195
diff changeset
2024 if (args.length () == 1)
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3195
diff changeset
2025 {
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3195
diff changeset
2026 octave_value arg = args(0);
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3195
diff changeset
2027
3212
bf61c443a366 [project @ 1998-11-05 04:24:45 by jwe]
jwe
parents: 3209
diff changeset
2028 if (arg.is_scalar_type () || arg.is_range ())
4233
ccfdb55c8156 [project @ 2002-12-20 22:43:54 by jwe]
jwe
parents: 4176
diff changeset
2029 retval = true;
3202
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3195
diff changeset
2030 else if (arg.is_matrix_type ())
4233
ccfdb55c8156 [project @ 2002-12-20 22:43:54 by jwe]
jwe
parents: 4176
diff changeset
2031 retval = (arg.rows () >= 1 && arg.columns () >= 1);
3202
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3195
diff changeset
2032 }
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3195
diff changeset
2033 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
2034 print_usage ();
3202
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3195
diff changeset
2035
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3195
diff changeset
2036 return retval;
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3195
diff changeset
2037 }
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3195
diff changeset
2038
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3333
diff changeset
2039 static octave_value
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2040 fill_matrix (const octave_value_list& args, int val, const char *fcn)
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
2041 {
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3333
diff changeset
2042 octave_value retval;
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
2043
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
2044 int nargin = args.length ();
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
2045
4946
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2046 oct_data_conv::data_type dt = oct_data_conv::dt_double;
4481
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4479
diff changeset
2047
4946
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2048 dim_vector dims (1, 1);
4481
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4479
diff changeset
2049
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4479
diff changeset
2050 if (nargin > 0 && args(nargin-1).is_string ())
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4479
diff changeset
2051 {
4946
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2052 std::string nm = args(nargin-1).string_value ();
4481
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4479
diff changeset
2053 nargin--;
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4479
diff changeset
2054
4946
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2055 dt = oct_data_conv::string_to_data_type (nm);
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2056
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2057 if (error_state)
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2058 return retval;
4481
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4479
diff changeset
2059 }
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4479
diff changeset
2060
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
2061 switch (nargin)
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
2062 {
712
36ba0576bd1b [project @ 1994-09-19 14:18:15 by jwe]
jwe
parents: 649
diff changeset
2063 case 0:
36ba0576bd1b [project @ 1994-09-19 14:18:15 by jwe]
jwe
parents: 649
diff changeset
2064 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 767
diff changeset
2065
610
14b2a186a5c0 [project @ 1994-08-14 00:55:49 by jwe]
jwe
parents: 597
diff changeset
2066 case 1:
4481
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4479
diff changeset
2067 get_dimensions (args(0), fcn, dims);
610
14b2a186a5c0 [project @ 1994-08-14 00:55:49 by jwe]
jwe
parents: 597
diff changeset
2068 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 767
diff changeset
2069
4563
742993a501b9 [project @ 2003-10-29 06:25:12 by jwe]
jwe
parents: 4559
diff changeset
2070 default:
742993a501b9 [project @ 2003-10-29 06:25:12 by jwe]
jwe
parents: 4559
diff changeset
2071 {
742993a501b9 [project @ 2003-10-29 06:25:12 by jwe]
jwe
parents: 4559
diff changeset
2072 dims.resize (nargin);
4481
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4479
diff changeset
2073
4563
742993a501b9 [project @ 2003-10-29 06:25:12 by jwe]
jwe
parents: 4559
diff changeset
2074 for (int i = 0; i < nargin; i++)
742993a501b9 [project @ 2003-10-29 06:25:12 by jwe]
jwe
parents: 4559
diff changeset
2075 {
6133
e0065af38cf4 [project @ 2006-11-02 03:33:50 by jwe]
jwe
parents: 5991
diff changeset
2076 dims(i) = args(i).is_empty () ? 0 : args(i).idx_type_value ();
4481
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4479
diff changeset
2077
4563
742993a501b9 [project @ 2003-10-29 06:25:12 by jwe]
jwe
parents: 4559
diff changeset
2078 if (error_state)
742993a501b9 [project @ 2003-10-29 06:25:12 by jwe]
jwe
parents: 4559
diff changeset
2079 {
4732
b484cdca27be [project @ 2004-02-04 04:32:48 by jwe]
jwe
parents: 4685
diff changeset
2080 error ("%s: expecting scalar integer arguments", fcn);
4563
742993a501b9 [project @ 2003-10-29 06:25:12 by jwe]
jwe
parents: 4559
diff changeset
2081 break;
742993a501b9 [project @ 2003-10-29 06:25:12 by jwe]
jwe
parents: 4559
diff changeset
2082 }
742993a501b9 [project @ 2003-10-29 06:25:12 by jwe]
jwe
parents: 4559
diff changeset
2083 }
742993a501b9 [project @ 2003-10-29 06:25:12 by jwe]
jwe
parents: 4559
diff changeset
2084 }
742993a501b9 [project @ 2003-10-29 06:25:12 by jwe]
jwe
parents: 4559
diff changeset
2085 break;
4481
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4479
diff changeset
2086 }
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4479
diff changeset
2087
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4479
diff changeset
2088 if (! error_state)
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4479
diff changeset
2089 {
4946
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2090 dims.chop_trailing_singletons ();
4565
1db951a4fcd5 [project @ 2003-10-29 13:49:30 by jwe]
jwe
parents: 4563
diff changeset
2091
4481
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4479
diff changeset
2092 check_dimensions (dims, fcn);
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3333
diff changeset
2093
5775
ace8d8d26933 [project @ 2006-04-24 19:13:06 by jwe]
jwe
parents: 5747
diff changeset
2094 // FIXME -- perhaps this should be made extensible by
4946
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2095 // using the class name to lookup a function to call to create
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2096 // the new value.
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2097
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2098 // Note that automatic narrowing will handle conversion from
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2099 // NDArray to scalar.
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2100
4481
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4479
diff changeset
2101 if (! error_state)
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4479
diff changeset
2102 {
4946
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2103 switch (dt)
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2104 {
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2105 case oct_data_conv::dt_int8:
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2106 retval = int8NDArray (dims, val);
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2107 break;
4481
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4479
diff changeset
2108
4946
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2109 case oct_data_conv::dt_uint8:
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2110 retval = uint8NDArray (dims, val);
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2111 break;
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2112
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2113 case oct_data_conv::dt_int16:
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2114 retval = int16NDArray (dims, val);
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2115 break;
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2116
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2117 case oct_data_conv::dt_uint16:
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2118 retval = uint16NDArray (dims, val);
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2119 break;
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2120
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2121 case oct_data_conv::dt_int32:
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2122 retval = int32NDArray (dims, val);
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2123 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 767
diff changeset
2124
4946
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2125 case oct_data_conv::dt_uint32:
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2126 retval = uint32NDArray (dims, val);
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2127 break;
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2128
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2129 case oct_data_conv::dt_int64:
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2130 retval = int64NDArray (dims, val);
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2131 break;
4481
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4479
diff changeset
2132
4946
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2133 case oct_data_conv::dt_uint64:
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2134 retval = uint64NDArray (dims, val);
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2135 break;
4481
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4479
diff changeset
2136
5775
ace8d8d26933 [project @ 2006-04-24 19:13:06 by jwe]
jwe
parents: 5747
diff changeset
2137 case oct_data_conv::dt_single: // FIXME
4946
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2138 case oct_data_conv::dt_double:
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2139 retval = NDArray (dims, val);
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2140 break;
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2141
4986
fac558699d0f [project @ 2004-09-10 15:57:13 by jwe]
jwe
parents: 4948
diff changeset
2142 case oct_data_conv::dt_logical:
fac558699d0f [project @ 2004-09-10 15:57:13 by jwe]
jwe
parents: 4948
diff changeset
2143 retval = boolNDArray (dims, val);
fac558699d0f [project @ 2004-09-10 15:57:13 by jwe]
jwe
parents: 4948
diff changeset
2144 break;
fac558699d0f [project @ 2004-09-10 15:57:13 by jwe]
jwe
parents: 4948
diff changeset
2145
4946
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2146 default:
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2147 error ("%s: invalid class name", fcn);
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2148 break;
4481
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4479
diff changeset
2149 }
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4479
diff changeset
2150 }
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
2151 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
2152
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
2153 return retval;
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
2154 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
2155
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2156 static octave_value
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2157 fill_matrix (const octave_value_list& args, double val, const char *fcn)
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2158 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2159 octave_value retval;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2160
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2161 int nargin = args.length ();
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2162
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2163 oct_data_conv::data_type dt = oct_data_conv::dt_double;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2164
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2165 dim_vector dims (1, 1);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2166
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2167 if (nargin > 0 && args(nargin-1).is_string ())
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2168 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2169 std::string nm = args(nargin-1).string_value ();
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2170 nargin--;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2171
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2172 dt = oct_data_conv::string_to_data_type (nm);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2173
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2174 if (error_state)
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2175 return retval;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2176 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2177
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2178 switch (nargin)
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2179 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2180 case 0:
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2181 break;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2182
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2183 case 1:
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2184 get_dimensions (args(0), fcn, dims);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2185 break;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2186
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2187 default:
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2188 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2189 dims.resize (nargin);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2190
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2191 for (int i = 0; i < nargin; i++)
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2192 {
6133
e0065af38cf4 [project @ 2006-11-02 03:33:50 by jwe]
jwe
parents: 5991
diff changeset
2193 dims(i) = args(i).is_empty () ? 0 : args(i).idx_type_value ();
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2194
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2195 if (error_state)
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2196 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2197 error ("%s: expecting scalar integer arguments", fcn);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2198 break;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2199 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2200 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2201 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2202 break;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2203 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2204
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2205 if (! error_state)
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2206 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2207 dims.chop_trailing_singletons ();
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2208
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2209 check_dimensions (dims, fcn);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2210
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2211 // Note that automatic narrowing will handle conversion from
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2212 // NDArray to scalar.
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2213
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2214 if (! error_state)
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2215 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2216 switch (dt)
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2217 {
5775
ace8d8d26933 [project @ 2006-04-24 19:13:06 by jwe]
jwe
parents: 5747
diff changeset
2218 case oct_data_conv::dt_single: // FIXME
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2219 case oct_data_conv::dt_double:
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2220 retval = NDArray (dims, val);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2221 break;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2222
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2223 default:
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2224 error ("%s: invalid class name", fcn);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2225 break;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2226 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2227 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2228 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2229
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2230 return retval;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2231 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2232
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2233 static octave_value
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2234 fill_matrix (const octave_value_list& args, const Complex& val,
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2235 const char *fcn)
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2236 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2237 octave_value retval;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2238
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2239 int nargin = args.length ();
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2240
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2241 oct_data_conv::data_type dt = oct_data_conv::dt_double;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2242
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2243 dim_vector dims (1, 1);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2244
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2245 if (nargin > 0 && args(nargin-1).is_string ())
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2246 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2247 std::string nm = args(nargin-1).string_value ();
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2248 nargin--;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2249
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2250 dt = oct_data_conv::string_to_data_type (nm);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2251
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2252 if (error_state)
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2253 return retval;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2254 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2255
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2256 switch (nargin)
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2257 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2258 case 0:
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2259 break;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2260
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2261 case 1:
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2262 get_dimensions (args(0), fcn, dims);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2263 break;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2264
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2265 default:
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2266 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2267 dims.resize (nargin);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2268
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2269 for (int i = 0; i < nargin; i++)
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2270 {
6133
e0065af38cf4 [project @ 2006-11-02 03:33:50 by jwe]
jwe
parents: 5991
diff changeset
2271 dims(i) = args(i).is_empty () ? 0 : args(i).idx_type_value ();
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2272
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2273 if (error_state)
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2274 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2275 error ("%s: expecting scalar integer arguments", fcn);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2276 break;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2277 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2278 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2279 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2280 break;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2281 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2282
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2283 if (! error_state)
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2284 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2285 dims.chop_trailing_singletons ();
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2286
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2287 check_dimensions (dims, fcn);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2288
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2289 // Note that automatic narrowing will handle conversion from
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2290 // NDArray to scalar.
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2291
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2292 if (! error_state)
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2293 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2294 switch (dt)
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2295 {
5775
ace8d8d26933 [project @ 2006-04-24 19:13:06 by jwe]
jwe
parents: 5747
diff changeset
2296 case oct_data_conv::dt_single: // FIXME
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2297 case oct_data_conv::dt_double:
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2298 retval = ComplexNDArray (dims, val);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2299 break;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2300
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2301 default:
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2302 error ("%s: invalid class name", fcn);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2303 break;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2304 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2305 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2306 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2307
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2308 return retval;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2309 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2310
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2311 static octave_value
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2312 fill_matrix (const octave_value_list& args, bool val, const char *fcn)
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2313 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2314 octave_value retval;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2315
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2316 int nargin = args.length ();
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2317
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2318 dim_vector dims (1, 1);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2319
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2320 switch (nargin)
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2321 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2322 case 0:
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2323 break;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2324
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2325 case 1:
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2326 get_dimensions (args(0), fcn, dims);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2327 break;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2328
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2329 default:
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2330 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2331 dims.resize (nargin);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2332
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2333 for (int i = 0; i < nargin; i++)
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2334 {
6133
e0065af38cf4 [project @ 2006-11-02 03:33:50 by jwe]
jwe
parents: 5991
diff changeset
2335 dims(i) = args(i).is_empty () ? 0 : args(i).idx_type_value ();
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2336
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2337 if (error_state)
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2338 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2339 error ("%s: expecting scalar integer arguments", fcn);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2340 break;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2341 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2342 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2343 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2344 break;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2345 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2346
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2347 if (! error_state)
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2348 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2349 dims.chop_trailing_singletons ();
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2350
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2351 check_dimensions (dims, fcn);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2352
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2353 // Note that automatic narrowing will handle conversion from
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2354 // NDArray to scalar.
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2355
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2356 if (! error_state)
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2357 retval = boolNDArray (dims, val);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2358 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2359
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2360 return retval;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2361 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2362
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3333
diff changeset
2363 DEFUN (ones, args, ,
3369
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
2364 "-*- texinfo -*-\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
2365 @deftypefn {Built-in Function} {} ones (@var{x})\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
2366 @deftypefnx {Built-in Function} {} ones (@var{n}, @var{m})\n\
4948
7124436476cb [project @ 2004-08-31 17:57:21 by jwe]
jwe
parents: 4947
diff changeset
2367 @deftypefnx {Built-in Function} {} ones (@var{n}, @var{m}, @var{k}, @dots{})\n\
7124436476cb [project @ 2004-08-31 17:57:21 by jwe]
jwe
parents: 4947
diff changeset
2368 @deftypefnx {Built-in Function} {} ones (@dots{}, @var{class})\n\
4481
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4479
diff changeset
2369 Return a matrix or N-dimensional array whose elements are all 1.\n\
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4479
diff changeset
2370 The arguments are handled the same as the arguments for @code{eye}.\n\
3369
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
2371 \n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
2372 If you need to create a matrix whose values are all the same, you should\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
2373 use an expression like\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
2374 \n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
2375 @example\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
2376 val_matrix = val * ones (n, m)\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
2377 @end example\n\
4945
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
2378 \n\
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
2379 The optional argument @var{class}, allows @code{ones} to return an array of\n\
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2380 the specified type, for example\n\
4945
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
2381 \n\
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
2382 @example\n\
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
2383 val = ones (n,m, \"uint8\")\n\
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
2384 @end example\n\
3369
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
2385 @end deftypefn")
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
2386 {
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2387 return fill_matrix (args, 1, "ones");
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
2388 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
2389
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3333
diff changeset
2390 DEFUN (zeros, args, ,
3369
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
2391 "-*- texinfo -*-\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
2392 @deftypefn {Built-in Function} {} zeros (@var{x})\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
2393 @deftypefnx {Built-in Function} {} zeros (@var{n}, @var{m})\n\
4948
7124436476cb [project @ 2004-08-31 17:57:21 by jwe]
jwe
parents: 4947
diff changeset
2394 @deftypefnx {Built-in Function} {} zeros (@var{n}, @var{m}, @var{k}, @dots{})\n\
7124436476cb [project @ 2004-08-31 17:57:21 by jwe]
jwe
parents: 4947
diff changeset
2395 @deftypefnx {Built-in Function} {} zeros (@dots{}, @var{class})\n\
4481
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4479
diff changeset
2396 Return a matrix or N-dimensional array whose elements are all 0.\n\
cfbaee1f562f [project @ 2003-08-06 13:56:07 by jwe]
jwe
parents: 4479
diff changeset
2397 The arguments are handled the same as the arguments for @code{eye}.\n\
4945
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
2398 \n\
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
2399 The optional argument @var{class}, allows @code{zeros} to return an array of\n\
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2400 the specified type, for example\n\
4945
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
2401 \n\
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
2402 @example\n\
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
2403 val = zeros (n,m, \"uint8\")\n\
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
2404 @end example\n\
3369
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
2405 @end deftypefn")
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
2406 {
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2407 return fill_matrix (args, 0, "zeros");
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2408 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2409
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2410 DEFUN (Inf, args, ,
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2411 "-*- texinfo -*-\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2412 @deftypefn {Built-in Function} {} Inf (@var{x})\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2413 @deftypefnx {Built-in Function} {} Inf (@var{n}, @var{m})\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2414 @deftypefnx {Built-in Function} {} Inf (@var{n}, @var{m}, @var{k}, @dots{})\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2415 @deftypefnx {Built-in Function} {} Inf (@dots{}, @var{class})\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2416 Return a matrix or N-dimensional array whose elements are all Infinity.\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2417 The arguments are handled the same as the arguments for @code{eye}.\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2418 The optional argument @var{class} may be either @samp{\"single\"} or\n\
5798
7e7ed81f5566 [project @ 2006-05-09 17:24:33 by jwe]
jwe
parents: 5775
diff changeset
2419 @samp{\"double\"}. The default is @samp{\"double\"}.\n\
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2420 @end deftypefn")
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2421 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2422 return fill_matrix (args, lo_ieee_inf_value (), "Inf");
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2423 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2424
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2425 DEFALIAS (inf, Inf);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2426
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2427 DEFUN (NaN, args, ,
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2428 "-*- texinfo -*-\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2429 @deftypefn {Built-in Function} {} NaN (@var{x})\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2430 @deftypefnx {Built-in Function} {} NaN (@var{n}, @var{m})\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2431 @deftypefnx {Built-in Function} {} NaN (@var{n}, @var{m}, @var{k}, @dots{})\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2432 @deftypefnx {Built-in Function} {} NaN (@dots{}, @var{class})\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2433 Return a matrix or N-dimensional array whose elements are all NaN\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2434 (Not a Number). The value NaN is the result of an operation like\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2435 @iftex\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2436 @tex\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2437 $0/0$, or $\\infty - \\infty$,\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2438 @end tex\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2439 @end iftex\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2440 @ifinfo\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2441 0/0, or @samp{Inf - Inf},\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2442 @end ifinfo\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2443 or any operation with a NaN.\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2444 \n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2445 Note that NaN always compares not equal to NaN. This behavior is\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2446 specified by the IEEE standard for floating point arithmetic. To\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2447 find NaN values, you must use the @code{isnan} function.\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2448 \n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2449 The arguments are handled the same as the arguments for @code{eye}.\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2450 The optional argument @var{class} may be either @samp{\"single\"} or\n\
5798
7e7ed81f5566 [project @ 2006-05-09 17:24:33 by jwe]
jwe
parents: 5775
diff changeset
2451 @samp{\"double\"}. The default is @samp{\"double\"}.\n\
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2452 @end deftypefn")
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2453 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2454 return fill_matrix (args, lo_ieee_nan_value (), "NaN");
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2455 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2456
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2457 DEFALIAS (nan, NaN);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2458
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2459 DEFUN (e, args, ,
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2460 "-*- texinfo -*-\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2461 @deftypefn {Built-in Function} {} e (@var{x})\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2462 @deftypefnx {Built-in Function} {} e (@var{n}, @var{m})\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2463 @deftypefnx {Built-in Function} {} e (@var{n}, @var{m}, @var{k}, @dots{})\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2464 @deftypefnx {Built-in Function} {} e (@dots{}, @var{class})\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2465 Return a matrix or N-dimensional array whose elements are all equal\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2466 to the base of natural logarithms. The constant\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2467 @iftex\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2468 @tex\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2469 $e$\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2470 @end tex\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2471 @end iftex\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2472 @ifinfo\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2473 @var{e}\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2474 @end ifinfo\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2475 satisfies the equation\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2476 @iftex\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2477 @tex\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2478 $\\log (e) = 1$.\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2479 @end tex\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2480 @end iftex\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2481 @ifinfo\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2482 @code{log} (@var{e}) = 1.\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2483 @end ifinfo\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2484 @end deftypefn")
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2485 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2486 #if defined (M_E)
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2487 double e_val = M_E;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2488 #else
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2489 double e_val = exp (1.0);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2490 #endif
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2491
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2492 return fill_matrix (args, e_val, "e");
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2493 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2494
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2495 DEFUN (eps, args, ,
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2496 "-*- texinfo -*-\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2497 @deftypefn {Built-in Function} {} eps (@var{x})\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2498 @deftypefnx {Built-in Function} {} eps (@var{n}, @var{m})\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2499 @deftypefnx {Built-in Function} {} eps (@var{n}, @var{m}, @var{k}, @dots{})\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2500 @deftypefnx {Built-in Function} {} eps (@dots{}, @var{class})\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2501 Return a matrix or N-dimensional array whose elements are all eps,\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2502 the machine precision. More precisely, @code{eps} is the largest\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2503 relative spacing between any two adjacent numbers in the machine's\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2504 floating point system. This number is obviously system-dependent. On\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2505 machines that support 64 bit IEEE floating point arithmetic, @code{eps}\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2506 is approximately\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2507 @ifinfo\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2508 2.2204e-16.\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2509 @end ifinfo\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2510 @iftex\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2511 @tex\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2512 $2.2204\\times10^{-16}$.\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2513 @end tex\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2514 @end iftex\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2515 @end deftypefn")
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2516 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2517 return fill_matrix (args, DBL_EPSILON, "eps");
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2518 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2519
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2520 DEFUN (pi, args, ,
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2521 "-*- texinfo -*-\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2522 @deftypefn {Built-in Function} {} pi (@var{x})\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2523 @deftypefnx {Built-in Function} {} pi (@var{n}, @var{m})\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2524 @deftypefnx {Built-in Function} {} pi (@var{n}, @var{m}, @var{k}, @dots{})\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2525 @deftypefnx {Built-in Function} {} pi (@dots{}, @var{class})\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2526 Return a matrix or N-dimensional array whose elements are all equal\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2527 to the ratio of the circumference of a circle to its diameter.\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2528 Internally, @code{pi} is computed as @samp{4.0 * atan (1.0)}.\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2529 @end deftypefn")
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2530 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2531 #if defined (M_PI)
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2532 double pi_val = M_PI;
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2533 #else
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2534 double pi_val = 4.0 * atan (1.0);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2535 #endif
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2536
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2537 return fill_matrix (args, pi_val, "pi");
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2538 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2539
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2540 DEFUN (realmax, args, ,
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2541 "-*- texinfo -*-\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2542 @deftypefn {Built-in Function} {} realmax (@var{x})\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2543 @deftypefnx {Built-in Function} {} realmax (@var{n}, @var{m})\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2544 @deftypefnx {Built-in Function} {} realmax (@var{n}, @var{m}, @var{k}, @dots{})\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2545 @deftypefnx {Built-in Function} {} realmax (@dots{}, @var{class})\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2546 Return a matrix or N-dimensional array whose elements are all equal\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2547 to the largest floating point number that is representable. The actual\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2548 value is system-dependent. On machines that support 64-bit IEEE\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2549 floating point arithmetic, @code{realmax} is approximately\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2550 @ifinfo\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2551 1.7977e+308\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2552 @end ifinfo\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2553 @iftex\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2554 @tex\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2555 $1.7977\\times10^{308}$.\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2556 @end tex\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2557 @end iftex\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2558 @seealso{realmin}\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2559 @end deftypefn")
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2560 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2561 return fill_matrix (args, DBL_MAX, "realmax");
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2562 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2563
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2564 DEFUN (realmin, args, ,
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2565 "-*- texinfo -*-\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2566 @deftypefn {Built-in Function} {} realmin (@var{x})\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2567 @deftypefnx {Built-in Function} {} realmin (@var{n}, @var{m})\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2568 @deftypefnx {Built-in Function} {} realmin (@var{n}, @var{m}, @var{k}, @dots{})\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2569 @deftypefnx {Built-in Function} {} realmin (@dots{}, @var{class})\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2570 Return a matrix or N-dimensional array whose elements are all equal\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2571 to the smallest normalized floating point number that is representable.\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2572 The actual value is system-dependent. On machines that support\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2573 64-bit IEEE floating point arithmetic, @code{realmin} is approximately\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2574 @ifinfo\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2575 2.2251e-308\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2576 @end ifinfo\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2577 @iftex\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2578 @tex\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2579 $2.2251\\times10^{-308}$.\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2580 @end tex\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2581 @end iftex\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2582 @seealso{realmax}\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2583 @end deftypefn")
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2584 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2585 return fill_matrix (args, DBL_MIN, "realmin");
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2586 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2587
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2588 DEFUN (I, args, ,
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2589 "-*- texinfo -*-\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2590 @deftypefn {Built-in Function} {} I (@var{x})\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2591 @deftypefnx {Built-in Function} {} I (@var{n}, @var{m})\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2592 @deftypefnx {Built-in Function} {} I (@var{n}, @var{m}, @var{k}, @dots{})\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2593 @deftypefnx {Built-in Function} {} I (@dots{}, @var{class})\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2594 Return a matrix or N-dimensional array whose elements are all equal\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2595 to the pure imaginary unit, defined as\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2596 @iftex\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2597 @tex\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2598 $\\sqrt{-1}$.\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2599 @end tex\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2600 @end iftex\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2601 @ifinfo\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2602 @code{sqrt (-1)}.\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2603 @end ifinfo\n\
7001
8b0cfeb06365 [project @ 2007-10-10 18:02:59 by jwe]
jwe
parents: 6999
diff changeset
2604 Since I (also i, J, and j) is a function, you can use the name(s) for\n\
5747
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2605 other purposes.\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2606 @end deftypefn")
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2607 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2608 return fill_matrix (args, Complex (0.0, 1.0), "I");
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2609 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2610
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2611 DEFALIAS (i, I);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2612 DEFALIAS (J, I);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2613 DEFALIAS (j, I);
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2614
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2615 DEFUN (NA, args, ,
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2616 "-*- texinfo -*-\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2617 @deftypefn {Built-in Function} {} NA (@var{x})\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2618 @deftypefnx {Built-in Function} {} NA (@var{n}, @var{m})\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2619 @deftypefnx {Built-in Function} {} NA (@var{n}, @var{m}, @var{k}, @dots{})\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2620 @deftypefnx {Built-in Function} {} NA (@dots{}, @var{class})\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2621 Return a matrix or N-dimensional array whose elements are all equal\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2622 to the special constant used to designate missing values.\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2623 @end deftypefn")
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2624 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2625 return fill_matrix (args, lo_ieee_na_value (), "NA");
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2626 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2627
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2628 DEFUN (false, args, ,
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2629 "-*- texinfo -*-\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2630 @deftypefn {Built-in Function} {} false (@var{x})\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2631 @deftypefnx {Built-in Function} {} false (@var{n}, @var{m})\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2632 @deftypefnx {Built-in Function} {} false (@var{n}, @var{m}, @var{k}, @dots{})\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2633 Return a matrix or N-dimensional array whose elements are all logical 0.\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2634 The arguments are handled the same as the arguments for @code{eye}.\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2635 @end deftypefn")
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2636 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2637 return fill_matrix (args, false, "false");
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2638 }
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2639
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2640 DEFUN (true, args, ,
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2641 "-*- texinfo -*-\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2642 @deftypefn {Built-in Function} {} true (@var{x})\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2643 @deftypefnx {Built-in Function} {} true (@var{n}, @var{m})\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2644 @deftypefnx {Built-in Function} {} true (@var{n}, @var{m}, @var{k}, @dots{})\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2645 Return a matrix or N-dimensional array whose elements are all logical 1.\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2646 The arguments are handled the same as the arguments for @code{eye}.\n\
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2647 @end deftypefn")
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2648 {
b09d4d0f5b63 [project @ 2006-04-07 06:43:10 by jwe]
jwe
parents: 5734
diff changeset
2649 return fill_matrix (args, true, "true");
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3333
diff changeset
2650 }
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
2651
4946
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2652 template <class MT>
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2653 octave_value
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2654 identity_matrix (int nr, int nc)
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2655 {
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2656 octave_value retval;
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2657
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2658 typename octave_array_type_traits<MT>::element_type one (1);
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2659
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2660 if (nr == 1 && nc == 1)
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2661 retval = one;
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2662 else
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2663 {
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2664 dim_vector dims (nr, nc);
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2665
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2666 typename octave_array_type_traits<MT>::element_type zero (0);
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2667
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2668 MT m (dims, zero);
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2669
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2670 if (nr > 0 && nc > 0)
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2671 {
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2672 int n = std::min (nr, nc);
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2673
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2674 for (int i = 0; i < n; i++)
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2675 m(i,i) = one;
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2676 }
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2677
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2678 retval = m;
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2679 }
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2680
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2681 return retval;
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2682 }
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2683
5058
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
2684 #define INSTANTIATE_EYE(T) \
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
2685 template octave_value identity_matrix<T> (int, int)
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
2686
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
2687 INSTANTIATE_EYE (int8NDArray);
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
2688 INSTANTIATE_EYE (uint8NDArray);
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
2689 INSTANTIATE_EYE (int16NDArray);
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
2690 INSTANTIATE_EYE (uint16NDArray);
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
2691 INSTANTIATE_EYE (int32NDArray);
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
2692 INSTANTIATE_EYE (uint32NDArray);
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
2693 INSTANTIATE_EYE (int64NDArray);
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
2694 INSTANTIATE_EYE (uint64NDArray);
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
2695 INSTANTIATE_EYE (NDArray);
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
2696 INSTANTIATE_EYE (boolNDArray);
11bea7392e69 [project @ 2004-11-01 21:06:44 by jwe]
jwe
parents: 5013
diff changeset
2697
4945
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
2698 static octave_value
4948
7124436476cb [project @ 2004-08-31 17:57:21 by jwe]
jwe
parents: 4947
diff changeset
2699 identity_matrix (int nr, int nc, oct_data_conv::data_type dt)
4945
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
2700 {
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
2701 octave_value retval;
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
2702
5775
ace8d8d26933 [project @ 2006-04-24 19:13:06 by jwe]
jwe
parents: 5747
diff changeset
2703 // FIXME -- perhaps this should be made extensible by using
4946
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2704 // the class name to lookup a function to call to create the new
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2705 // value.
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2706
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2707 if (! error_state)
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2708 {
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2709 switch (dt)
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2710 {
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2711 case oct_data_conv::dt_int8:
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2712 retval = identity_matrix<int8NDArray> (nr, nc);
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2713 break;
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2714
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2715 case oct_data_conv::dt_uint8:
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2716 retval = identity_matrix<uint8NDArray> (nr, nc);
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2717 break;
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2718
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2719 case oct_data_conv::dt_int16:
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2720 retval = identity_matrix<int16NDArray> (nr, nc);
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2721 break;
4945
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
2722
4946
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2723 case oct_data_conv::dt_uint16:
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2724 retval = identity_matrix<uint16NDArray> (nr, nc);
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2725 break;
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2726
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2727 case oct_data_conv::dt_int32:
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2728 retval = identity_matrix<int32NDArray> (nr, nc);
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2729 break;
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2730
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2731 case oct_data_conv::dt_uint32:
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2732 retval = identity_matrix<uint32NDArray> (nr, nc);
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2733 break;
4945
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
2734
4946
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2735 case oct_data_conv::dt_int64:
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2736 retval = identity_matrix<int64NDArray> (nr, nc);
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2737 break;
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2738
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2739 case oct_data_conv::dt_uint64:
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2740 retval = identity_matrix<uint64NDArray> (nr, nc);
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2741 break;
4945
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
2742
5775
ace8d8d26933 [project @ 2006-04-24 19:13:06 by jwe]
jwe
parents: 5747
diff changeset
2743 case oct_data_conv::dt_single: // FIXME
4946
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2744 case oct_data_conv::dt_double:
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2745 retval = identity_matrix<NDArray> (nr, nc);
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2746 break;
4945
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
2747
4986
fac558699d0f [project @ 2004-09-10 15:57:13 by jwe]
jwe
parents: 4948
diff changeset
2748 case oct_data_conv::dt_logical:
fac558699d0f [project @ 2004-09-10 15:57:13 by jwe]
jwe
parents: 4948
diff changeset
2749 retval = identity_matrix<boolNDArray> (nr, nc);
fac558699d0f [project @ 2004-09-10 15:57:13 by jwe]
jwe
parents: 4948
diff changeset
2750 break;
fac558699d0f [project @ 2004-09-10 15:57:13 by jwe]
jwe
parents: 4948
diff changeset
2751
4946
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2752 default:
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2753 error ("eye: invalid class name");
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2754 break;
4945
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
2755 }
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
2756 }
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
2757
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
2758 return retval;
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
2759 }
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
2760
4946
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2761 #undef INT_EYE_MATRIX
48a39e2b2ab7 [project @ 2004-08-31 17:27:04 by jwe]
jwe
parents: 4945
diff changeset
2762
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1940
diff changeset
2763 DEFUN (eye, args, ,
3369
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
2764 "-*- texinfo -*-\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
2765 @deftypefn {Built-in Function} {} eye (@var{x})\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
2766 @deftypefnx {Built-in Function} {} eye (@var{n}, @var{m})\n\
4948
7124436476cb [project @ 2004-08-31 17:57:21 by jwe]
jwe
parents: 4947
diff changeset
2767 @deftypefnx {Built-in Function} {} eye (@dots{}, @var{class})\n\
3369
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
2768 Return an identity matrix. If invoked with a single scalar argument,\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
2769 @code{eye} returns a square matrix with the dimension specified. If you\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
2770 supply two scalar arguments, @code{eye} takes them to be the number of\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
2771 rows and columns. If given a vector with two elements, @code{eye} uses\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
2772 the values of the elements as the number of rows and columns,\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
2773 respectively. For example,\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
2774 \n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
2775 @example\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
2776 @group\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
2777 eye (3)\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
2778 @result{} 1 0 0\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
2779 0 1 0\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
2780 0 0 1\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
2781 @end group\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
2782 @end example\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
2783 \n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
2784 The following expressions all produce the same result:\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
2785 \n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
2786 @example\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
2787 @group\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
2788 eye (2)\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
2789 @equiv{}\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
2790 eye (2, 2)\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
2791 @equiv{}\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
2792 eye (size ([1, 2; 3, 4])\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
2793 @end group\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
2794 @end example\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
2795 \n\
4945
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
2796 The optional argument @var{class}, allows @code{eye} to return an array of\n\
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
2797 the specified type, like\n\
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
2798 \n\
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
2799 @example\n\
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
2800 val = zeros (n,m, \"uint8\")\n\
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
2801 @end example\n\
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
2802 \n\
6556
8810bbf321ce [project @ 2007-04-20 18:39:40 by jwe]
jwe
parents: 6518
diff changeset
2803 Calling @code{eye} with no arguments is equivalent to calling it\n\
8810bbf321ce [project @ 2007-04-20 18:39:40 by jwe]
jwe
parents: 6518
diff changeset
2804 with an argument of 1. This odd definition is for compatibility\n\
8810bbf321ce [project @ 2007-04-20 18:39:40 by jwe]
jwe
parents: 6518
diff changeset
2805 with @sc{Matlab}.\n\
3369
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
2806 @end deftypefn")
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
2807 {
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3333
diff changeset
2808 octave_value retval;
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
2809
4948
7124436476cb [project @ 2004-08-31 17:57:21 by jwe]
jwe
parents: 4947
diff changeset
2810 int nargin = args.length ();
4945
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
2811
4948
7124436476cb [project @ 2004-08-31 17:57:21 by jwe]
jwe
parents: 4947
diff changeset
2812 oct_data_conv::data_type dt = oct_data_conv::dt_double;
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
2813
4945
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
2814 // Check for type information.
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
2815
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
2816 if (nargin > 0 && args(nargin-1).is_string ())
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
2817 {
4948
7124436476cb [project @ 2004-08-31 17:57:21 by jwe]
jwe
parents: 4947
diff changeset
2818 std::string nm = args(nargin-1).string_value ();
4945
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
2819 nargin--;
4948
7124436476cb [project @ 2004-08-31 17:57:21 by jwe]
jwe
parents: 4947
diff changeset
2820
7124436476cb [project @ 2004-08-31 17:57:21 by jwe]
jwe
parents: 4947
diff changeset
2821 dt = oct_data_conv::string_to_data_type (nm);
7124436476cb [project @ 2004-08-31 17:57:21 by jwe]
jwe
parents: 4947
diff changeset
2822
7124436476cb [project @ 2004-08-31 17:57:21 by jwe]
jwe
parents: 4947
diff changeset
2823 if (error_state)
7124436476cb [project @ 2004-08-31 17:57:21 by jwe]
jwe
parents: 4947
diff changeset
2824 return retval;
4945
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
2825 }
4bd917f8a4a7 [project @ 2004-08-31 15:09:17 by jwe]
jwe
parents: 4915
diff changeset
2826
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
2827 switch (nargin)
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
2828 {
712
36ba0576bd1b [project @ 1994-09-19 14:18:15 by jwe]
jwe
parents: 649
diff changeset
2829 case 0:
4948
7124436476cb [project @ 2004-08-31 17:57:21 by jwe]
jwe
parents: 4947
diff changeset
2830 retval = identity_matrix (1, 1, dt);
712
36ba0576bd1b [project @ 1994-09-19 14:18:15 by jwe]
jwe
parents: 649
diff changeset
2831 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 767
diff changeset
2832
610
14b2a186a5c0 [project @ 1994-08-14 00:55:49 by jwe]
jwe
parents: 597
diff changeset
2833 case 1:
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3333
diff changeset
2834 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
2835 octave_idx_type nr, nc;
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3333
diff changeset
2836 get_dimensions (args(0), "eye", nr, nc);
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3333
diff changeset
2837
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3333
diff changeset
2838 if (! error_state)
4948
7124436476cb [project @ 2004-08-31 17:57:21 by jwe]
jwe
parents: 4947
diff changeset
2839 retval = identity_matrix (nr, nc, dt);
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3333
diff changeset
2840 }
610
14b2a186a5c0 [project @ 1994-08-14 00:55:49 by jwe]
jwe
parents: 597
diff changeset
2841 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 767
diff changeset
2842
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
2843 case 2:
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3333
diff changeset
2844 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
2845 octave_idx_type nr, nc;
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3333
diff changeset
2846 get_dimensions (args(0), args(1), "eye", nr, nc);
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3333
diff changeset
2847
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3333
diff changeset
2848 if (! error_state)
4948
7124436476cb [project @ 2004-08-31 17:57:21 by jwe]
jwe
parents: 4947
diff changeset
2849 retval = identity_matrix (nr, nc, dt);
3354
87721841efd7 [project @ 1999-11-17 19:06:11 by jwe]
jwe
parents: 3333
diff changeset
2850 }
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
2851 break;
777
a2f9d3fd720c [project @ 1994-10-07 14:01:53 by jwe]
jwe
parents: 767
diff changeset
2852
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
2853 default:
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
2854 print_usage ();
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
2855 break;
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
2856 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
2857
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
2858 return retval;
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
2859 }
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
2860
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1940
diff changeset
2861 DEFUN (linspace, args, ,
3369
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
2862 "-*- texinfo -*-\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
2863 @deftypefn {Built-in Function} {} linspace (@var{base}, @var{limit}, @var{n})\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
2864 Return a row vector with @var{n} linearly spaced elements between\n\
6630
0fcc8d65b571 [project @ 2007-05-16 15:32:09 by jwe]
jwe
parents: 6561
diff changeset
2865 @var{base} and @var{limit}. If the number of elements is greater than one,\n\
0fcc8d65b571 [project @ 2007-05-16 15:32:09 by jwe]
jwe
parents: 6561
diff changeset
2866 then the @var{base} and @var{limit} are always included in\n\
3369
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
2867 the range. If @var{base} is greater than @var{limit}, the elements are\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
2868 stored in decreasing order. If the number of points is not specified, a\n\
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
2869 value of 100 is used.\n\
1100
3b6f6c5217e7 [project @ 1995-02-14 01:45:09 by jwe]
jwe
parents: 1032
diff changeset
2870 \n\
4455
abbf63293766 [project @ 2003-07-11 01:01:16 by jwe]
jwe
parents: 4358
diff changeset
2871 The @code{linspace} function always returns a row vector.\n\
6630
0fcc8d65b571 [project @ 2007-05-16 15:32:09 by jwe]
jwe
parents: 6561
diff changeset
2872 \n\
0fcc8d65b571 [project @ 2007-05-16 15:32:09 by jwe]
jwe
parents: 6561
diff changeset
2873 For compatibility with @sc{Matlab}, return the second argument if\n\
0fcc8d65b571 [project @ 2007-05-16 15:32:09 by jwe]
jwe
parents: 6561
diff changeset
2874 fewer than two values are requested.\n\
3369
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 3361
diff changeset
2875 @end deftypefn")
1100
3b6f6c5217e7 [project @ 1995-02-14 01:45:09 by jwe]
jwe
parents: 1032
diff changeset
2876 {
3418
ca92c9d3f882 [project @ 2000-01-12 03:07:47 by jwe]
jwe
parents: 3373
diff changeset
2877 octave_value retval;
1100
3b6f6c5217e7 [project @ 1995-02-14 01:45:09 by jwe]
jwe
parents: 1032
diff changeset
2878
3b6f6c5217e7 [project @ 1995-02-14 01:45:09 by jwe]
jwe
parents: 1032
diff changeset
2879 int nargin = args.length ();
3b6f6c5217e7 [project @ 1995-02-14 01:45:09 by jwe]
jwe
parents: 1032
diff changeset
2880
6133
e0065af38cf4 [project @ 2006-11-02 03:33:50 by jwe]
jwe
parents: 5991
diff changeset
2881 octave_idx_type npoints = 100;
1100
3b6f6c5217e7 [project @ 1995-02-14 01:45:09 by jwe]
jwe
parents: 1032
diff changeset
2882
1940
1b193e313c56 [project @ 1996-02-13 16:28:47 by jwe]
jwe
parents: 1884
diff changeset
2883 if (nargin != 2 && nargin != 3)
1b193e313c56 [project @ 1996-02-13 16:28:47 by jwe]
jwe
parents: 1884
diff changeset
2884 {
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
2885 print_usage ();
1940
1b193e313c56 [project @ 1996-02-13 16:28:47 by jwe]
jwe
parents: 1884
diff changeset
2886 return retval;
1b193e313c56 [project @ 1996-02-13 16:28:47 by jwe]
jwe
parents: 1884
diff changeset
2887 }
1b193e313c56 [project @ 1996-02-13 16:28:47 by jwe]
jwe
parents: 1884
diff changeset
2888
1100
3b6f6c5217e7 [project @ 1995-02-14 01:45:09 by jwe]
jwe
parents: 1032
diff changeset
2889 if (nargin == 3)
6133
e0065af38cf4 [project @ 2006-11-02 03:33:50 by jwe]
jwe
parents: 5991
diff changeset
2890 npoints = args(2).idx_type_value ();
1100
3b6f6c5217e7 [project @ 1995-02-14 01:45:09 by jwe]
jwe
parents: 1032
diff changeset
2891
3b6f6c5217e7 [project @ 1995-02-14 01:45:09 by jwe]
jwe
parents: 1032
diff changeset
2892 if (! error_state)
3b6f6c5217e7 [project @ 1995-02-14 01:45:09 by jwe]
jwe
parents: 1032
diff changeset
2893 {
3322
8c6b4de3bdc8 [project @ 1999-10-26 21:33:27 by jwe]
jwe
parents: 3321
diff changeset
2894 octave_value arg_1 = args(0);
8c6b4de3bdc8 [project @ 1999-10-26 21:33:27 by jwe]
jwe
parents: 3321
diff changeset
2895 octave_value arg_2 = args(1);
1100
3b6f6c5217e7 [project @ 1995-02-14 01:45:09 by jwe]
jwe
parents: 1032
diff changeset
2896
3322
8c6b4de3bdc8 [project @ 1999-10-26 21:33:27 by jwe]
jwe
parents: 3321
diff changeset
2897 if (arg_1.is_complex_type () || arg_2.is_complex_type ())
8c6b4de3bdc8 [project @ 1999-10-26 21:33:27 by jwe]
jwe
parents: 3321
diff changeset
2898 {
8c6b4de3bdc8 [project @ 1999-10-26 21:33:27 by jwe]
jwe
parents: 3321
diff changeset
2899 Complex x1 = arg_1.complex_value ();
8c6b4de3bdc8 [project @ 1999-10-26 21:33:27 by jwe]
jwe
parents: 3321
diff changeset
2900 Complex x2 = arg_2.complex_value ();
8c6b4de3bdc8 [project @ 1999-10-26 21:33:27 by jwe]
jwe
parents: 3321
diff changeset
2901
8c6b4de3bdc8 [project @ 1999-10-26 21:33:27 by jwe]
jwe
parents: 3321
diff changeset
2902 if (! error_state)
1100
3b6f6c5217e7 [project @ 1995-02-14 01:45:09 by jwe]
jwe
parents: 1032
diff changeset
2903 {
3322
8c6b4de3bdc8 [project @ 1999-10-26 21:33:27 by jwe]
jwe
parents: 3321
diff changeset
2904 ComplexRowVector rv = linspace (x1, x2, npoints);
1100
3b6f6c5217e7 [project @ 1995-02-14 01:45:09 by jwe]
jwe
parents: 1032
diff changeset
2905
3b6f6c5217e7 [project @ 1995-02-14 01:45:09 by jwe]
jwe
parents: 1032
diff changeset
2906 if (! error_state)
3418
ca92c9d3f882 [project @ 2000-01-12 03:07:47 by jwe]
jwe
parents: 3373
diff changeset
2907 retval = rv;
1100
3b6f6c5217e7 [project @ 1995-02-14 01:45:09 by jwe]
jwe
parents: 1032
diff changeset
2908 }
3b6f6c5217e7 [project @ 1995-02-14 01:45:09 by jwe]
jwe
parents: 1032
diff changeset
2909 }
3b6f6c5217e7 [project @ 1995-02-14 01:45:09 by jwe]
jwe
parents: 1032
diff changeset
2910 else
3322
8c6b4de3bdc8 [project @ 1999-10-26 21:33:27 by jwe]
jwe
parents: 3321
diff changeset
2911 {
8c6b4de3bdc8 [project @ 1999-10-26 21:33:27 by jwe]
jwe
parents: 3321
diff changeset
2912 double x1 = arg_1.double_value ();
8c6b4de3bdc8 [project @ 1999-10-26 21:33:27 by jwe]
jwe
parents: 3321
diff changeset
2913 double x2 = arg_2.double_value ();
8c6b4de3bdc8 [project @ 1999-10-26 21:33:27 by jwe]
jwe
parents: 3321
diff changeset
2914
8c6b4de3bdc8 [project @ 1999-10-26 21:33:27 by jwe]
jwe
parents: 3321
diff changeset
2915 if (! error_state)
8c6b4de3bdc8 [project @ 1999-10-26 21:33:27 by jwe]
jwe
parents: 3321
diff changeset
2916 {
8c6b4de3bdc8 [project @ 1999-10-26 21:33:27 by jwe]
jwe
parents: 3321
diff changeset
2917 RowVector rv = linspace (x1, x2, npoints);
8c6b4de3bdc8 [project @ 1999-10-26 21:33:27 by jwe]
jwe
parents: 3321
diff changeset
2918
8c6b4de3bdc8 [project @ 1999-10-26 21:33:27 by jwe]
jwe
parents: 3321
diff changeset
2919 if (! error_state)
3418
ca92c9d3f882 [project @ 2000-01-12 03:07:47 by jwe]
jwe
parents: 3373
diff changeset
2920 retval = rv;
3322
8c6b4de3bdc8 [project @ 1999-10-26 21:33:27 by jwe]
jwe
parents: 3321
diff changeset
2921 }
8c6b4de3bdc8 [project @ 1999-10-26 21:33:27 by jwe]
jwe
parents: 3321
diff changeset
2922 }
1100
3b6f6c5217e7 [project @ 1995-02-14 01:45:09 by jwe]
jwe
parents: 1032
diff changeset
2923 }
4732
b484cdca27be [project @ 2004-02-04 04:32:48 by jwe]
jwe
parents: 4685
diff changeset
2924 else
b484cdca27be [project @ 2004-02-04 04:32:48 by jwe]
jwe
parents: 4685
diff changeset
2925 error ("linspace: expecting third argument to be an integer");
1100
3b6f6c5217e7 [project @ 1995-02-14 01:45:09 by jwe]
jwe
parents: 1032
diff changeset
2926
3b6f6c5217e7 [project @ 1995-02-14 01:45:09 by jwe]
jwe
parents: 1032
diff changeset
2927 return retval;
3b6f6c5217e7 [project @ 1995-02-14 01:45:09 by jwe]
jwe
parents: 1032
diff changeset
2928 }
3b6f6c5217e7 [project @ 1995-02-14 01:45:09 by jwe]
jwe
parents: 1032
diff changeset
2929
5775
ace8d8d26933 [project @ 2006-04-24 19:13:06 by jwe]
jwe
parents: 5747
diff changeset
2930 // FIXME -- should accept dimensions as separate args for N-d
5734
a7d2c47371d2 [project @ 2006-04-04 18:29:13 by jwe]
jwe
parents: 5731
diff changeset
2931 // arrays as well as 1-d and 2-d arrays.
a7d2c47371d2 [project @ 2006-04-04 18:29:13 by jwe]
jwe
parents: 5731
diff changeset
2932
5731
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
2933 DEFUN (resize, args, ,
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
2934 "-*- texinfo -*-\n\
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
2935 @deftypefn {Built-in Function} {} resize (@var{x}, @var{m})\n\
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
2936 @deftypefnx {Built-in Function} {} resize (@var{x}, @var{m}, @var{n})\n\
6174
d3c599afc455 [project @ 2006-11-16 17:52:02 by jwe]
jwe
parents: 6156
diff changeset
2937 Destructively resize @var{x}.\n\
d3c599afc455 [project @ 2006-11-16 17:52:02 by jwe]
jwe
parents: 6156
diff changeset
2938 \n\
d3c599afc455 [project @ 2006-11-16 17:52:02 by jwe]
jwe
parents: 6156
diff changeset
2939 @strong{Values in @var{x} are not preserved as they are with\n\
6175
a4ecbadedc17 [project @ 2006-11-16 18:19:20 by jwe]
jwe
parents: 6174
diff changeset
2940 @code{reshape}.}\n\
6174
d3c599afc455 [project @ 2006-11-16 17:52:02 by jwe]
jwe
parents: 6156
diff changeset
2941 \n\
d3c599afc455 [project @ 2006-11-16 17:52:02 by jwe]
jwe
parents: 6156
diff changeset
2942 If only @var{m} is supplied and it is a scalar, the dimension of the\n\
d3c599afc455 [project @ 2006-11-16 17:52:02 by jwe]
jwe
parents: 6156
diff changeset
2943 result is @var{m}-by-@var{m}. If @var{m} is a vector, then the\n\
d3c599afc455 [project @ 2006-11-16 17:52:02 by jwe]
jwe
parents: 6156
diff changeset
2944 dimensions of the result are given by the elements of @var{m}.\n\
d3c599afc455 [project @ 2006-11-16 17:52:02 by jwe]
jwe
parents: 6156
diff changeset
2945 If both @var{m} and @var{n} are scalars, then the dimensions of\n\
d3c599afc455 [project @ 2006-11-16 17:52:02 by jwe]
jwe
parents: 6156
diff changeset
2946 the result are @var{m}-by-@var{n}.\n\
d3c599afc455 [project @ 2006-11-16 17:52:02 by jwe]
jwe
parents: 6156
diff changeset
2947 @seealso{reshape}\n\
5731
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
2948 @end deftypefn")
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
2949 {
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
2950 octave_value retval;
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
2951 int nargin = args.length ();
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
2952
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
2953 if (nargin == 2)
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
2954 {
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
2955 Array<double> vec = args(1).vector_value ();
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
2956 int ndim = vec.length ();
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
2957 if (ndim == 1)
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
2958 {
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
2959 octave_idx_type m = static_cast<octave_idx_type> (vec(0));
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
2960 retval = args(0);
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
2961 retval = retval.resize (dim_vector (m, m), true);
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
2962 }
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
2963 else
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
2964 {
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
2965 dim_vector dv;
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
2966 dv.resize (ndim);
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
2967 for (int i = 0; i < ndim; i++)
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
2968 dv(i) = static_cast<octave_idx_type> (vec(i));
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
2969 retval = args(0);
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
2970 retval = retval.resize (dv, true);
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
2971 }
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
2972 }
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
2973 else if (nargin == 3)
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
2974 {
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
2975 octave_idx_type m = static_cast<octave_idx_type>
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
2976 (args(1).scalar_value());
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
2977 octave_idx_type n = static_cast<octave_idx_type>
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
2978 (args(2).scalar_value());
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
2979 if (!error_state)
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
2980 {
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
2981 retval = args(0);
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
2982 retval = retval.resize (dim_vector (m, n), true);
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
2983 }
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
2984 }
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
2985 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
2986 print_usage ();
5731
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
2987 return retval;
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
2988 }
c7d5a534afa5 [project @ 2006-04-03 19:33:26 by jwe]
jwe
parents: 5724
diff changeset
2989
5775
ace8d8d26933 [project @ 2006-04-24 19:13:06 by jwe]
jwe
parents: 5747
diff changeset
2990 // FIXME -- should use octave_idx_type for dimensions.
5734
a7d2c47371d2 [project @ 2006-04-04 18:29:13 by jwe]
jwe
parents: 5731
diff changeset
2991
4567
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
2992 DEFUN (reshape, args, ,
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
2993 "-*- texinfo -*-\n\
6671
9042b00fc45e [project @ 2007-05-30 06:33:29 by jwe]
jwe
parents: 6630
diff changeset
2994 @deftypefn {Built-in Function} {} reshape (@var{a}, @var{m}, @var{n}, @dots{})\n\
9042b00fc45e [project @ 2007-05-30 06:33:29 by jwe]
jwe
parents: 6630
diff changeset
2995 @deftypefnx {Built-in Function} {} reshape (@var{a}, @var{siz})\n\
4567
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
2996 Return a matrix with the given dimensions whose elements are taken\n\
6671
9042b00fc45e [project @ 2007-05-30 06:33:29 by jwe]
jwe
parents: 6630
diff changeset
2997 from the matrix @var{a}. The elements of the matrix are accessed in\n\
4567
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
2998 column-major order (like Fortran arrays are stored).\n\
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
2999 \n\
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
3000 For example,\n\
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
3001 \n\
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
3002 @example\n\
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
3003 @group\n\
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
3004 reshape ([1, 2, 3, 4], 2, 2)\n\
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
3005 @result{} 1 3\n\
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
3006 2 4\n\
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
3007 @end group\n\
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
3008 @end example\n\
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
3009 \n\
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
3010 @noindent\n\
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
3011 Note that the total number of elements in the original\n\
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
3012 matrix must match the total number of elements in the new matrix.\n\
5013
1eb9ce5c0152 [project @ 2004-09-21 22:18:07 by jwe]
jwe
parents: 4986
diff changeset
3013 \n\
1eb9ce5c0152 [project @ 2004-09-21 22:18:07 by jwe]
jwe
parents: 4986
diff changeset
3014 A single dimension of the return matrix can be unknown and is flagged\n\
1eb9ce5c0152 [project @ 2004-09-21 22:18:07 by jwe]
jwe
parents: 4986
diff changeset
3015 by an empty argument.\n\
4567
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
3016 @end deftypefn")
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
3017 {
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
3018 octave_value retval;
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
3019
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
3020 int nargin = args.length ();
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
3021
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
3022 Array<int> new_size;
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
3023
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
3024 if (nargin == 2)
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
3025 new_size = args(1).int_vector_value ();
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
3026 else if (nargin > 2)
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
3027 {
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
3028 new_size.resize (nargin-1);
5013
1eb9ce5c0152 [project @ 2004-09-21 22:18:07 by jwe]
jwe
parents: 4986
diff changeset
3029 int empty_dim = -1;
1eb9ce5c0152 [project @ 2004-09-21 22:18:07 by jwe]
jwe
parents: 4986
diff changeset
3030
4567
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
3031 for (int i = 1; i < nargin; i++)
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
3032 {
5013
1eb9ce5c0152 [project @ 2004-09-21 22:18:07 by jwe]
jwe
parents: 4986
diff changeset
3033 if (args(i).is_empty ())
1eb9ce5c0152 [project @ 2004-09-21 22:18:07 by jwe]
jwe
parents: 4986
diff changeset
3034 if (empty_dim > 0)
1eb9ce5c0152 [project @ 2004-09-21 22:18:07 by jwe]
jwe
parents: 4986
diff changeset
3035 {
1eb9ce5c0152 [project @ 2004-09-21 22:18:07 by jwe]
jwe
parents: 4986
diff changeset
3036 error ("reshape: only a single dimension can be unknown");
1eb9ce5c0152 [project @ 2004-09-21 22:18:07 by jwe]
jwe
parents: 4986
diff changeset
3037 break;
1eb9ce5c0152 [project @ 2004-09-21 22:18:07 by jwe]
jwe
parents: 4986
diff changeset
3038 }
1eb9ce5c0152 [project @ 2004-09-21 22:18:07 by jwe]
jwe
parents: 4986
diff changeset
3039 else
1eb9ce5c0152 [project @ 2004-09-21 22:18:07 by jwe]
jwe
parents: 4986
diff changeset
3040 {
1eb9ce5c0152 [project @ 2004-09-21 22:18:07 by jwe]
jwe
parents: 4986
diff changeset
3041 empty_dim = i;
1eb9ce5c0152 [project @ 2004-09-21 22:18:07 by jwe]
jwe
parents: 4986
diff changeset
3042 new_size(i-1) = 1;
1eb9ce5c0152 [project @ 2004-09-21 22:18:07 by jwe]
jwe
parents: 4986
diff changeset
3043 }
1eb9ce5c0152 [project @ 2004-09-21 22:18:07 by jwe]
jwe
parents: 4986
diff changeset
3044 else
1eb9ce5c0152 [project @ 2004-09-21 22:18:07 by jwe]
jwe
parents: 4986
diff changeset
3045 {
6133
e0065af38cf4 [project @ 2006-11-02 03:33:50 by jwe]
jwe
parents: 5991
diff changeset
3046 new_size(i-1) = args(i).idx_type_value ();
4567
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
3047
5013
1eb9ce5c0152 [project @ 2004-09-21 22:18:07 by jwe]
jwe
parents: 4986
diff changeset
3048 if (error_state)
1eb9ce5c0152 [project @ 2004-09-21 22:18:07 by jwe]
jwe
parents: 4986
diff changeset
3049 break;
1eb9ce5c0152 [project @ 2004-09-21 22:18:07 by jwe]
jwe
parents: 4986
diff changeset
3050 }
1eb9ce5c0152 [project @ 2004-09-21 22:18:07 by jwe]
jwe
parents: 4986
diff changeset
3051 }
1eb9ce5c0152 [project @ 2004-09-21 22:18:07 by jwe]
jwe
parents: 4986
diff changeset
3052
1eb9ce5c0152 [project @ 2004-09-21 22:18:07 by jwe]
jwe
parents: 4986
diff changeset
3053 if (! error_state && (empty_dim > 0))
1eb9ce5c0152 [project @ 2004-09-21 22:18:07 by jwe]
jwe
parents: 4986
diff changeset
3054 {
1eb9ce5c0152 [project @ 2004-09-21 22:18:07 by jwe]
jwe
parents: 4986
diff changeset
3055 int nel = 1;
1eb9ce5c0152 [project @ 2004-09-21 22:18:07 by jwe]
jwe
parents: 4986
diff changeset
3056 for (int i = 0; i < nargin - 1; i++)
1eb9ce5c0152 [project @ 2004-09-21 22:18:07 by jwe]
jwe
parents: 4986
diff changeset
3057 nel *= new_size(i);
1eb9ce5c0152 [project @ 2004-09-21 22:18:07 by jwe]
jwe
parents: 4986
diff changeset
3058
1eb9ce5c0152 [project @ 2004-09-21 22:18:07 by jwe]
jwe
parents: 4986
diff changeset
3059 if (nel == 0)
1eb9ce5c0152 [project @ 2004-09-21 22:18:07 by jwe]
jwe
parents: 4986
diff changeset
3060 new_size(empty_dim-1) = 0;
1eb9ce5c0152 [project @ 2004-09-21 22:18:07 by jwe]
jwe
parents: 4986
diff changeset
3061 else
1eb9ce5c0152 [project @ 2004-09-21 22:18:07 by jwe]
jwe
parents: 4986
diff changeset
3062 {
1eb9ce5c0152 [project @ 2004-09-21 22:18:07 by jwe]
jwe
parents: 4986
diff changeset
3063 int size_empty_dim = args(0).numel () / nel;
1eb9ce5c0152 [project @ 2004-09-21 22:18:07 by jwe]
jwe
parents: 4986
diff changeset
3064
1eb9ce5c0152 [project @ 2004-09-21 22:18:07 by jwe]
jwe
parents: 4986
diff changeset
3065 if (args(0).numel () != size_empty_dim * nel)
1eb9ce5c0152 [project @ 2004-09-21 22:18:07 by jwe]
jwe
parents: 4986
diff changeset
3066 error ("reshape: size is not divisble by the product of known dimensions (= %d)", nel);
1eb9ce5c0152 [project @ 2004-09-21 22:18:07 by jwe]
jwe
parents: 4986
diff changeset
3067 else
1eb9ce5c0152 [project @ 2004-09-21 22:18:07 by jwe]
jwe
parents: 4986
diff changeset
3068 new_size(empty_dim-1) = size_empty_dim;
1eb9ce5c0152 [project @ 2004-09-21 22:18:07 by jwe]
jwe
parents: 4986
diff changeset
3069 }
4567
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
3070 }
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
3071 }
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
3072 else
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
3073 {
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
3074 print_usage ();
4567
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
3075 return retval;
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
3076 }
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
3077
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
3078 if (error_state)
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
3079 {
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
3080 error ("reshape: invalid arguments");
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
3081 return retval;
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
3082 }
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
3083
4739
7bd3748e2735 [project @ 2004-02-05 18:53:18 by jwe]
jwe
parents: 4732
diff changeset
3084 // Remove trailing singletons in new_size, but leave at least 2
7bd3748e2735 [project @ 2004-02-05 18:53:18 by jwe]
jwe
parents: 4732
diff changeset
3085 // elements.
7bd3748e2735 [project @ 2004-02-05 18:53:18 by jwe]
jwe
parents: 4732
diff changeset
3086
4567
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
3087 int n = new_size.length ();
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
3088
4739
7bd3748e2735 [project @ 2004-02-05 18:53:18 by jwe]
jwe
parents: 4732
diff changeset
3089 while (n > 2)
7bd3748e2735 [project @ 2004-02-05 18:53:18 by jwe]
jwe
parents: 4732
diff changeset
3090 {
7bd3748e2735 [project @ 2004-02-05 18:53:18 by jwe]
jwe
parents: 4732
diff changeset
3091 if (new_size(n-1) == 1)
7bd3748e2735 [project @ 2004-02-05 18:53:18 by jwe]
jwe
parents: 4732
diff changeset
3092 n--;
7bd3748e2735 [project @ 2004-02-05 18:53:18 by jwe]
jwe
parents: 4732
diff changeset
3093 else
7bd3748e2735 [project @ 2004-02-05 18:53:18 by jwe]
jwe
parents: 4732
diff changeset
3094 break;
7bd3748e2735 [project @ 2004-02-05 18:53:18 by jwe]
jwe
parents: 4732
diff changeset
3095 }
7bd3748e2735 [project @ 2004-02-05 18:53:18 by jwe]
jwe
parents: 4732
diff changeset
3096
7bd3748e2735 [project @ 2004-02-05 18:53:18 by jwe]
jwe
parents: 4732
diff changeset
3097 new_size.resize (n);
7bd3748e2735 [project @ 2004-02-05 18:53:18 by jwe]
jwe
parents: 4732
diff changeset
3098
4567
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
3099 if (n < 2)
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
3100 {
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
3101 error ("reshape: expecting size to be vector with at least 2 elements");
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
3102 return retval;
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
3103 }
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
3104
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
3105 dim_vector new_dims;
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
3106
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
3107 new_dims.resize (n);
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
3108
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5164
diff changeset
3109 for (octave_idx_type i = 0; i < n; i++)
4567
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
3110 new_dims(i) = new_size(i);
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
3111
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
3112 octave_value arg = args(0);
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
3113
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
3114 if (new_dims.numel () == arg.numel ())
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
3115 retval = (new_dims == arg.dims ()) ? arg : arg.reshape (new_dims);
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
3116 else
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
3117 error ("reshape: size mismatch");
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
3118
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
3119 return retval;
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
3120 }
fc30061d01da [project @ 2003-10-29 20:11:15 by jwe]
jwe
parents: 4565
diff changeset
3121
4532
01ee68d18069 [project @ 2003-10-10 00:49:54 by jwe]
jwe
parents: 4516
diff changeset
3122 DEFUN (squeeze, args, ,
01ee68d18069 [project @ 2003-10-10 00:49:54 by jwe]
jwe
parents: 4516
diff changeset
3123 "-*- texinfo -*-\n\
01ee68d18069 [project @ 2003-10-10 00:49:54 by jwe]
jwe
parents: 4516
diff changeset
3124 @deftypefn {Built-in Function} {} squeeze (@var{x})\n\
01ee68d18069 [project @ 2003-10-10 00:49:54 by jwe]
jwe
parents: 4516
diff changeset
3125 Remove singleton dimensions from @var{x} and return the result.\n\
6999
9325d3f604a3 [project @ 2007-10-10 17:03:34 by jwe]
jwe
parents: 6979
diff changeset
3126 Note that for compatibility with @sc{Matlab}, all objects have\n\
7007
6304d9ea0a30 [project @ 2007-10-11 16:26:36 by jwe]
jwe
parents: 7001
diff changeset
3127 a minimum of two dimensions and row vectors are left unchanged.\n\
4532
01ee68d18069 [project @ 2003-10-10 00:49:54 by jwe]
jwe
parents: 4516
diff changeset
3128 @end deftypefn")
01ee68d18069 [project @ 2003-10-10 00:49:54 by jwe]
jwe
parents: 4516
diff changeset
3129 {
01ee68d18069 [project @ 2003-10-10 00:49:54 by jwe]
jwe
parents: 4516
diff changeset
3130 octave_value retval;
01ee68d18069 [project @ 2003-10-10 00:49:54 by jwe]
jwe
parents: 4516
diff changeset
3131
01ee68d18069 [project @ 2003-10-10 00:49:54 by jwe]
jwe
parents: 4516
diff changeset
3132 if (args.length () == 1)
4545
c16f153836a0 [project @ 2003-10-24 04:45:45 by jwe]
jwe
parents: 4532
diff changeset
3133 retval = args(0).squeeze ();
4532
01ee68d18069 [project @ 2003-10-10 00:49:54 by jwe]
jwe
parents: 4516
diff changeset
3134 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5798
diff changeset
3135 print_usage ();
4532
01ee68d18069 [project @ 2003-10-10 00:49:54 by jwe]
jwe
parents: 4516
diff changeset
3136
01ee68d18069 [project @ 2003-10-10 00:49:54 by jwe]
jwe
parents: 4516
diff changeset
3137 return retval;
01ee68d18069 [project @ 2003-10-10 00:49:54 by jwe]
jwe
parents: 4516
diff changeset
3138 }
01ee68d18069 [project @ 2003-10-10 00:49:54 by jwe]
jwe
parents: 4516
diff changeset
3139
6953
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3140 /*
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3141 %!shared x
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3142 %! x = [1, -3, 4, 5, -7];
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3143 %!assert(norm(x,1), 20);
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3144 %!assert(norm(x,2), 10);
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3145 %!assert(norm(x,3), 8.24257059961711, -4*eps);
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3146 %!assert(norm(x,Inf), 7);
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3147 %!assert(norm(x,-Inf), 1);
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3148 %!assert(norm(x,"inf"), 7);
7103
1ed1a94735a6 [project @ 2007-11-06 17:13:30 by jwe]
jwe
parents: 7102
diff changeset
3149 %!assert(norm(x,"fro"), 10, -eps);
6953
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3150 %!assert(norm(x), 10);
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3151 %!assert(norm([1e200, 1]), 1e200);
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3152 %!assert(norm([3+4i, 3-4i, sqrt(31)]), 9, -4*eps);
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3153 %!shared m
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3154 %! m = magic (4);
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3155 %!assert(norm(m,1), 34);
7026
b60eeac5ac38 [project @ 2007-10-15 08:00:30 by dbateman]
dbateman
parents: 7017
diff changeset
3156 %!assert(norm(m,2), 34, -eps);
6953
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3157 %!assert(norm(m,Inf), 34);
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3158 %!assert(norm(m,"inf"), 34);
7103
1ed1a94735a6 [project @ 2007-11-06 17:13:30 by jwe]
jwe
parents: 7102
diff changeset
3159 %!shared m2, flo, fhi
7102
a627f27c1e8e [project @ 2007-11-06 17:02:11 by jwe]
jwe
parents: 7093
diff changeset
3160 %! m2 = [1,2;3,4];
a627f27c1e8e [project @ 2007-11-06 17:02:11 by jwe]
jwe
parents: 7093
diff changeset
3161 %! flo = 1e-300;
a627f27c1e8e [project @ 2007-11-06 17:02:11 by jwe]
jwe
parents: 7093
diff changeset
3162 %! fhi = 1e+300;
7103
1ed1a94735a6 [project @ 2007-11-06 17:13:30 by jwe]
jwe
parents: 7102
diff changeset
3163 %!assert (norm(flo*m2,"fro"), sqrt(30)*flo, -eps)
1ed1a94735a6 [project @ 2007-11-06 17:13:30 by jwe]
jwe
parents: 7102
diff changeset
3164 %!assert (norm(fhi*m2,"fro"), sqrt(30)*fhi, -eps)
6953
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3165 */
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3166
6945
6bbf56a9718a [project @ 2007-10-02 20:47:22 by jwe]
jwe
parents: 6887
diff changeset
3167 // Compute various norms of the vector X.
6bbf56a9718a [project @ 2007-10-02 20:47:22 by jwe]
jwe
parents: 6887
diff changeset
3168
6953
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3169 DEFUN (norm, args, ,
6508
184ab67c3bc1 [project @ 2007-04-07 00:43:09 by jwe]
jwe
parents: 6401
diff changeset
3170 "-*- texinfo -*-\n\
6953
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3171 @deftypefn {Function File} {} norm (@var{a}, @var{p})\n\
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3172 Compute the p-norm of the matrix @var{a}. If the second argument is\n\
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3173 missing, @code{p = 2} is assumed.\n\
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3174 \n\
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3175 If @var{a} is a matrix:\n\
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3176 \n\
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3177 @table @asis\n\
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3178 @item @var{p} = @code{1}\n\
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3179 1-norm, the largest column sum of the absolute values of @var{a}.\n\
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3180 \n\
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3181 @item @var{p} = @code{2}\n\
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3182 Largest singular value of @var{a}.\n\
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3183 \n\
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents: 7145
diff changeset
3184 @item @var{p} = @code{Inf} or @code{\"inf\"}\n\
6953
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3185 @cindex infinity norm\n\
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3186 Infinity norm, the largest row sum of the absolute values of @var{a}.\n\
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3187 \n\
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3188 @item @var{p} = @code{\"fro\"}\n\
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3189 @cindex Frobenius norm\n\
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3190 Frobenius norm of @var{a}, @code{sqrt (sum (diag (@var{a}' * @var{a})))}.\n\
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3191 @end table\n\
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3192 \n\
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3193 If @var{a} is a vector or a scalar:\n\
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3194 \n\
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3195 @table @asis\n\
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents: 7145
diff changeset
3196 @item @var{p} = @code{Inf} or @code{\"inf\"}\n\
6953
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3197 @code{max (abs (@var{a}))}.\n\
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3198 \n\
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3199 @item @var{p} = @code{-Inf}\n\
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3200 @code{min (abs (@var{a}))}.\n\
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3201 \n\
7189
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents: 7145
diff changeset
3202 @item @var{p} = @code{\"fro\"}\n\
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents: 7145
diff changeset
3203 Frobenius norm of @var{a}, @code{sqrt (sumsq (abs (a)))}.\n\
e8d953d03f6a [project @ 2007-11-26 20:42:09 by dbateman]
dbateman
parents: 7145
diff changeset
3204 \n\
6953
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3205 @item other\n\
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3206 p-norm of @var{a}, @code{(sum (abs (@var{a}) .^ @var{p})) ^ (1/@var{p})}.\n\
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3207 @end table\n\
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3208 @seealso{cond, svd}\n\
6508
184ab67c3bc1 [project @ 2007-04-07 00:43:09 by jwe]
jwe
parents: 6401
diff changeset
3209 @end deftypefn")
184ab67c3bc1 [project @ 2007-04-07 00:43:09 by jwe]
jwe
parents: 6401
diff changeset
3210 {
6953
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3211 // Currently only handles vector norms for full double/complex
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3212 // vectors internally. Other cases are handled by __norm__.m.
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3213
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3214 octave_value_list retval;
6508
184ab67c3bc1 [project @ 2007-04-07 00:43:09 by jwe]
jwe
parents: 6401
diff changeset
3215
184ab67c3bc1 [project @ 2007-04-07 00:43:09 by jwe]
jwe
parents: 6401
diff changeset
3216 int nargin = args.length ();
184ab67c3bc1 [project @ 2007-04-07 00:43:09 by jwe]
jwe
parents: 6401
diff changeset
3217
184ab67c3bc1 [project @ 2007-04-07 00:43:09 by jwe]
jwe
parents: 6401
diff changeset
3218 if (nargin == 1 || nargin == 2)
184ab67c3bc1 [project @ 2007-04-07 00:43:09 by jwe]
jwe
parents: 6401
diff changeset
3219 {
6953
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3220 octave_value x_arg = args(0);
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3221
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3222 if (x_arg.is_empty ())
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3223 retval(0) = 0.0;
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3224 else if (x_arg.ndims () == 2)
6508
184ab67c3bc1 [project @ 2007-04-07 00:43:09 by jwe]
jwe
parents: 6401
diff changeset
3225 {
6953
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3226 if ((x_arg.rows () == 1 || x_arg.columns () == 1)
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3227 && ! (x_arg.is_sparse_type () || x_arg.is_integer_type ()))
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3228 {
7093
e5005117103d [project @ 2007-10-31 23:41:37 by jwe]
jwe
parents: 7078
diff changeset
3229 double p_val = 2;
e5005117103d [project @ 2007-10-31 23:41:37 by jwe]
jwe
parents: 7078
diff changeset
3230
e5005117103d [project @ 2007-10-31 23:41:37 by jwe]
jwe
parents: 7078
diff changeset
3231 if (nargin == 2)
6953
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3232 {
7093
e5005117103d [project @ 2007-10-31 23:41:37 by jwe]
jwe
parents: 7078
diff changeset
3233 octave_value p_arg = args(1);
e5005117103d [project @ 2007-10-31 23:41:37 by jwe]
jwe
parents: 7078
diff changeset
3234
e5005117103d [project @ 2007-10-31 23:41:37 by jwe]
jwe
parents: 7078
diff changeset
3235 if (p_arg.is_string ())
e5005117103d [project @ 2007-10-31 23:41:37 by jwe]
jwe
parents: 7078
diff changeset
3236 {
e5005117103d [project @ 2007-10-31 23:41:37 by jwe]
jwe
parents: 7078
diff changeset
3237 std::string p = args(1).string_value ();
e5005117103d [project @ 2007-10-31 23:41:37 by jwe]
jwe
parents: 7078
diff changeset
3238
e5005117103d [project @ 2007-10-31 23:41:37 by jwe]
jwe
parents: 7078
diff changeset
3239 if (p == "inf")
e5005117103d [project @ 2007-10-31 23:41:37 by jwe]
jwe
parents: 7078
diff changeset
3240 p_val = octave_Inf;
e5005117103d [project @ 2007-10-31 23:41:37 by jwe]
jwe
parents: 7078
diff changeset
3241 else if (p == "fro")
e5005117103d [project @ 2007-10-31 23:41:37 by jwe]
jwe
parents: 7078
diff changeset
3242 p_val = -1;
e5005117103d [project @ 2007-10-31 23:41:37 by jwe]
jwe
parents: 7078
diff changeset
3243 else
e5005117103d [project @ 2007-10-31 23:41:37 by jwe]
jwe
parents: 7078
diff changeset
3244 error ("norm: unrecognized norm `%s'", p.c_str ());
e5005117103d [project @ 2007-10-31 23:41:37 by jwe]
jwe
parents: 7078
diff changeset
3245 }
6953
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3246 else
7093
e5005117103d [project @ 2007-10-31 23:41:37 by jwe]
jwe
parents: 7078
diff changeset
3247 {
e5005117103d [project @ 2007-10-31 23:41:37 by jwe]
jwe
parents: 7078
diff changeset
3248 p_val = p_arg.double_value ();
e5005117103d [project @ 2007-10-31 23:41:37 by jwe]
jwe
parents: 7078
diff changeset
3249
e5005117103d [project @ 2007-10-31 23:41:37 by jwe]
jwe
parents: 7078
diff changeset
3250 if (error_state)
e5005117103d [project @ 2007-10-31 23:41:37 by jwe]
jwe
parents: 7078
diff changeset
3251 error ("norm: unrecognized norm value");
e5005117103d [project @ 2007-10-31 23:41:37 by jwe]
jwe
parents: 7078
diff changeset
3252 }
6953
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3253 }
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3254
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3255 if (! error_state)
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3256 {
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3257 if (x_arg.is_real_type ())
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3258 {
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3259 MArray<double> x (x_arg.array_value ());
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3260
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3261 if (! error_state)
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3262 retval(0) = x.norm (p_val);
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3263 else
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3264 error ("norm: expecting real vector");
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3265 }
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3266 else
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3267 {
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3268 MArray<Complex> x (x_arg.complex_array_value ());
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3269
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3270 if (! error_state)
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3271 retval(0) = x.norm (p_val);
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3272 else
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3273 error ("norm: expecting complex vector");
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3274 }
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3275 }
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3276 }
6508
184ab67c3bc1 [project @ 2007-04-07 00:43:09 by jwe]
jwe
parents: 6401
diff changeset
3277 else
6953
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3278 retval = feval ("__norm__", args);
6508
184ab67c3bc1 [project @ 2007-04-07 00:43:09 by jwe]
jwe
parents: 6401
diff changeset
3279 }
184ab67c3bc1 [project @ 2007-04-07 00:43:09 by jwe]
jwe
parents: 6401
diff changeset
3280 else
6953
4567a35e0777 [project @ 2007-10-04 02:53:11 by jwe]
jwe
parents: 6945
diff changeset
3281 error ("norm: only valid for 2-D objects");
6508
184ab67c3bc1 [project @ 2007-04-07 00:43:09 by jwe]
jwe
parents: 6401
diff changeset
3282 }
184ab67c3bc1 [project @ 2007-04-07 00:43:09 by jwe]
jwe
parents: 6401
diff changeset
3283 else
184ab67c3bc1 [project @ 2007-04-07 00:43:09 by jwe]
jwe
parents: 6401
diff changeset
3284 print_usage ();
184ab67c3bc1 [project @ 2007-04-07 00:43:09 by jwe]
jwe
parents: 6401
diff changeset
3285
7269
3fade00a6ac7 [project @ 2007-12-07 19:26:20 by jwe]
jwe
parents: 7231
diff changeset
3286 // Should not return a sparse type
3fade00a6ac7 [project @ 2007-12-07 19:26:20 by jwe]
jwe
parents: 7231
diff changeset
3287 if (retval(0).is_sparse_type ())
3fade00a6ac7 [project @ 2007-12-07 19:26:20 by jwe]
jwe
parents: 7231
diff changeset
3288 {
3fade00a6ac7 [project @ 2007-12-07 19:26:20 by jwe]
jwe
parents: 7231
diff changeset
3289 if (retval(0).type_name () == "sparse matrix")
3fade00a6ac7 [project @ 2007-12-07 19:26:20 by jwe]
jwe
parents: 7231
diff changeset
3290 retval(0) = retval(0).matrix_value ();
3fade00a6ac7 [project @ 2007-12-07 19:26:20 by jwe]
jwe
parents: 7231
diff changeset
3291 else if (retval(0).type_name () == "sparse complex matrix")
3fade00a6ac7 [project @ 2007-12-07 19:26:20 by jwe]
jwe
parents: 7231
diff changeset
3292 retval(0) = retval(0).complex_matrix_value ();
3fade00a6ac7 [project @ 2007-12-07 19:26:20 by jwe]
jwe
parents: 7231
diff changeset
3293 else if (retval(0).type_name () == "sparse bool matrix")
3fade00a6ac7 [project @ 2007-12-07 19:26:20 by jwe]
jwe
parents: 7231
diff changeset
3294 retval(0) = retval(0).bool_matrix_value ();
3fade00a6ac7 [project @ 2007-12-07 19:26:20 by jwe]
jwe
parents: 7231
diff changeset
3295 }
3fade00a6ac7 [project @ 2007-12-07 19:26:20 by jwe]
jwe
parents: 7231
diff changeset
3296
6508
184ab67c3bc1 [project @ 2007-04-07 00:43:09 by jwe]
jwe
parents: 6401
diff changeset
3297 return retval;
184ab67c3bc1 [project @ 2007-04-07 00:43:09 by jwe]
jwe
parents: 6401
diff changeset
3298 }
184ab67c3bc1 [project @ 2007-04-07 00:43:09 by jwe]
jwe
parents: 6401
diff changeset
3299
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3300 #define UNARY_OP_DEFUN_BODY(F) \
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3301 \
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3302 octave_value retval; \
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3303 \
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3304 if (args.length () == 1) \
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3305 retval = F (args(0)); \
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3306 else \
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3307 print_usage (); \
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3308 \
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3309 return retval
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3310
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3311 DEFUN (not, args, ,
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3312 "-*- texinfo -*-\n\
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3313 @deftypefn {Built-in Function} {} not (@var{x})\n\
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3314 This function is equivalent to @code{! x}.\n\
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3315 @end deftypefn")
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3316 {
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3317 UNARY_OP_DEFUN_BODY (op_not);
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3318 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3319
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3320 DEFUN (uplus, args, ,
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3321 "-*- texinfo -*-\n\
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3322 @deftypefn {Built-in Function} {} uplus (@var{x})\n\
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3323 This function is equivalent to @code{+ x}.\n\
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3324 @end deftypefn")
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3325 {
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3326 UNARY_OP_DEFUN_BODY (op_uplus);
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3327 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3328
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3329 DEFUN (uminus, args, ,
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3330 "-*- texinfo -*-\n\
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3331 @deftypefn {Built-in Function} {} uminus (@var{x})\n\
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3332 This function is equivalent to @code{- x}.\n\
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3333 @end deftypefn")
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3334 {
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3335 UNARY_OP_DEFUN_BODY (op_uminus);
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3336 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3337
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3338 DEFUN (transpose, args, ,
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3339 "-*- texinfo -*-\n\
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3340 @deftypefn {Built-in Function} {} transpose (@var{x})\n\
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3341 This function is equivalent to @code{x.'}.\n\
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3342 @end deftypefn")
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3343 {
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3344 UNARY_OP_DEFUN_BODY (op_transpose);
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3345 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3346
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3347 DEFUN (ctranspose, args, ,
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3348 "-*- texinfo -*-\n\
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3349 @deftypefn {Built-in Function} {} ctranspose (@var{x})\n\
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3350 This function is equivalent to @code{x'}.\n\
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3351 @end deftypefn")
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3352 {
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3353 UNARY_OP_DEFUN_BODY (op_hermitian);
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3354 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3355
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3356 #define BINARY_OP_DEFUN_BODY(F) \
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3357 \
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3358 octave_value retval; \
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3359 \
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3360 if (args.length () == 2) \
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3361 retval = F (args(0), args(1)); \
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3362 else \
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3363 print_usage (); \
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3364 \
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3365 return retval
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3366
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3367 DEFUN (plus, args, ,
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3368 "-*- texinfo -*-\n\
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3369 @deftypefn {Built-in Function} {} plus (@var{x}, @var{y})\n\
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3370 This function is equivalent to @code{x + y}.\n\
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3371 @end deftypefn")
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3372 {
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3373 BINARY_OP_DEFUN_BODY (op_add);
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3374 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3375
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3376 DEFUN (minus, args, ,
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3377 "-*- texinfo -*-\n\
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3378 @deftypefn {Built-in Function} {} minus (@var{x}, @var{y})\n\
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3379 This function is equivalent to @code{x - y}.\n\
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3380 @end deftypefn")
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3381 {
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3382 BINARY_OP_DEFUN_BODY (op_sub);
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3383 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3384
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3385 DEFUN (mtimes, args, ,
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3386 "-*- texinfo -*-\n\
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3387 @deftypefn {Built-in Function} {} mtimes (@var{x}, @var{y})\n\
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3388 This function is equivalent to @code{x * y}.\n\
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3389 @end deftypefn")
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3390 {
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3391 BINARY_OP_DEFUN_BODY (op_mul);
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3392 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3393
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3394 DEFUN (mrdivide, args, ,
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3395 "-*- texinfo -*-\n\
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3396 @deftypefn {Built-in Function} {} mrdivide (@var{x}, @var{y})\n\
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3397 This function is equivalent to @code{x / y}.\n\
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3398 @end deftypefn")
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3399 {
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3400 BINARY_OP_DEFUN_BODY (op_div);
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3401 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3402
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3403 DEFUN (mpower, args, ,
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3404 "-*- texinfo -*-\n\
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3405 @deftypefn {Built-in Function} {} mpower (@var{x}, @var{y})\n\
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3406 This function is equivalent to @code{x ^ y}.\n\
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3407 @end deftypefn")
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3408 {
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3409 BINARY_OP_DEFUN_BODY (op_pow);
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3410 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3411
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3412 DEFUN (mldivide, args, ,
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3413 "-*- texinfo -*-\n\
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3414 @deftypefn {Built-in Function} {} mldivide (@var{x}, @var{y})\n\
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3415 This function is equivalent to @code{x \\ y}.\n\
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3416 @end deftypefn")
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3417 {
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3418 BINARY_OP_DEFUN_BODY (op_ldiv);
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3419 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3420
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3421 DEFUN (lt, args, ,
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3422 "-*- texinfo -*-\n\
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3423 @deftypefn {Built-in Function} {} lt (@var{x}, @var{y})\n\
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3424 This function is equivalent to @code{x < y}.\n\
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3425 @end deftypefn")
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3426 {
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3427 BINARY_OP_DEFUN_BODY (op_lt);
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3428 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3429
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3430 DEFUN (le, args, ,
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3431 "-*- texinfo -*-\n\
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3432 @deftypefn {Built-in Function} {} le (@var{x}, @var{y})\n\
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3433 This function is equivalent to @code{x <= y}.\n\
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3434 @end deftypefn")
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3435 {
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3436 BINARY_OP_DEFUN_BODY (op_le);
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3437 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3438
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3439 DEFUN (eq, args, ,
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3440 "-*- texinfo -*-\n\
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3441 @deftypefn {Built-in Function} {} eq (@var{x}, @var{y})\n\
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3442 This function is equivalent to @code{x == y}.\n\
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3443 @end deftypefn")
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3444 {
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3445 BINARY_OP_DEFUN_BODY (op_eq);
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3446 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3447
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3448 DEFUN (ge, args, ,
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3449 "-*- texinfo -*-\n\
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3450 @deftypefn {Built-in Function} {} ge (@var{x}, @var{y})\n\
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3451 This function is equivalent to @code{x >= y}.\n\
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3452 @end deftypefn")
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3453 {
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3454 BINARY_OP_DEFUN_BODY (op_ge);
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3455 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3456
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3457 DEFUN (gt, args, ,
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3458 "-*- texinfo -*-\n\
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3459 @deftypefn {Built-in Function} {} gt (@var{x}, @var{y})\n\
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3460 This function is equivalent to @code{x > y}.\n\
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3461 @end deftypefn")
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3462 {
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3463 BINARY_OP_DEFUN_BODY (op_gt);
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3464 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3465
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3466 DEFUN (ne, args, ,
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3467 "-*- texinfo -*-\n\
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3468 @deftypefn {Built-in Function} {} ne (@var{x}, @var{y})\n\
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3469 This function is equivalent to @code{x != y}.\n\
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3470 @end deftypefn")
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3471 {
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3472 BINARY_OP_DEFUN_BODY (op_ne);
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3473 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3474
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3475 DEFUN (times, args, ,
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3476 "-*- texinfo -*-\n\
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3477 @deftypefn {Built-in Function} {} times (@var{x}, @var{y})\n\
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3478 This function is equivalent to @code{x .* y}.\n\
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3479 @end deftypefn")
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3480 {
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3481 BINARY_OP_DEFUN_BODY (op_el_mul);
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3482 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3483
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3484 DEFUN (rdivide, args, ,
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3485 "-*- texinfo -*-\n\
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3486 @deftypefn {Built-in Function} {} rdivide (@var{x}, @var{y})\n\
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3487 This function is equivalent to @code{x ./ y}.\n\
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3488 @end deftypefn")
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3489 {
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3490 BINARY_OP_DEFUN_BODY (op_el_div);
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3491 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3492
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3493 DEFUN (power, args, ,
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3494 "-*- texinfo -*-\n\
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3495 @deftypefn {Built-in Function} {} power (@var{x}, @var{y})\n\
7623
431f3788f5c4 minor doc patch
David Bateman <dbateman@free.fr>
parents: 7620
diff changeset
3496 This function is equivalent to @code{x .^ y}.\n\
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3497 @end deftypefn")
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3498 {
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3499 BINARY_OP_DEFUN_BODY (op_el_pow);
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3500 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3501
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3502 DEFUN (ldivide, args, ,
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3503 "-*- texinfo -*-\n\
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3504 @deftypefn {Built-in Function} {} ldivide (@var{x}, @var{y})\n\
7623
431f3788f5c4 minor doc patch
David Bateman <dbateman@free.fr>
parents: 7620
diff changeset
3505 This function is equivalent to @code{x .\\ y}.\n\
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3506 @end deftypefn")
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3507 {
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3508 BINARY_OP_DEFUN_BODY (op_el_ldiv);
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3509 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3510
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3511 DEFUN (and, args, ,
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3512 "-*- texinfo -*-\n\
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3513 @deftypefn {Built-in Function} {} and (@var{x}, @var{y})\n\
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3514 This function is equivalent to @code{x & y}.\n\
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3515 @end deftypefn")
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3516 {
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3517 BINARY_OP_DEFUN_BODY (op_el_and);
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3518 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3519
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3520 DEFUN (or, args, ,
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3521 "-*- texinfo -*-\n\
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3522 @deftypefn {Built-in Function} {} or (@var{x}, @var{y})\n\
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3523 This function is equivalent to @code{x | y}.\n\
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3524 @end deftypefn")
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3525 {
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3526 BINARY_OP_DEFUN_BODY (op_el_or);
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3527 }
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6508
diff changeset
3528
7065
97db94ae2cf0 [project @ 2007-10-25 05:50:55 by jwe]
jwe
parents: 7045
diff changeset
3529 static double tic_toc_timestamp = -1.0;
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3530
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3531 DEFUN (tic, args, nargout,
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3532 "-*- texinfo -*-\n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3533 @deftypefn {Built-in Function} {} tic ()\n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3534 @deftypefnx {Built-in Function} {} toc ()\n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3535 Set or check a wall-clock timer. Calling @code{tic} without an\n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3536 output argument sets the timer. Subsequent calls to @code{toc}\n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3537 return the number of seconds since the timer was set. For example,\n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3538 \n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3539 @example\n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3540 tic ();\n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3541 # many computations later...\n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3542 elapsed_time = toc ();\n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3543 @end example\n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3544 \n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3545 @noindent\n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3546 will set the variable @code{elapsed_time} to the number of seconds since\n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3547 the most recent call to the function @code{tic}.\n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3548 \n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3549 If called with one output argument then this function returns a scalar\n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3550 of type @code{uint64} and the wall-clock timer is not started.\n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3551 \n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3552 @example\n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3553 @group\n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3554 t = tic; sleep (5); (double (tic ()) - double (t)) * 1e-6\n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3555 @result{} 5\n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3556 @end group\n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3557 @end example\n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3558 \n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3559 Nested timing with @code{tic} and @code{toc} is not supported.\n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3560 Therefore @code{toc} will always return the elapsed time from the most\n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3561 recent call to @code{tic}.\n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3562 \n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3563 If you are more interested in the CPU time that your process used, you\n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3564 should use the @code{cputime} function instead. The @code{tic} and\n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3565 @code{toc} functions report the actual wall clock time that elapsed\n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3566 between the calls. This may include time spent processing other jobs or\n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3567 doing nothing at all. For example,\n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3568 \n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3569 @example\n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3570 @group\n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3571 tic (); sleep (5); toc ()\n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3572 @result{} 5\n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3573 t = cputime (); sleep (5); cputime () - t\n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3574 @result{} 0\n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3575 @end group\n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3576 @end example\n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3577 \n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3578 @noindent\n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3579 (This example also illustrates that the CPU timer may have a fairly\n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3580 coarse resolution.)\n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3581 @end deftypefn")
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3582 {
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3583 octave_value retval;
7065
97db94ae2cf0 [project @ 2007-10-25 05:50:55 by jwe]
jwe
parents: 7045
diff changeset
3584
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3585 int nargin = args.length ();
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3586
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3587 if (nargin != 0)
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3588 warning ("tic: ignoring extra arguments");
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3589
7065
97db94ae2cf0 [project @ 2007-10-25 05:50:55 by jwe]
jwe
parents: 7045
diff changeset
3590 octave_time now;
97db94ae2cf0 [project @ 2007-10-25 05:50:55 by jwe]
jwe
parents: 7045
diff changeset
3591
97db94ae2cf0 [project @ 2007-10-25 05:50:55 by jwe]
jwe
parents: 7045
diff changeset
3592 double tmp = now.double_value ();
97db94ae2cf0 [project @ 2007-10-25 05:50:55 by jwe]
jwe
parents: 7045
diff changeset
3593
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3594 if (nargout > 0)
7065
97db94ae2cf0 [project @ 2007-10-25 05:50:55 by jwe]
jwe
parents: 7045
diff changeset
3595 retval = static_cast<octave_uint64> (1e6 * tmp);
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3596 else
7065
97db94ae2cf0 [project @ 2007-10-25 05:50:55 by jwe]
jwe
parents: 7045
diff changeset
3597 tic_toc_timestamp = tmp;
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3598
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3599 return retval;
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3600 }
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3601
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3602 DEFUN (toc, args, nargout,
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3603 "-*- texinfo -*-\n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3604 @deftypefn {Built-in Function} {} toc ()\n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3605 See tic.\n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3606 @end deftypefn")
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3607 {
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3608 octave_value retval;
7065
97db94ae2cf0 [project @ 2007-10-25 05:50:55 by jwe]
jwe
parents: 7045
diff changeset
3609
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3610 int nargin = args.length ();
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3611
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3612 if (nargin != 0)
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3613 warning ("tic: ignoring extra arguments");
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3614
7065
97db94ae2cf0 [project @ 2007-10-25 05:50:55 by jwe]
jwe
parents: 7045
diff changeset
3615 if (tic_toc_timestamp < 0)
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3616 {
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3617 warning ("toc called before timer set");
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3618 if (nargout > 0)
7065
97db94ae2cf0 [project @ 2007-10-25 05:50:55 by jwe]
jwe
parents: 7045
diff changeset
3619 retval = Matrix ();
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3620 }
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3621 else
7065
97db94ae2cf0 [project @ 2007-10-25 05:50:55 by jwe]
jwe
parents: 7045
diff changeset
3622 {
97db94ae2cf0 [project @ 2007-10-25 05:50:55 by jwe]
jwe
parents: 7045
diff changeset
3623 octave_time now;
97db94ae2cf0 [project @ 2007-10-25 05:50:55 by jwe]
jwe
parents: 7045
diff changeset
3624
97db94ae2cf0 [project @ 2007-10-25 05:50:55 by jwe]
jwe
parents: 7045
diff changeset
3625 double tmp = now.double_value () - tic_toc_timestamp;
97db94ae2cf0 [project @ 2007-10-25 05:50:55 by jwe]
jwe
parents: 7045
diff changeset
3626
97db94ae2cf0 [project @ 2007-10-25 05:50:55 by jwe]
jwe
parents: 7045
diff changeset
3627 if (nargout > 0)
97db94ae2cf0 [project @ 2007-10-25 05:50:55 by jwe]
jwe
parents: 7045
diff changeset
3628 retval = tmp;
97db94ae2cf0 [project @ 2007-10-25 05:50:55 by jwe]
jwe
parents: 7045
diff changeset
3629 else
97db94ae2cf0 [project @ 2007-10-25 05:50:55 by jwe]
jwe
parents: 7045
diff changeset
3630 octave_stdout << "Elapsed time is " << tmp << " seconds.\n";
97db94ae2cf0 [project @ 2007-10-25 05:50:55 by jwe]
jwe
parents: 7045
diff changeset
3631 }
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3632
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3633 return retval;
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3634 }
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3635
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3636 DEFUN (cputime, args, ,
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3637 "-*- texinfo -*-\n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3638 @deftypefn {Built-in Function} {[@var{total}, @var{user}, @var{system}] =} cputime ();\n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3639 Return the CPU time used by your Octave session. The first output is\n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3640 the total time spent executing your process and is equal to the sum of\n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3641 second and third outputs, which are the number of CPU seconds spent\n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3642 executing in user mode and the number of CPU seconds spent executing in\n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3643 system mode, respectively. If your system does not have a way to report\n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3644 CPU time usage, @code{cputime} returns 0 for each of its output values.\n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3645 Note that because Octave used some CPU time to start, it is reasonable\n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3646 to check to see if @code{cputime} works by checking to see if the total\n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3647 CPU time used is nonzero.\n\
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3648 @end deftypefn")
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3649 {
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3650 octave_value_list retval;
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3651 int nargin = args.length ();
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3652 double usr = 0.0;
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3653 double sys = 0.0;
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3654
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3655 if (nargin != 0)
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3656 warning ("tic: ignoring extra arguments");
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3657
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3658 #if defined (HAVE_GETRUSAGE)
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3659
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3660 struct rusage ru;
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3661
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3662 getrusage (RUSAGE_SELF, &ru);
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3663
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3664 usr = static_cast<double> (ru.ru_utime.tv_sec) +
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3665 static_cast<double> (ru.ru_utime.tv_usec) * 1e-6;
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3666
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3667 sys = static_cast<double> (ru.ru_stime.tv_sec) +
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3668 static_cast<double> (ru.ru_stime.tv_usec) * 1e-6;
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3669
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3670 #elif defined (HAVE_TIMES) && defined (HAVE_SYS_TIMES_H)
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3671
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3672 struct tms t;
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3673
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3674 times (&t);
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3675
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3676 unsigned long ticks;
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3677 unsigned long seconds;
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3678 unsigned long fraction;
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3679
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3680 ticks = t.tms_utime + t.tms_cutime;
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3681 fraction = ticks % HZ;
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3682 seconds = ticks / HZ;
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3683
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3684 usr = static_cast<double> (seconds) + static_cast<double>(fraction) /
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3685 static_cast<double>(HZ);
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3686
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3687 ticks = t.tms_stime + t.tms_cstime;
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3688 fraction = ticks % HZ;
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3689 seconds = ticks / HZ;
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3690
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3691 sys = static_cast<double> (seconds) + static_cast<double>(fraction) /
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3692 static_cast<double>(HZ);
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3693
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3694 #elif defined (__WIN32__)
7145
d169c9f4a697 [project @ 2007-11-09 17:43:06 by jwe]
jwe
parents: 7144
diff changeset
3695
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3696 HANDLE hProcess = GetCurrentProcess ();
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3697 FILETIME ftCreation, ftExit, ftUser, ftKernel;
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3698 GetProcessTimes (hProcess, &ftCreation, &ftExit, &ftKernel, &ftUser);
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3699
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3700 int64_t itmp = *(reinterpret_cast<int64_t *> (&ftUser));
7145
d169c9f4a697 [project @ 2007-11-09 17:43:06 by jwe]
jwe
parents: 7144
diff changeset
3701 usr = static_cast<double> (itmp) * 1e-7;
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3702
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3703 itmp = *(reinterpret_cast<int64_t *> (&ftKernel));
7145
d169c9f4a697 [project @ 2007-11-09 17:43:06 by jwe]
jwe
parents: 7144
diff changeset
3704 sys = static_cast<double> (itmp) * 1e-7;
7045
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3705
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3706 #endif
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3707
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3708 retval (2) = sys;
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3709 retval (1) = usr;
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3710 retval (0) = sys + usr;
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3711
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3712 return retval;
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3713 }
271fa61d8fae [project @ 2007-10-22 11:52:38 by dbateman]
dbateman
parents: 7026
diff changeset
3714
7433
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3715 DEFUN (sort, args, nargout,
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3716 "-*- texinfo -*-\n\
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3717 @deftypefn {Loadable Function} {[@var{s}, @var{i}] =} sort (@var{x})\n\
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3718 @deftypefnx {Loadable Function} {[@var{s}, @var{i}] =} sort (@var{x}, @var{dim})\n\
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3719 @deftypefnx {Loadable Function} {[@var{s}, @var{i}] =} sort (@var{x}, @var{mode})\n\
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3720 @deftypefnx {Loadable Function} {[@var{s}, @var{i}] =} sort (@var{x}, @var{dim}, @var{mode})\n\
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3721 Return a copy of @var{x} with the elements arranged in increasing\n\
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3722 order. For matrices, @code{sort} orders the elements in each column.\n\
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3723 \n\
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3724 For example,\n\
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3725 \n\
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3726 @example\n\
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3727 @group\n\
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3728 sort ([1, 2; 2, 3; 3, 1])\n\
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3729 @result{} 1 1\n\
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3730 2 2\n\
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3731 3 3\n\
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3732 @end group\n\
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3733 @end example\n\
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3734 \n\
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3735 The @code{sort} function may also be used to produce a matrix\n\
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3736 containing the original row indices of the elements in the sorted\n\
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3737 matrix. For example,\n\
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3738 \n\
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3739 @example\n\
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3740 @group\n\
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3741 [s, i] = sort ([1, 2; 2, 3; 3, 1])\n\
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3742 @result{} s = 1 1\n\
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3743 2 2\n\
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3744 3 3\n\
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3745 @result{} i = 1 3\n\
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3746 2 1\n\
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3747 3 2\n\
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3748 @end group\n\
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3749 @end example\n\
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3750 \n\
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3751 If the optional argument @var{dim} is given, then the matrix is sorted\n\
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3752 along the dimension defined by @var{dim}. The optional argument @code{mode}\n\
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3753 defines the order in which the values will be sorted. Valid values of\n\
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3754 @code{mode} are `ascend' or `descend'.\n\
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3755 \n\
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3756 For equal elements, the indices are such that the equal elements are listed\n\
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3757 in the order that appeared in the original list.\n\
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3758 \n\
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3759 The @code{sort} function may also be used to sort strings and cell arrays\n\
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3760 of strings, in which case the dictionary order of the strings is used.\n\
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3761 \n\
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3762 The algorithm used in @code{sort} is optimized for the sorting of partially\n\
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3763 ordered lists.\n\
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3764 @end deftypefn")
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3765 {
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3766 octave_value_list retval;
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3767
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3768 int nargin = args.length ();
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3769 sortmode smode = ASCENDING;
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3770
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3771 if (nargin < 1 || nargin > 3)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3772 {
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3773 print_usage ();
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3774 return retval;
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3775 }
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3776
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3777 bool return_idx = nargout > 1;
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3778
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3779 octave_value arg = args(0);
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3780
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3781 int dim = 0;
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3782 if (nargin > 1)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3783 {
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3784 if (args(1).is_string ())
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3785 {
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3786 std::string mode = args(1).string_value();
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3787 if (mode == "ascend")
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3788 smode = ASCENDING;
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3789 else if (mode == "descend")
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3790 smode = DESCENDING;
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3791 else
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3792 {
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3793 error ("sort: mode must be either \"ascend\" or \"descend\"");
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3794 return retval;
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3795 }
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3796 }
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3797 else
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3798 dim = args(1).nint_value () - 1;
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3799 }
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3800
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3801 if (nargin > 2)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3802 {
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3803 if (args(1).is_string ())
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3804 {
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3805 print_usage ();
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3806 return retval;
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3807 }
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3808
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3809 if (! args(2).is_string ())
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3810 {
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3811 error ("sort: mode must be a string");
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3812 return retval;
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3813 }
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3814 std::string mode = args(2).string_value();
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3815 if (mode == "ascend")
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3816 smode = ASCENDING;
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3817 else if (mode == "descend")
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3818 smode = DESCENDING;
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3819 else
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3820 {
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3821 error ("sort: mode must be either \"ascend\" or \"descend\"");
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3822 return retval;
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3823 }
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3824 }
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3825
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3826 dim_vector dv = arg.dims ();
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3827 if (error_state)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3828 {
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3829 gripe_wrong_type_arg ("sort", arg);
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3830 return retval;
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3831 }
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3832 if (nargin == 1 || args(1).is_string ())
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3833 {
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3834 // Find first non singleton dimension
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3835 for (int i = 0; i < dv.length (); i++)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3836 if (dv(i) > 1)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3837 {
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3838 dim = i;
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3839 break;
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3840 }
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3841 }
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3842 else
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3843 {
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3844 if (dim < 0 || dim > dv.length () - 1)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3845 {
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3846 error ("sort: dim must be a valid dimension");
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3847 return retval;
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3848 }
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3849 }
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3850
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3851 if (return_idx)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3852 {
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3853 Array<octave_idx_type> sidx;
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3854
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3855 retval (0) = arg.sort (sidx, dim, smode);
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3856
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3857 octave_idx_type *ps = sidx.fortran_vec ();
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3858 NDArray midx (sidx.dims ());
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3859 double *pm = midx.fortran_vec ();
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3860
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3861 for (octave_idx_type i = 0; i < sidx.numel (); i++)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3862 pm [i] = static_cast<double>
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3863 (ps [i] + static_cast<octave_idx_type> (1));
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3864
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3865 retval (1) = midx;
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3866 }
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3867 else
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3868 retval(0) = arg.sort (dim, smode);
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3869
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3870 return retval;
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3871 }
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3872
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3873 /*
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3874
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3875 %% Double
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3876 %!assert (sort ([NaN, 1, -1, 2, Inf]), [-1, 1, 2, Inf, NaN])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3877 %!assert (sort ([NaN, 1, -1, 2, Inf], 1), [NaN, 1, -1, 2, Inf])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3878 %!assert (sort ([NaN, 1, -1, 2, Inf], 2), [-1, 1, 2, Inf, NaN])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3879 %!error (sort ([NaN, 1, -1, 2, Inf], 3))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3880 %!assert (sort ([NaN, 1, -1, 2, Inf], "ascend"), [-1, 1, 2, Inf, NaN])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3881 %!assert (sort ([NaN, 1, -1, 2, Inf], 2, "ascend"), [-1, 1, 2, Inf, NaN])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3882 %!assert (sort ([NaN, 1, -1, 2, Inf], "descend"), [NaN, Inf, 2, 1, -1])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3883 %!assert (sort ([NaN, 1, -1, 2, Inf], 2, "descend"), [NaN, Inf, 2, 1, -1])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3884 %!assert (sort ([3, 1, 7, 5; 8, 2, 6, 4]), [3, 1, 6, 4; 8, 2, 7, 5])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3885 %!assert (sort ([3, 1, 7, 5; 8, 2, 6, 4], 1), [3, 1, 6, 4; 8, 2, 7, 5])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3886 %!assert (sort ([3, 1, 7, 5; 8, 2, 6, 4], 2), [1, 3, 5, 7; 2, 4, 6, 8])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3887 %!assert (sort (1), 1)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3888
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3889 %!test
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3890 %! [v, i] = sort ([NaN, 1, -1, Inf, 1]);
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3891 %! assert (v, [-1, 1, 1, Inf, NaN])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3892 %! assert (i, [3, 2, 5, 4, 1])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3893
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3894 %% Complex
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3895 %!assert (sort ([NaN, 1i, -1, 2, Inf]), [1i, -1, 2, Inf, NaN])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3896 %!assert (sort ([NaN, 1i, -1, 2, Inf], 1), [NaN, 1i, -1, 2, Inf])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3897 %!assert (sort ([NaN, 1i, -1, 2, Inf], 2), [1i, -1, 2, Inf, NaN])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3898 %!error (sort ([NaN, 1i, -1, 2, Inf], 3))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3899 %!assert (sort ([NaN, 1i, -1, 2, Inf], "ascend"), [1i, -1, 2, Inf, NaN])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3900 %!assert (sort ([NaN, 1i, -1, 2, Inf], 2, "ascend"), [1i, -1, 2, Inf, NaN])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3901 %!assert (sort ([NaN, 1i, -1, 2, Inf], "descend"), [NaN, Inf, 2, -1, 1i])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3902 %!assert (sort ([NaN, 1i, -1, 2, Inf], 2, "descend"), [NaN, Inf, 2, -1, 1i])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3903 %!assert (sort ([3, 1i, 7, 5; 8, 2, 6, 4]), [3, 1i, 6, 4; 8, 2, 7, 5])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3904 %!assert (sort ([3, 1i, 7, 5; 8, 2, 6, 4], 1), [3, 1i, 6, 4; 8, 2, 7, 5])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3905 %!assert (sort ([3, 1i, 7, 5; 8, 2, 6, 4], 2), [1i, 3, 5, 7; 2, 4, 6, 8])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3906 %!assert (sort (1i), 1i)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3907
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3908 %!test
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3909 %! [v, i] = sort ([NaN, 1i, -1, Inf, 1, 1i]);
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3910 %! assert (v, [1, 1i, 1i, -1, Inf, NaN])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3911 %! assert (i, [5, 2, 6, 3, 4, 1])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3912
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3913 %% Bool
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3914 %!assert (sort ([true, false, true, false]), [false, false, true, true])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3915 %!assert (sort ([true, false, true, false], 1), [true, false, true, false])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3916 %!assert (sort ([true, false, true, false], 2), [false, false, true, true])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3917 %!error (sort ([true, false, true, false], 3))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3918 %!assert (sort ([true, false, true, false], "ascend"), [false, false, true, true])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3919 %!assert (sort ([true, false, true, false], 2, "ascend"), [false, false, true, true])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3920 %!assert (sort ([true, false, true, false], "descend"), [true, true, false, false])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3921 %!assert (sort ([true, false, true, false], 2, "descend"), [true, true, false, false])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3922 %!assert (sort (true), true)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3923
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3924 %!test
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3925 %! [v, i] = sort ([true, false, true, false]);
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3926 %! assert (v, [false, false, true, true])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3927 %! assert (i, [2, 4, 1, 3])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3928
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3929 %% Sparse Double
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3930 %!assert (sort (sparse ([0, NaN, 1, 0, -1, 2, Inf])), sparse ([-1, 0, 0, 1, 2, Inf, NaN]))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3931 %!assert (sort (sparse ([0, NaN, 1, 0, -1, 2, Inf]), 1), sparse ([0, NaN, 1, 0, -1, 2, Inf]))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3932 %!assert (sort (sparse ([0, NaN, 1, 0, -1, 2, Inf]), 2), sparse ([-1, 0, 0, 1, 2, Inf, NaN]))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3933 %!error (sort (sparse ([0, NaN, 1, 0, -1, 2, Inf]), 3))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3934 %!assert (sort (sparse ([0, NaN, 1, 0, -1, 2, Inf]), "ascend"), sparse ([-1, 0, 0, 1, 2, Inf, NaN]))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3935 %!assert (sort (sparse ([0, NaN, 1, 0, -1, 2, Inf]), 2, "ascend"), sparse ([-1, 0, 0, 1, 2, Inf, NaN]))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3936 %!assert (sort (sparse ([0, NaN, 1, 0, -1, 2, Inf]), "descend"), sparse ([NaN, Inf, 2, 1, 0, 0, -1]))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3937 %!assert (sort (sparse ([0, NaN, 1, 0, -1, 2, Inf]), 2, "descend"), sparse ([NaN, Inf, 2, 1, 0, 0, -1]))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3938
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3939 %!shared a
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3940 %! a = randn (10, 10);
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3941 %! a (a < 0) = 0;
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3942 %!assert (sort (sparse (a)), sparse (sort (a)))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3943 %!assert (sort (sparse (a), 1), sparse (sort (a, 1)))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3944 %!assert (sort (sparse (a), 2), sparse (sort (a, 2)))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3945 %!test
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3946 %! [v, i] = sort (a);
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3947 %! [vs, is] = sort (sparse (a));
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3948 %! assert (vs, sparse (v))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3949 %! assert (is, i)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3950
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3951 %% Sparse Complex
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3952 %!assert (sort (sparse ([0, NaN, 1i, 0, -1, 2, Inf])), sparse ([0, 0, 1i, -1, 2, Inf, NaN]))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3953 %!assert (sort (sparse ([0, NaN, 1i, 0, -1, 2, Inf]), 1), sparse ([0, NaN, 1i, 0, -1, 2, Inf]))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3954 %!assert (sort (sparse ([0, NaN, 1i, 0, -1, 2, Inf]), 2), sparse ([0, 0, 1i, -1, 2, Inf, NaN]))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3955 %!error (sort (sparse ([0, NaN, 1i, 0, -1, 2, Inf]), 3))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3956 %!assert (sort (sparse ([0, NaN, 1i, 0, -1, 2, Inf]), "ascend"), sparse ([0, 0, 1i, -1, 2, Inf, NaN]))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3957 %!assert (sort (sparse ([0, NaN, 1i, 0, -1, 2, Inf]), 2, "ascend"), sparse ([0, 0, 1i, -1, 2, Inf, NaN]))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3958 %!assert (sort (sparse ([0, NaN, 1i, 0, -1, 2, Inf]), "descend"), sparse ([NaN, Inf, 2, -1, 1i, 0, 0]))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3959 %!assert (sort (sparse ([0, NaN, 1i, 0, -1, 2, Inf]), 2, "descend"), sparse ([NaN, Inf, 2, -1, 1i, 0, 0]))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3960
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3961 %!shared a
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3962 %! a = randn (10, 10);
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3963 %! a (a < 0) = 0;
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3964 %! a = 1i * a;
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3965 %!assert (sort (sparse (a)), sparse (sort (a)))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3966 %!assert (sort (sparse (a), 1), sparse (sort (a, 1)))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3967 %!assert (sort (sparse (a), 2), sparse (sort (a, 2)))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3968 %!test
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3969 %! [v, i] = sort (a);
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3970 %! [vs, is] = sort (sparse (a));
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3971 %! assert (vs, sparse (v))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3972 %! assert (is, i)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3973
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3974 %% Sparse Bool
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3975 %!assert (sort (sparse ([true, false, true, false])), sparse ([false, false, true, true]))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3976 %!assert (sort (sparse([true, false, true, false]), 1), sparse ([true, false, true, false]))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3977 %!assert (sort (sparse ([true, false, true, false]), 2), sparse ([false, false, true, true]))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3978 %!error (sort (sparse ([true, false, true, false], 3)))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3979 %!assert (sort (sparse ([true, false, true, false]), "ascend"), sparse([false, false, true, true]))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3980 %!assert (sort (sparse ([true, false, true, false]), 2, "ascend"), sparse([false, false, true, true]))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3981 %!assert (sort (sparse ([true, false, true, false]), "descend"), sparse ([true, true, false, false]))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3982 %!assert (sort (sparse ([true, false, true, false]), 2, "descend"), sparse([true, true, false, false]))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3983
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3984 %!test
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3985 %! [v, i] = sort (sparse([true, false, true, false]));
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3986 %! assert (v, sparse([false, false, true, true]))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3987 %! assert (i, [2, 4, 1, 3])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3988
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3989 %% Cell string array
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3990 %!shared a, b, c
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3991 %! a = {"Alice", "Cecile", "Eric", "Barry", "David"};
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3992 %! b = {"Alice", "Barry", "Cecile", "David", "Eric"};
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3993 %! c = {"Eric", "David", "Cecile", "Barry", "Alice"};
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3994 %!assert (sort (a), b);
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3995 %!assert (sort (a, 1), a)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3996 %!assert (sort (a, 2), b)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3997 %!error (sort (a, 3))
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3998 %!assert (sort (a, "ascend"), b)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
3999 %!assert (sort (a, 2, "ascend"), b)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
4000 %!assert (sort (a, "descend"), c)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
4001 %!assert (sort (a, 2, "descend"), c)
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
4002
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
4003 %!test
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
4004 %! [v, i] = sort (a);
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
4005 %! assert (i, [1, 4, 2, 5, 3])
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
4006
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
4007 */
402168152bb9 [project @ 2008-01-31 18:59:09 by dbateman]
dbateman
parents: 7269
diff changeset
4008
523
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
4009 /*
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
4010 ;;; Local Variables: ***
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
4011 ;;; mode: C++ ***
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
4012 ;;; End: ***
4a07f0083ab0 [project @ 1994-07-20 18:33:47 by jwe]
jwe
parents:
diff changeset
4013 */