523
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
523
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
5307
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
523
|
21 |
|
22 */ |
|
23 |
|
24 #ifdef HAVE_CONFIG_H |
1192
|
25 #include <config.h> |
523
|
26 #endif |
|
27 |
2184
|
28 #include <cfloat> |
|
29 #include <cmath> |
|
30 |
1728
|
31 #include <string> |
|
32 |
2184
|
33 #include "lo-ieee.h" |
1755
|
34 #include "str-vec.h" |
4153
|
35 #include "quit.h" |
1755
|
36 |
6953
|
37 #include "Cell.h" |
1352
|
38 #include "defun.h" |
|
39 #include "error.h" |
|
40 #include "gripes.h" |
6953
|
41 #include "oct-map.h" |
|
42 #include "oct-obj.h" |
2366
|
43 #include "ov.h" |
5476
|
44 #include "ov-complex.h" |
|
45 #include "ov-cx-mat.h" |
6953
|
46 #include "parse.h" |
|
47 #include "pt-mat.h" |
523
|
48 #include "utils.h" |
6953
|
49 #include "variables.h" |
523
|
50 |
4015
|
51 #define ANY_ALL(FCN) \ |
|
52 \ |
4233
|
53 octave_value retval; \ |
4015
|
54 \ |
|
55 int nargin = args.length (); \ |
|
56 \ |
4021
|
57 if (nargin == 1 || nargin == 2) \ |
4015
|
58 { \ |
4021
|
59 int dim = (nargin == 1 ? -1 : args(1).int_value (true) - 1); \ |
|
60 \ |
|
61 if (! error_state) \ |
|
62 { \ |
4556
|
63 if (dim >= -1) \ |
4015
|
64 retval = args(0).FCN (dim); \ |
4021
|
65 else \ |
|
66 error (#FCN ": invalid dimension argument = %d", dim + 1); \ |
|
67 } \ |
4015
|
68 else \ |
4021
|
69 error (#FCN ": expecting dimension argument to be an integer"); \ |
4015
|
70 } \ |
4021
|
71 else \ |
5823
|
72 print_usage (); \ |
4015
|
73 \ |
|
74 return retval |
|
75 |
1957
|
76 DEFUN (all, args, , |
3369
|
77 "-*- texinfo -*-\n\ |
4015
|
78 @deftypefn {Built-in Function} {} all (@var{x}, @var{dim})\n\ |
3369
|
79 The function @code{all} behaves like the function @code{any}, except\n\ |
|
80 that it returns true only if all the elements of a vector, or all the\n\ |
4015
|
81 elements along dimension @var{dim} of a matrix, are nonzero.\n\ |
3369
|
82 @end deftypefn") |
523
|
83 { |
4015
|
84 ANY_ALL (all); |
523
|
85 } |
|
86 |
1957
|
87 DEFUN (any, args, , |
3369
|
88 "-*- texinfo -*-\n\ |
4015
|
89 @deftypefn {Built-in Function} {} any (@var{x}, @var{dim})\n\ |
3369
|
90 For a vector argument, return 1 if any element of the vector is\n\ |
|
91 nonzero.\n\ |
|
92 \n\ |
|
93 For a matrix argument, return a row vector of ones and\n\ |
|
94 zeros with each element indicating whether any of the elements of the\n\ |
|
95 corresponding column of the matrix are nonzero. For example,\n\ |
|
96 \n\ |
|
97 @example\n\ |
|
98 @group\n\ |
|
99 any (eye (2, 4))\n\ |
|
100 @result{} [ 1, 1, 0, 0 ]\n\ |
|
101 @end group\n\ |
|
102 @end example\n\ |
|
103 \n\ |
4015
|
104 If the optional argument @var{dim} is supplied, work along dimension\n\ |
|
105 @var{dim}. For example,\n\ |
3369
|
106 \n\ |
|
107 @example\n\ |
4015
|
108 @group\n\ |
|
109 any (eye (2, 4), 2)\n\ |
|
110 @result{} [ 1; 1 ]\n\ |
|
111 @end group\n\ |
3369
|
112 @end example\n\ |
|
113 @end deftypefn") |
523
|
114 { |
4015
|
115 ANY_ALL (any); |
523
|
116 } |
|
117 |
649
|
118 // These mapping functions may also be useful in other places, eh? |
|
119 |
|
120 typedef double (*d_dd_fcn) (double, double); |
|
121 |
|
122 static Matrix |
2672
|
123 map_d_m (d_dd_fcn f, double x, const Matrix& y) |
649
|
124 { |
5275
|
125 octave_idx_type nr = y.rows (); |
|
126 octave_idx_type nc = y.columns (); |
649
|
127 |
|
128 Matrix retval (nr, nc); |
|
129 |
5275
|
130 for (octave_idx_type j = 0; j < nc; j++) |
|
131 for (octave_idx_type i = 0; i < nr; i++) |
4153
|
132 { |
|
133 OCTAVE_QUIT; |
|
134 retval (i, j) = f (x, y (i, j)); |
|
135 } |
649
|
136 |
|
137 return retval; |
|
138 } |
|
139 |
|
140 static Matrix |
2672
|
141 map_m_d (d_dd_fcn f, const Matrix& x, double y) |
649
|
142 { |
5275
|
143 octave_idx_type nr = x.rows (); |
|
144 octave_idx_type nc = x.columns (); |
649
|
145 |
|
146 Matrix retval (nr, nc); |
|
147 |
5275
|
148 for (octave_idx_type j = 0; j < nc; j++) |
|
149 for (octave_idx_type i = 0; i < nr; i++) |
4153
|
150 { |
|
151 OCTAVE_QUIT; |
|
152 retval (i, j) = f (x (i, j), y); |
|
153 } |
649
|
154 |
|
155 return retval; |
|
156 } |
|
157 |
|
158 static Matrix |
2672
|
159 map_m_m (d_dd_fcn f, const Matrix& x, const Matrix& y) |
649
|
160 { |
5275
|
161 octave_idx_type x_nr = x.rows (); |
|
162 octave_idx_type x_nc = x.columns (); |
649
|
163 |
5275
|
164 octave_idx_type y_nr = y.rows (); |
|
165 octave_idx_type y_nc = y.columns (); |
649
|
166 |
719
|
167 assert (x_nr == y_nr && x_nc == y_nc); |
649
|
168 |
|
169 Matrix retval (x_nr, x_nc); |
|
170 |
5275
|
171 for (octave_idx_type j = 0; j < x_nc; j++) |
|
172 for (octave_idx_type i = 0; i < x_nr; i++) |
4153
|
173 { |
|
174 OCTAVE_QUIT; |
|
175 retval (i, j) = f (x (i, j), y (i, j)); |
|
176 } |
649
|
177 |
|
178 return retval; |
|
179 } |
|
180 |
1957
|
181 DEFUN (atan2, args, , |
3428
|
182 "-*- texinfo -*-\n\ |
|
183 @deftypefn {Mapping Function} {} atan2 (@var{y}, @var{x})\n\ |
|
184 Compute atan (@var{y} / @var{x}) for corresponding elements of @var{y}\n\ |
|
185 and @var{x}. The result is in range -pi to pi.\n\ |
3439
|
186 @end deftypefn") |
649
|
187 { |
4233
|
188 octave_value retval; |
649
|
189 |
712
|
190 int nargin = args.length (); |
|
191 |
|
192 if (nargin == 2 && args(0).is_defined () && args(1).is_defined ()) |
649
|
193 { |
2086
|
194 octave_value arg_y = args(0); |
|
195 octave_value arg_x = args(1); |
649
|
196 |
5275
|
197 octave_idx_type y_nr = arg_y.rows (); |
|
198 octave_idx_type y_nc = arg_y.columns (); |
649
|
199 |
5275
|
200 octave_idx_type x_nr = arg_x.rows (); |
|
201 octave_idx_type x_nc = arg_x.columns (); |
649
|
202 |
|
203 int arg_y_empty = empty_arg ("atan2", y_nr, y_nc); |
|
204 int arg_x_empty = empty_arg ("atan2", x_nr, x_nc); |
|
205 |
719
|
206 if (arg_y_empty > 0 && arg_x_empty > 0) |
4233
|
207 return octave_value (Matrix ()); |
719
|
208 else if (arg_y_empty || arg_x_empty) |
649
|
209 return retval; |
|
210 |
5275
|
211 octave_idx_type y_is_scalar = (y_nr == 1 && y_nc == 1); |
|
212 octave_idx_type x_is_scalar = (x_nr == 1 && x_nc == 1); |
649
|
213 |
|
214 if (y_is_scalar && x_is_scalar) |
|
215 { |
|
216 double y = arg_y.double_value (); |
|
217 |
|
218 if (! error_state) |
|
219 { |
|
220 double x = arg_x.double_value (); |
|
221 |
|
222 if (! error_state) |
|
223 retval = atan2 (y, x); |
|
224 } |
|
225 } |
|
226 else if (y_is_scalar) |
|
227 { |
|
228 double y = arg_y.double_value (); |
|
229 |
|
230 if (! error_state) |
|
231 { |
|
232 Matrix x = arg_x.matrix_value (); |
|
233 |
|
234 if (! error_state) |
2672
|
235 retval = map_d_m (atan2, y, x); |
649
|
236 } |
|
237 } |
|
238 else if (x_is_scalar) |
|
239 { |
|
240 Matrix y = arg_y.matrix_value (); |
|
241 |
|
242 if (! error_state) |
|
243 { |
|
244 double x = arg_x.double_value (); |
|
245 |
|
246 if (! error_state) |
2672
|
247 retval = map_m_d (atan2, y, x); |
649
|
248 } |
|
249 } |
|
250 else if (y_nr == x_nr && y_nc == x_nc) |
|
251 { |
|
252 Matrix y = arg_y.matrix_value (); |
|
253 |
|
254 if (! error_state) |
|
255 { |
|
256 Matrix x = arg_x.matrix_value (); |
|
257 |
|
258 if (! error_state) |
2672
|
259 retval = map_m_m (atan2, y, x); |
649
|
260 } |
|
261 } |
|
262 else |
|
263 error ("atan2: nonconformant matrices"); |
|
264 } |
712
|
265 else |
5823
|
266 print_usage (); |
649
|
267 |
|
268 return retval; |
|
269 } |
|
270 |
4311
|
271 DEFUN (fmod, args, , |
|
272 "-*- texinfo -*-\n\ |
|
273 @deftypefn {Mapping Function} {} fmod (@var{x}, @var{y})\n\ |
4685
|
274 Compute the floating point remainder of dividing @var{x} by @var{y}\n\ |
|
275 using the C library function @code{fmod}. The result has the same\n\ |
|
276 sign as @var{x}. If @var{y} is zero, the result implementation-defined.\n\ |
4311
|
277 @end deftypefn") |
|
278 { |
|
279 octave_value retval; |
|
280 |
|
281 int nargin = args.length (); |
|
282 |
|
283 if (nargin == 2 && args(0).is_defined () && args(1).is_defined ()) |
|
284 { |
|
285 octave_value arg_x = args(0); |
|
286 octave_value arg_y = args(1); |
|
287 |
5275
|
288 octave_idx_type y_nr = arg_y.rows (); |
|
289 octave_idx_type y_nc = arg_y.columns (); |
4311
|
290 |
5275
|
291 octave_idx_type x_nr = arg_x.rows (); |
|
292 octave_idx_type x_nc = arg_x.columns (); |
4311
|
293 |
|
294 int arg_y_empty = empty_arg ("fmod", y_nr, y_nc); |
|
295 int arg_x_empty = empty_arg ("fmod", x_nr, x_nc); |
|
296 |
|
297 if (arg_y_empty > 0 && arg_x_empty > 0) |
|
298 return octave_value (Matrix ()); |
|
299 else if (arg_y_empty || arg_x_empty) |
|
300 return retval; |
|
301 |
5275
|
302 octave_idx_type y_is_scalar = (y_nr == 1 && y_nc == 1); |
|
303 octave_idx_type x_is_scalar = (x_nr == 1 && x_nc == 1); |
4311
|
304 |
|
305 if (y_is_scalar && x_is_scalar) |
|
306 { |
|
307 double y = arg_y.double_value (); |
|
308 |
|
309 if (! error_state) |
|
310 { |
|
311 double x = arg_x.double_value (); |
|
312 |
|
313 if (! error_state) |
|
314 retval = fmod (x, y); |
|
315 } |
|
316 } |
|
317 else if (y_is_scalar) |
|
318 { |
|
319 double y = arg_y.double_value (); |
|
320 |
|
321 if (! error_state) |
|
322 { |
|
323 Matrix x = arg_x.matrix_value (); |
|
324 |
|
325 if (! error_state) |
|
326 retval = map_m_d (fmod, x, y); |
|
327 } |
|
328 } |
|
329 else if (x_is_scalar) |
|
330 { |
|
331 Matrix y = arg_y.matrix_value (); |
|
332 |
|
333 if (! error_state) |
|
334 { |
|
335 double x = arg_x.double_value (); |
|
336 |
|
337 if (! error_state) |
|
338 retval = map_d_m (fmod, x, y); |
|
339 } |
|
340 } |
|
341 else if (y_nr == x_nr && y_nc == x_nc) |
|
342 { |
|
343 Matrix y = arg_y.matrix_value (); |
|
344 |
|
345 if (! error_state) |
|
346 { |
|
347 Matrix x = arg_x.matrix_value (); |
|
348 |
|
349 if (! error_state) |
|
350 retval = map_m_m (fmod, x, y); |
|
351 } |
|
352 } |
|
353 else |
|
354 error ("fmod: nonconformant matrices"); |
|
355 } |
|
356 else |
5823
|
357 print_usage (); |
4311
|
358 |
|
359 return retval; |
|
360 } |
|
361 |
3723
|
362 #define DATA_REDUCTION(FCN) \ |
|
363 \ |
4233
|
364 octave_value retval; \ |
3723
|
365 \ |
|
366 int nargin = args.length (); \ |
|
367 \ |
|
368 if (nargin == 1 || nargin == 2) \ |
|
369 { \ |
|
370 octave_value arg = args(0); \ |
|
371 \ |
3864
|
372 int dim = (nargin == 1 ? -1 : args(1).int_value (true) - 1); \ |
3723
|
373 \ |
|
374 if (! error_state) \ |
|
375 { \ |
4556
|
376 if (dim >= -1) \ |
3723
|
377 { \ |
|
378 if (arg.is_real_type ()) \ |
|
379 { \ |
4569
|
380 NDArray tmp = arg.array_value (); \ |
3723
|
381 \ |
|
382 if (! error_state) \ |
4233
|
383 retval = tmp.FCN (dim); \ |
3723
|
384 } \ |
|
385 else if (arg.is_complex_type ()) \ |
|
386 { \ |
4569
|
387 ComplexNDArray tmp = arg.complex_array_value (); \ |
3723
|
388 \ |
|
389 if (! error_state) \ |
4233
|
390 retval = tmp.FCN (dim); \ |
3723
|
391 } \ |
|
392 else \ |
|
393 { \ |
|
394 gripe_wrong_type_arg (#FCN, arg); \ |
|
395 return retval; \ |
|
396 } \ |
|
397 } \ |
|
398 else \ |
|
399 error (#FCN ": invalid dimension argument = %d", dim + 1); \ |
|
400 } \ |
|
401 } \ |
|
402 else \ |
5823
|
403 print_usage (); \ |
3723
|
404 \ |
|
405 return retval |
|
406 |
1957
|
407 DEFUN (cumprod, args, , |
3428
|
408 "-*- texinfo -*-\n\ |
3723
|
409 @deftypefn {Built-in Function} {} cumprod (@var{x}, @var{dim})\n\ |
|
410 Cumulative product of elements along dimension @var{dim}. If\n\ |
|
411 @var{dim} is omitted, it defaults to 1 (column-wise cumulative\n\ |
|
412 products).\n\ |
5061
|
413 \n\ |
|
414 As a special case, if @var{x} is a vector and @var{dim} is omitted,\n\ |
|
415 return the cumulative product of the elements as a vector with the\n\ |
|
416 same orientation as @var{x}.\n\ |
3428
|
417 @end deftypefn") |
523
|
418 { |
3723
|
419 DATA_REDUCTION (cumprod); |
523
|
420 } |
|
421 |
1957
|
422 DEFUN (cumsum, args, , |
3428
|
423 "-*- texinfo -*-\n\ |
3723
|
424 @deftypefn {Built-in Function} {} cumsum (@var{x}, @var{dim})\n\ |
|
425 Cumulative sum of elements along dimension @var{dim}. If @var{dim}\n\ |
|
426 is omitted, it defaults to 1 (column-wise cumulative sums).\n\ |
5061
|
427 \n\ |
|
428 As a special case, if @var{x} is a vector and @var{dim} is omitted,\n\ |
|
429 return the cumulative sum of the elements as a vector with the\n\ |
|
430 same orientation as @var{x}.\n\ |
3428
|
431 @end deftypefn") |
523
|
432 { |
3723
|
433 DATA_REDUCTION (cumsum); |
523
|
434 } |
|
435 |
6979
|
436 template <class T> |
2086
|
437 static octave_value |
6979
|
438 make_diag (const T& v, octave_idx_type k) |
767
|
439 { |
2086
|
440 octave_value retval; |
6979
|
441 dim_vector dv = v.dims (); |
|
442 octave_idx_type nd = dv.length (); |
|
443 |
|
444 if (nd > 2) |
|
445 error ("diag: expecting 2-dimensional matrix"); |
767
|
446 else |
|
447 { |
6979
|
448 octave_idx_type nr = dv (0); |
|
449 octave_idx_type nc = dv (1); |
|
450 |
|
451 if (nr == 0 || nc == 0) |
|
452 retval = T (); |
|
453 else if (nr != 1 && nc != 1) |
|
454 retval = v.diag (k); |
|
455 else |
|
456 { |
|
457 octave_idx_type roff = 0; |
|
458 octave_idx_type coff = 0; |
|
459 if (k > 0) |
|
460 { |
|
461 roff = 0; |
|
462 coff = k; |
|
463 } |
|
464 else if (k < 0) |
|
465 { |
|
466 roff = -k; |
|
467 coff = 0; |
|
468 } |
|
469 |
|
470 if (nr == 1) |
|
471 { |
|
472 octave_idx_type n = nc + std::abs (k); |
|
473 T m (dim_vector (n, n), T::resize_fill_value ()); |
|
474 |
|
475 for (octave_idx_type i = 0; i < nc; i++) |
|
476 m (i+roff, i+coff) = v (0, i); |
|
477 retval = m; |
|
478 } |
|
479 else |
|
480 { |
|
481 octave_idx_type n = nr + std::abs (k); |
|
482 T m (dim_vector (n, n), T::resize_fill_value ()); |
|
483 for (octave_idx_type i = 0; i < nr; i++) |
|
484 m (i+roff, i+coff) = v (i, 0); |
|
485 retval = m; |
|
486 } |
|
487 } |
767
|
488 } |
6979
|
489 |
767
|
490 return retval; |
|
491 } |
|
492 |
6979
|
493 #if !defined (CXX_NEW_FRIEND_TEMPLATE_DECL) |
|
494 static octave_value |
|
495 make_diag (const Matrix& v, octave_idx_type k); |
|
496 |
|
497 static octave_value |
|
498 make_diag (const ComplexMatrix& v, octave_idx_type k); |
|
499 |
|
500 static octave_value |
|
501 make_diag (const charMatrix& v, octave_idx_type k); |
|
502 |
|
503 static octave_value |
|
504 make_diag (const boolMatrix& v, octave_idx_type k); |
|
505 |
|
506 static octave_value |
|
507 make_diag (const int8NDArray& v, octave_idx_type k); |
|
508 |
|
509 static octave_value |
|
510 make_diag (const int16NDArray& v, octave_idx_type k); |
|
511 |
|
512 static octave_value |
|
513 make_diag (const int32NDArray& v, octave_idx_type k); |
|
514 |
|
515 static octave_value |
|
516 make_diag (const int64NDArray& v, octave_idx_type k); |
|
517 |
2086
|
518 static octave_value |
6979
|
519 make_diag (const uint8NDArray& v, octave_idx_type k); |
|
520 |
|
521 static octave_value |
|
522 make_diag (const uint16NDArray& v, octave_idx_type k); |
|
523 |
|
524 static octave_value |
|
525 make_diag (const uint32NDArray& v, octave_idx_type k); |
|
526 |
|
527 static octave_value |
|
528 make_diag (const uint64NDArray& v, octave_idx_type k); |
|
529 #endif |
|
530 |
|
531 static octave_value |
|
532 make_diag (const octave_value& a, octave_idx_type k) |
767
|
533 { |
2086
|
534 octave_value retval; |
6979
|
535 std::string result_type = a.class_name (); |
|
536 |
|
537 if (result_type == "double") |
767
|
538 { |
6979
|
539 if (a.is_real_type ()) |
|
540 { |
|
541 Matrix m = a.matrix_value (); |
|
542 if (!error_state) |
|
543 retval = make_diag (m, k); |
|
544 } |
|
545 else |
|
546 { |
|
547 ComplexMatrix m = a.complex_matrix_value (); |
|
548 if (!error_state) |
|
549 retval = make_diag (m, k); |
|
550 } |
767
|
551 } |
6979
|
552 #if 0 |
|
553 else if (result_type == "single") |
|
554 retval = make_diag (a.single_array_value (), k); |
|
555 #endif |
|
556 else if (result_type == "char") |
767
|
557 { |
6979
|
558 charMatrix m = a.char_matrix_value (); |
|
559 if (!error_state) |
|
560 { |
|
561 retval = make_diag (m, k); |
|
562 if (a.is_sq_string ()) |
|
563 retval = octave_value (retval.char_array_value (), true, '\''); |
|
564 } |
|
565 } |
|
566 else if (result_type == "logical") |
|
567 { |
|
568 boolMatrix m = a.bool_matrix_value (); |
|
569 if (!error_state) |
|
570 retval = make_diag (m, k); |
767
|
571 } |
6979
|
572 else if (result_type == "int8") |
|
573 retval = make_diag (a.int8_array_value (), k); |
|
574 else if (result_type == "int16") |
|
575 retval = make_diag (a.int16_array_value (), k); |
|
576 else if (result_type == "int32") |
|
577 retval = make_diag (a.int32_array_value (), k); |
|
578 else if (result_type == "int64") |
|
579 retval = make_diag (a.int64_array_value (), k); |
|
580 else if (result_type == "uint8") |
|
581 retval = make_diag (a.uint8_array_value (), k); |
|
582 else if (result_type == "uint16") |
|
583 retval = make_diag (a.uint16_array_value (), k); |
|
584 else if (result_type == "uint32") |
|
585 retval = make_diag (a.uint32_array_value (), k); |
|
586 else if (result_type == "uint64") |
|
587 retval = make_diag (a.uint64_array_value (), k); |
767
|
588 else |
6979
|
589 gripe_wrong_type_arg ("diag", a); |
767
|
590 |
|
591 return retval; |
|
592 } |
|
593 |
2086
|
594 static octave_value |
|
595 make_diag (const octave_value& arg) |
767
|
596 { |
6979
|
597 return make_diag (arg, 0); |
767
|
598 } |
|
599 |
2086
|
600 static octave_value |
|
601 make_diag (const octave_value& a, const octave_value& b) |
767
|
602 { |
2086
|
603 octave_value retval; |
767
|
604 |
5275
|
605 octave_idx_type k = b.int_value (); |
767
|
606 |
|
607 if (error_state) |
6979
|
608 error ("diag: invalid second argument"); |
767
|
609 else |
6979
|
610 retval = make_diag (a, k); |
767
|
611 |
|
612 return retval; |
|
613 } |
|
614 |
1957
|
615 DEFUN (diag, args, , |
3369
|
616 "-*- texinfo -*-\n\ |
|
617 @deftypefn {Built-in Function} {} diag (@var{v}, @var{k})\n\ |
|
618 Return a diagonal matrix with vector @var{v} on diagonal @var{k}. The\n\ |
|
619 second argument is optional. If it is positive, the vector is placed on\n\ |
|
620 the @var{k}-th super-diagonal. If it is negative, it is placed on the\n\ |
|
621 @var{-k}-th sub-diagonal. The default value of @var{k} is 0, and the\n\ |
|
622 vector is placed on the main diagonal. For example,\n\ |
|
623 \n\ |
|
624 @example\n\ |
|
625 @group\n\ |
|
626 diag ([1, 2, 3], 1)\n\ |
|
627 @result{} 0 1 0 0\n\ |
|
628 0 0 2 0\n\ |
|
629 0 0 0 3\n\ |
|
630 0 0 0 0\n\ |
|
631 @end group\n\ |
|
632 @end example\n\ |
6772
|
633 \n\ |
|
634 @noindent\n\ |
|
635 Given a matrix argument, instead of a vector, @code{diag} extracts the\n\ |
6774
|
636 @var{k}-th diagonal of the matrix.\n\ |
3369
|
637 @end deftypefn") |
523
|
638 { |
4233
|
639 octave_value retval; |
523
|
640 |
|
641 int nargin = args.length (); |
|
642 |
712
|
643 if (nargin == 1 && args(0).is_defined ()) |
767
|
644 retval = make_diag (args(0)); |
712
|
645 else if (nargin == 2 && args(0).is_defined () && args(1).is_defined ()) |
767
|
646 retval = make_diag (args(0), args(1)); |
523
|
647 else |
5823
|
648 print_usage (); |
523
|
649 |
|
650 return retval; |
|
651 } |
|
652 |
1957
|
653 DEFUN (prod, args, , |
3428
|
654 "-*- texinfo -*-\n\ |
3723
|
655 @deftypefn {Built-in Function} {} prod (@var{x}, @var{dim})\n\ |
|
656 Product of elements along dimension @var{dim}. If @var{dim} is\n\ |
|
657 omitted, it defaults to 1 (column-wise products).\n\ |
5061
|
658 \n\ |
|
659 As a special case, if @var{x} is a vector and @var{dim} is omitted,\n\ |
|
660 return the product of the elements.\n\ |
3428
|
661 @end deftypefn") |
523
|
662 { |
3723
|
663 DATA_REDUCTION (prod); |
523
|
664 } |
|
665 |
4824
|
666 static octave_value |
|
667 do_cat (const octave_value_list& args, std::string fname) |
4806
|
668 { |
|
669 octave_value retval; |
|
670 |
4824
|
671 int n_args = args.length (); |
4806
|
672 |
5714
|
673 if (n_args == 1) |
|
674 retval = Matrix (); |
|
675 else if (n_args == 2) |
|
676 retval = args(1); |
5507
|
677 else if (n_args > 2) |
4824
|
678 { |
5275
|
679 octave_idx_type dim = args(0).int_value () - 1; |
4806
|
680 |
4824
|
681 if (error_state) |
4806
|
682 { |
4824
|
683 error ("cat: expecting first argument to be a integer"); |
4806
|
684 return retval; |
|
685 } |
|
686 |
4824
|
687 if (dim >= 0) |
|
688 { |
4915
|
689 |
|
690 dim_vector dv = args(1).dims (); |
4824
|
691 |
4915
|
692 for (int i = 2; i < args.length (); i++) |
|
693 { |
|
694 // add_dims constructs a dimension vector which holds the |
4824
|
695 // dimensions of the final array after concatenation. |
4806
|
696 |
4915
|
697 if (! dv.concat (args(i).dims (), dim)) |
4806
|
698 { |
4824
|
699 // Dimensions do not match. |
4915
|
700 error ("cat: dimension mismatch"); |
4806
|
701 return retval; |
|
702 } |
4824
|
703 } |
|
704 |
4915
|
705 // The lines below might seem crazy, since we take a copy |
|
706 // of the first argument, resize it to be empty and then resize |
|
707 // it to be full. This is done since it means that there is no |
|
708 // recopying of data, as would happen if we used a single resize. |
|
709 // It should be noted that resize operation is also significantly |
|
710 // slower than the do_cat_op function, so it makes sense to have an |
|
711 // empty matrix and copy all data. |
4824
|
712 // |
4915
|
713 // We might also start with a empty octave_value using |
|
714 // tmp = octave_value_typeinfo::lookup_type (args(1).type_name()); |
|
715 // and then directly resize. However, for some types there might be |
|
716 // some additional setup needed, and so this should be avoided. |
5533
|
717 |
4915
|
718 octave_value tmp; |
5533
|
719 |
6399
|
720 int i; |
|
721 for (i = 1; i < n_args; i++) |
5533
|
722 { |
|
723 if (! args (i).all_zero_dims ()) |
|
724 { |
|
725 tmp = args (i); |
|
726 break; |
|
727 } |
|
728 } |
5164
|
729 |
6401
|
730 if (i == n_args) |
|
731 retval = Matrix (); |
|
732 else |
4915
|
733 { |
6401
|
734 tmp = tmp.resize (dim_vector (0,0)).resize (dv); |
4824
|
735 |
4915
|
736 if (error_state) |
|
737 return retval; |
4806
|
738 |
6883
|
739 int dv_len = dv.length (); |
|
740 Array<octave_idx_type> ra_idx (dv_len, 0); |
6401
|
741 |
|
742 for (int j = i; j < n_args; j++) |
|
743 { |
6887
|
744 if (args (j). dims (). any_zero ()) |
6883
|
745 continue; |
|
746 |
6401
|
747 tmp = do_cat_op (tmp, args (j), ra_idx); |
|
748 |
|
749 if (error_state) |
|
750 return retval; |
|
751 |
|
752 dim_vector dv_tmp = args (j).dims (); |
|
753 |
6883
|
754 if (dim >= dv_len) |
|
755 { |
|
756 if (j > i) |
|
757 error ("%s: indexing error", fname.c_str ()); |
|
758 break; |
|
759 } |
|
760 else |
|
761 ra_idx (dim) += (dim < dv_tmp.length () ? |
|
762 dv_tmp (dim) : 1); |
6401
|
763 } |
|
764 |
|
765 retval = tmp; |
4915
|
766 } |
4806
|
767 } |
5533
|
768 else |
|
769 error ("%s: invalid dimension argument", fname.c_str ()); |
4806
|
770 } |
|
771 else |
5823
|
772 print_usage (); |
4806
|
773 |
|
774 return retval; |
|
775 } |
|
776 |
|
777 DEFUN (horzcat, args, , |
4824
|
778 "-*- texinfo -*-\n\ |
4806
|
779 @deftypefn {Built-in Function} {} horzcat (@var{array1}, @var{array2}, @dots{}, @var{arrayN})\n\ |
|
780 Return the horizontal concatenation of N-d array objects, @var{array1},\n\ |
|
781 @var{array2}, @dots{}, @var{arrayN} along dimension 2.\n\ |
5642
|
782 @seealso{cat, vertcat}\n\ |
|
783 @end deftypefn") |
4806
|
784 { |
|
785 octave_value_list args_tmp = args; |
|
786 |
|
787 int dim = 2; |
|
788 |
|
789 octave_value d (dim); |
|
790 |
|
791 args_tmp.prepend (d); |
|
792 |
4824
|
793 return do_cat (args_tmp, "horzcat"); |
4806
|
794 } |
|
795 |
|
796 DEFUN (vertcat, args, , |
|
797 "-*- texinfo -*-\n\ |
|
798 @deftypefn {Built-in Function} {} vertcat (@var{array1}, @var{array2}, @dots{}, @var{arrayN})\n\ |
|
799 Return the vertical concatenation of N-d array objects, @var{array1},\n\ |
|
800 @var{array2}, @dots{}, @var{arrayN} along dimension 1.\n\ |
5642
|
801 @seealso{cat, horzcat}\n\ |
|
802 @end deftypefn") |
4806
|
803 { |
|
804 octave_value_list args_tmp = args; |
|
805 |
|
806 int dim = 1; |
|
807 |
|
808 octave_value d (dim); |
|
809 |
|
810 args_tmp.prepend (d); |
|
811 |
4824
|
812 return do_cat (args_tmp, "vertcat"); |
4806
|
813 } |
|
814 |
4758
|
815 DEFUN (cat, args, , |
|
816 "-*- texinfo -*-\n\ |
|
817 @deftypefn {Built-in Function} {} cat (@var{dim}, @var{array1}, @var{array2}, @dots{}, @var{arrayN})\n\ |
4806
|
818 Return the concatenation of N-d array objects, @var{array1},\n\ |
|
819 @var{array2}, @dots{}, @var{arrayN} along dimension @var{dim}.\n\ |
4758
|
820 \n\ |
|
821 @example\n\ |
|
822 @group\n\ |
|
823 A = ones (2, 2);\n\ |
|
824 B = zeros (2, 2);\n\ |
|
825 cat (2, A, B)\n\ |
|
826 @result{} ans =\n\ |
|
827 \n\ |
|
828 1 1 0 0\n\ |
|
829 1 1 0 0\n\ |
|
830 @end group\n\ |
|
831 @end example\n\ |
|
832 \n\ |
|
833 Alternatively, we can concatenate @var{A} and @var{B} along the\n\ |
|
834 second dimension the following way:\n\ |
|
835 \n\ |
|
836 @example\n\ |
|
837 @group\n\ |
|
838 [A, B].\n\ |
|
839 @end group\n\ |
|
840 @end example\n\ |
|
841 \n\ |
|
842 @var{dim} can be larger than the dimensions of the N-d array objects\n\ |
|
843 and the result will thus have @var{dim} dimensions as the\n\ |
|
844 following example shows:\n\ |
|
845 @example\n\ |
|
846 @group\n\ |
|
847 cat (4, ones(2, 2), zeros (2, 2))\n\ |
|
848 @result{} ans =\n\ |
|
849 \n\ |
|
850 ans(:,:,1,1) =\n\ |
|
851 \n\ |
|
852 1 1\n\ |
|
853 1 1\n\ |
|
854 \n\ |
|
855 ans(:,:,1,2) =\n\ |
|
856 0 0\n\ |
|
857 0 0\n\ |
|
858 @end group\n\ |
|
859 @end example\n\ |
5642
|
860 @seealso{horzcat, vertcat}\n\ |
|
861 @end deftypefn") |
4758
|
862 { |
4824
|
863 return do_cat (args, "cat"); |
4758
|
864 } |
|
865 |
4593
|
866 static octave_value |
6959
|
867 do_permute (const octave_value_list& args, bool inv) |
4593
|
868 { |
|
869 octave_value retval; |
|
870 |
5148
|
871 if (args.length () == 2 && args(1).length () >= args(1).ndims ()) |
4593
|
872 { |
|
873 Array<int> vec = args(1).int_vector_value (); |
|
874 |
5775
|
875 // FIXME -- maybe we should create an idx_vector object |
5148
|
876 // here and pass that to permute? |
|
877 |
|
878 int n = vec.length (); |
|
879 |
|
880 for (int i = 0; i < n; i++) |
|
881 vec(i)--; |
|
882 |
4593
|
883 octave_value ret = args(0).permute (vec, inv); |
|
884 |
|
885 if (! error_state) |
|
886 retval = ret; |
|
887 } |
|
888 else |
5823
|
889 print_usage (); |
4593
|
890 |
|
891 return retval; |
|
892 } |
|
893 |
|
894 DEFUN (permute, args, , |
|
895 "-*- texinfo -*-\n\ |
|
896 @deftypefn {Built-in Function} {} permute (@var{a}, @var{perm})\n\ |
|
897 Return the generalized transpose for an N-d array object @var{a}.\n\ |
|
898 The permutation vector @var{perm} must contain the elements\n\ |
|
899 @code{1:ndims(a)} (in any order, but each element must appear just once).\n\ |
5642
|
900 @seealso{ipermute}\n\ |
|
901 @end deftypefn") |
4593
|
902 { |
6959
|
903 return do_permute (args, false); |
4593
|
904 } |
|
905 |
|
906 DEFUN (ipermute, args, , |
|
907 "-*- texinfo -*-\n\ |
|
908 @deftypefn {Built-in Function} {} ipermute (@var{a}, @var{iperm})\n\ |
|
909 The inverse of the @code{permute} function. The expression\n\ |
|
910 \n\ |
|
911 @example\n\ |
|
912 ipermute (permute (a, perm), perm)\n\ |
|
913 @end example\n\ |
|
914 returns the original array @var{a}.\n\ |
5642
|
915 @seealso{permute}\n\ |
|
916 @end deftypefn") |
4593
|
917 { |
6959
|
918 return do_permute (args, true); |
4593
|
919 } |
|
920 |
3195
|
921 DEFUN (length, args, , |
3373
|
922 "-*- texinfo -*-\n\ |
|
923 @deftypefn {Built-in Function} {} length (@var{a})\n\ |
4176
|
924 Return the `length' of the object @var{a}. For matrix objects, the\n\ |
3373
|
925 length is the number of rows or columns, whichever is greater (this\n\ |
6556
|
926 odd definition is used for compatibility with @sc{Matlab}).\n\ |
3373
|
927 @end deftypefn") |
3195
|
928 { |
|
929 octave_value retval; |
|
930 |
|
931 if (args.length () == 1) |
|
932 { |
|
933 int len = args(0).length (); |
|
934 |
|
935 if (! error_state) |
4233
|
936 retval = len; |
3195
|
937 } |
|
938 else |
5823
|
939 print_usage (); |
3195
|
940 |
|
941 return retval; |
|
942 } |
|
943 |
4554
|
944 DEFUN (ndims, args, , |
|
945 "-*- texinfo -*-\n\ |
|
946 @deftypefn {Built-in Function} {} ndims (@var{a})\n\ |
|
947 Returns the number of dimensions of array @var{a}.\n\ |
|
948 For any array, the result will always be larger than or equal to 2.\n\ |
|
949 Trailing singleton dimensions are not counted.\n\ |
|
950 @end deftypefn") |
|
951 { |
|
952 octave_value retval; |
|
953 |
|
954 if (args.length () == 1) |
|
955 { |
|
956 int n_dims = args(0).ndims (); |
|
957 |
|
958 if (! error_state) |
|
959 retval = n_dims; |
|
960 } |
|
961 else |
5823
|
962 print_usage (); |
4554
|
963 |
|
964 return retval; |
|
965 } |
|
966 |
4559
|
967 DEFUN (numel, args, , |
|
968 "-*- texinfo -*-\n\ |
|
969 @deftypefn {Built-in Function} {} numel (@var{a})\n\ |
|
970 Returns the number of elements in the object @var{a}.\n\ |
5724
|
971 @seealso{size}\n\ |
4559
|
972 @end deftypefn") |
|
973 { |
|
974 octave_value retval; |
|
975 |
|
976 if (args.length () == 1) |
|
977 { |
|
978 int numel = args(0).numel (); |
|
979 |
|
980 if (! error_state) |
|
981 { |
|
982 if (numel < 0) |
|
983 numel = 0; |
|
984 |
|
985 retval = numel; |
|
986 } |
|
987 } |
|
988 else |
5823
|
989 print_usage (); |
4559
|
990 |
|
991 return retval; |
|
992 } |
|
993 |
1957
|
994 DEFUN (size, args, nargout, |
3373
|
995 "-*- texinfo -*-\n\ |
|
996 @deftypefn {Built-in Function} {} size (@var{a}, @var{n})\n\ |
|
997 Return the number rows and columns of @var{a}.\n\ |
|
998 \n\ |
|
999 With one input argument and one output argument, the result is returned\n\ |
4741
|
1000 in a row vector. If there are multiple output arguments, the number of\n\ |
|
1001 rows is assigned to the first, and the number of columns to the second,\n\ |
|
1002 etc. For example,\n\ |
3373
|
1003 \n\ |
|
1004 @example\n\ |
|
1005 @group\n\ |
|
1006 size ([1, 2; 3, 4; 5, 6])\n\ |
|
1007 @result{} [ 3, 2 ]\n\ |
1031
|
1008 \n\ |
3373
|
1009 [nr, nc] = size ([1, 2; 3, 4; 5, 6])\n\ |
|
1010 @result{} nr = 3\n\ |
|
1011 @result{} nc = 2\n\ |
|
1012 @end group\n\ |
|
1013 @end example\n\ |
|
1014 \n\ |
4741
|
1015 If given a second argument, @code{size} will return the size of the\n\ |
|
1016 corresponding dimension. For example\n\ |
1031
|
1017 \n\ |
3373
|
1018 @example\n\ |
|
1019 size ([1, 2; 3, 4; 5, 6], 2)\n\ |
|
1020 @result{} 2\n\ |
|
1021 @end example\n\ |
|
1022 \n\ |
|
1023 @noindent\n\ |
|
1024 returns the number of columns in the given matrix.\n\ |
5724
|
1025 @seealso{numel}\n\ |
3373
|
1026 @end deftypefn") |
523
|
1027 { |
2086
|
1028 octave_value_list retval; |
523
|
1029 |
|
1030 int nargin = args.length (); |
|
1031 |
4513
|
1032 if (nargin == 1) |
523
|
1033 { |
4513
|
1034 dim_vector dimensions = args(0).dims (); |
|
1035 |
|
1036 int ndims = dimensions.length (); |
1031
|
1037 |
4513
|
1038 Matrix m (1, ndims); |
|
1039 |
|
1040 if (nargout > 1) |
523
|
1041 { |
5991
|
1042 for (int i = nargout-1; i >= ndims; i--) |
|
1043 retval(i) = 1; |
|
1044 |
6197
|
1045 if (ndims > nargout) |
|
1046 { |
|
1047 octave_idx_type d = 1; |
|
1048 |
|
1049 while (ndims >= nargout) |
|
1050 d *= dimensions(--ndims); |
|
1051 |
|
1052 retval(ndims) = d; |
|
1053 } |
|
1054 |
4513
|
1055 while (ndims--) |
|
1056 retval(ndims) = dimensions(ndims); |
523
|
1057 } |
4513
|
1058 else |
712
|
1059 { |
4513
|
1060 for (int i = 0; i < ndims; i++) |
|
1061 m(0, i) = dimensions(i); |
|
1062 |
|
1063 retval(0) = m; |
712
|
1064 } |
1031
|
1065 } |
|
1066 else if (nargin == 2 && nargout < 2) |
|
1067 { |
5275
|
1068 octave_idx_type nd = args(1).int_value (true); |
1031
|
1069 |
|
1070 if (error_state) |
|
1071 error ("size: expecting scalar as second argument"); |
712
|
1072 else |
1031
|
1073 { |
4741
|
1074 dim_vector dv = args(0).dims (); |
|
1075 |
4911
|
1076 if (nd > 0) |
|
1077 { |
|
1078 if (nd <= dv.length ()) |
|
1079 retval(0) = dv(nd-1); |
|
1080 else |
|
1081 retval(0) = 1; |
|
1082 } |
1031
|
1083 else |
4741
|
1084 error ("size: requested dimension (= %d) out of range", nd); |
1031
|
1085 } |
523
|
1086 } |
712
|
1087 else |
5823
|
1088 print_usage (); |
523
|
1089 |
|
1090 return retval; |
|
1091 } |
|
1092 |
6156
|
1093 DEFUN (size_equal, args, , |
|
1094 "-*- texinfo -*-\n\ |
6561
|
1095 @deftypefn {Built-in Function} {} size_equal (@var{a}, @var{b}, @dots{})\n\ |
|
1096 Return true if the dimensions of all arguments agree.\n\ |
6156
|
1097 Trailing singleton dimensions are ignored.\n\ |
|
1098 @seealso{size, numel}\n\ |
|
1099 @end deftypefn") |
|
1100 { |
|
1101 octave_value retval; |
|
1102 |
6561
|
1103 int nargin = args.length (); |
|
1104 |
|
1105 if (nargin >= 2) |
6156
|
1106 { |
6561
|
1107 retval = true; |
|
1108 |
6156
|
1109 dim_vector a_dims = args(0).dims (); |
|
1110 a_dims.chop_trailing_singletons (); |
6561
|
1111 |
|
1112 for (int i = 1; i < nargin; ++i) |
|
1113 { |
|
1114 dim_vector b_dims = args(i).dims (); |
|
1115 b_dims.chop_trailing_singletons (); |
|
1116 |
|
1117 if (a_dims != b_dims) |
|
1118 { |
|
1119 retval = false; |
|
1120 break; |
|
1121 } |
|
1122 } |
6156
|
1123 } |
|
1124 else |
|
1125 print_usage (); |
|
1126 |
|
1127 return retval; |
|
1128 } |
|
1129 |
5602
|
1130 DEFUN (nnz, args, , |
|
1131 "-*- texinfo -*-\n\ |
6156
|
1132 @deftypefn {Built-in Function} {@var{scalar} =} nnz (@var{a})\n\ |
|
1133 Returns the number of non zero elements in @var{a}.\n\ |
5602
|
1134 @seealso{sparse}\n\ |
|
1135 @end deftypefn") |
|
1136 { |
|
1137 octave_value retval; |
|
1138 |
|
1139 if (args.length () == 1) |
|
1140 retval = args(0).nnz (); |
|
1141 else |
5823
|
1142 print_usage (); |
5602
|
1143 |
|
1144 return retval; |
|
1145 } |
|
1146 |
5604
|
1147 DEFUN (nzmax, args, , |
|
1148 "-*- texinfo -*-\n\ |
6156
|
1149 @deftypefn {Built-in Function} {@var{scalar} =} nzmax (@var{SM})\n\ |
5604
|
1150 Return the amount of storage allocated to the sparse matrix @var{SM}.\n\ |
7001
|
1151 Note that Octave tends to crop unused memory at the first opportunity\n\ |
5604
|
1152 for sparse objects. There are some cases of user created sparse objects\n\ |
|
1153 where the value returned by @dfn{nzmaz} will not be the same as @dfn{nnz},\n\ |
|
1154 but in general they will give the same result.\n\ |
|
1155 @seealso{sparse, spalloc}\n\ |
|
1156 @end deftypefn") |
|
1157 { |
|
1158 octave_value retval; |
|
1159 |
|
1160 if (args.length() == 1) |
|
1161 retval = args(0).nzmax (); |
|
1162 else |
5823
|
1163 print_usage (); |
5604
|
1164 |
|
1165 return retval; |
|
1166 } |
|
1167 |
5677
|
1168 DEFUN (rows, args, , |
|
1169 "-*- texinfo -*-\n\ |
|
1170 @deftypefn {Built-in Function} {} rows (@var{a})\n\ |
|
1171 Return the number of rows of @var{a}.\n\ |
5724
|
1172 @seealso{size, numel, columns, length, isscalar, isvector, ismatrix}\n\ |
5677
|
1173 @end deftypefn") |
|
1174 { |
|
1175 octave_value retval; |
|
1176 |
|
1177 if (args.length () == 1) |
|
1178 retval = args(0).rows (); |
|
1179 else |
5823
|
1180 print_usage (); |
5677
|
1181 |
|
1182 return retval; |
|
1183 } |
|
1184 |
|
1185 DEFUN (columns, args, , |
|
1186 "-*- texinfo -*-\n\ |
|
1187 @deftypefn {Built-in Function} {} columns (@var{a})\n\ |
|
1188 Return the number of columns of @var{a}.\n\ |
5724
|
1189 @seealso{size, numel, rows, length, isscalar, isvector, and ismatrix}\n\ |
5677
|
1190 @end deftypefn") |
|
1191 { |
|
1192 octave_value retval; |
|
1193 |
|
1194 if (args.length () == 1) |
|
1195 retval = args(0).columns (); |
|
1196 else |
5823
|
1197 print_usage (); |
5677
|
1198 |
|
1199 return retval; |
|
1200 } |
|
1201 |
1957
|
1202 DEFUN (sum, args, , |
3428
|
1203 "-*- texinfo -*-\n\ |
3723
|
1204 @deftypefn {Built-in Function} {} sum (@var{x}, @var{dim})\n\ |
|
1205 Sum of elements along dimension @var{dim}. If @var{dim} is\n\ |
|
1206 omitted, it defaults to 1 (column-wise sum).\n\ |
5061
|
1207 \n\ |
|
1208 As a special case, if @var{x} is a vector and @var{dim} is omitted,\n\ |
|
1209 return the sum of the elements.\n\ |
3428
|
1210 @end deftypefn") |
523
|
1211 { |
3723
|
1212 DATA_REDUCTION (sum); |
523
|
1213 } |
|
1214 |
1957
|
1215 DEFUN (sumsq, args, , |
3428
|
1216 "-*- texinfo -*-\n\ |
3723
|
1217 @deftypefn {Built-in Function} {} sumsq (@var{x}, @var{dim})\n\ |
|
1218 Sum of squares of elements along dimension @var{dim}. If @var{dim}\n\ |
|
1219 is omitted, it defaults to 1 (column-wise sum of squares).\n\ |
3095
|
1220 \n\ |
5061
|
1221 As a special case, if @var{x} is a vector and @var{dim} is omitted,\n\ |
|
1222 return the sum of squares of the elements.\n\ |
|
1223 \n\ |
|
1224 This function is conceptually equivalent to computing\n\ |
3723
|
1225 @example\n\ |
|
1226 sum (x .* conj (x), dim)\n\ |
|
1227 @end example\n\ |
|
1228 but it uses less memory and avoids calling conj if @var{x} is real.\n\ |
3428
|
1229 @end deftypefn") |
523
|
1230 { |
3723
|
1231 DATA_REDUCTION (sumsq); |
523
|
1232 } |
|
1233 |
6688
|
1234 DEFUN (islogical, args, , |
3428
|
1235 "-*- texinfo -*-\n\ |
6688
|
1236 @deftypefn {Built-in Functio} {} islogical (@var{x})\n\ |
|
1237 Return true if @var{x} is a logical object.\n\ |
3439
|
1238 @end deftypefn") |
3209
|
1239 { |
|
1240 octave_value retval; |
|
1241 |
|
1242 if (args.length () == 1) |
3258
|
1243 retval = args(0).is_bool_type (); |
3209
|
1244 else |
5823
|
1245 print_usage (); |
3209
|
1246 |
|
1247 return retval; |
|
1248 } |
|
1249 |
6688
|
1250 DEFALIAS (isbool, islogical); |
3209
|
1251 |
6223
|
1252 DEFUN (isinteger, args, , |
|
1253 "-*- texinfo -*-\n\ |
6230
|
1254 @deftypefn {Built-in Function} {} isinteger (@var{x})\n\ |
6223
|
1255 Return true if @var{x} is an integer object (int8, uint8, int16, etc.).\n\ |
|
1256 Note that @code{isinteger (14)} is false because numeric constants in\n\ |
|
1257 are double precision floating point values.\n\ |
|
1258 @seealso{isreal, isnumeric, class, isa}\n\ |
|
1259 @end deftypefn") |
|
1260 { |
|
1261 octave_value retval; |
|
1262 |
|
1263 if (args.length () == 1) |
|
1264 retval = args(0).is_integer_type (); |
|
1265 else |
|
1266 print_usage (); |
|
1267 |
|
1268 return retval; |
|
1269 } |
|
1270 |
4028
|
1271 DEFUN (iscomplex, args, , |
3428
|
1272 "-*- texinfo -*-\n\ |
4028
|
1273 @deftypefn {Built-in Function} {} iscomplex (@var{x})\n\ |
3428
|
1274 Return true if @var{x} is a complex-valued numeric object.\n\ |
|
1275 @end deftypefn") |
3186
|
1276 { |
|
1277 octave_value retval; |
|
1278 |
|
1279 if (args.length () == 1) |
3258
|
1280 retval = args(0).is_complex_type (); |
3186
|
1281 else |
5823
|
1282 print_usage (); |
3186
|
1283 |
|
1284 return retval; |
|
1285 } |
|
1286 |
5775
|
1287 // FIXME -- perhaps this should be implemented with an |
5476
|
1288 // octave_value member function? |
|
1289 |
|
1290 DEFUN (complex, args, , |
|
1291 "-*- texinfo -*-\n\ |
|
1292 @deftypefn {Built-in Function} {} complex (@var{val})\n\ |
|
1293 @deftypefnx {Built-in Function} {} complex (@var{re}, @var{im})\n\ |
|
1294 Convert @var{x} to a complex value.\n\ |
|
1295 @end deftypefn") |
|
1296 { |
|
1297 octave_value retval; |
|
1298 |
|
1299 int nargin = args.length (); |
|
1300 |
|
1301 if (nargin == 1) |
|
1302 { |
|
1303 octave_value arg = args(0); |
|
1304 |
|
1305 if (arg.is_complex_type ()) |
|
1306 retval = arg; |
|
1307 else |
|
1308 { |
|
1309 if (arg.numel () == 1) |
|
1310 { |
|
1311 Complex val = arg.complex_value (); |
|
1312 |
|
1313 if (! error_state) |
|
1314 retval = octave_value (new octave_complex (val)); |
|
1315 } |
|
1316 else |
|
1317 { |
|
1318 ComplexNDArray val = arg.complex_array_value (); |
|
1319 |
|
1320 if (! error_state) |
|
1321 retval = octave_value (new octave_complex_matrix (val)); |
|
1322 } |
|
1323 |
|
1324 if (error_state) |
|
1325 error ("complex: invalid conversion"); |
|
1326 } |
|
1327 } |
|
1328 else if (nargin == 2) |
|
1329 { |
|
1330 octave_value re = args(0); |
|
1331 octave_value im = args(1); |
|
1332 |
|
1333 if (re.numel () == 1) |
|
1334 { |
|
1335 double re_val = re.double_value (); |
|
1336 |
|
1337 if (im.numel () == 1) |
|
1338 { |
|
1339 double im_val = im.double_value (); |
|
1340 |
|
1341 if (! error_state) |
|
1342 retval = octave_value (new octave_complex (Complex (re_val, im_val))); |
|
1343 } |
|
1344 else |
|
1345 { |
|
1346 const NDArray im_val = im.array_value (); |
|
1347 |
|
1348 if (! error_state) |
|
1349 { |
|
1350 ComplexNDArray result (im_val.dims (), Complex ()); |
|
1351 |
|
1352 for (octave_idx_type i = 0; i < im_val.numel (); i++) |
|
1353 result.xelem (i) = Complex (re_val, im_val(i)); |
|
1354 |
|
1355 retval = octave_value (new octave_complex_matrix (result)); |
|
1356 } |
|
1357 } |
|
1358 } |
|
1359 else |
|
1360 { |
|
1361 const NDArray re_val = re.array_value (); |
|
1362 |
|
1363 if (im.numel () == 1) |
|
1364 { |
|
1365 double im_val = im.double_value (); |
|
1366 |
|
1367 if (! error_state) |
|
1368 { |
|
1369 ComplexNDArray result (re_val.dims (), Complex ()); |
|
1370 |
|
1371 for (octave_idx_type i = 0; i < re_val.numel (); i++) |
|
1372 result.xelem (i) = Complex (re_val(i), im_val); |
|
1373 |
|
1374 retval = octave_value (new octave_complex_matrix (result)); |
|
1375 } |
|
1376 } |
|
1377 else |
|
1378 { |
|
1379 const NDArray im_val = im.array_value (); |
|
1380 |
|
1381 if (! error_state) |
|
1382 { |
|
1383 if (re_val.dims () == im_val.dims ()) |
|
1384 { |
|
1385 ComplexNDArray result (re_val.dims (), Complex ()); |
|
1386 |
|
1387 for (octave_idx_type i = 0; i < re_val.numel (); i++) |
|
1388 result.xelem (i) = Complex (re_val(i), im_val(i)); |
|
1389 |
|
1390 retval = octave_value (new octave_complex_matrix (result)); |
|
1391 } |
|
1392 else |
|
1393 error ("complex: dimension mismatch"); |
|
1394 } |
|
1395 } |
|
1396 } |
|
1397 |
|
1398 if (error_state) |
|
1399 error ("complex: invalid conversion"); |
|
1400 } |
|
1401 else |
5823
|
1402 print_usage (); |
5476
|
1403 |
|
1404 return retval; |
|
1405 } |
|
1406 |
3258
|
1407 DEFUN (isreal, args, , |
3428
|
1408 "-*- texinfo -*-\n\ |
|
1409 @deftypefn {Built-in Function} {} isreal (@var{x})\n\ |
|
1410 Return true if @var{x} is a real-valued numeric object.\n\ |
|
1411 @end deftypefn") |
3258
|
1412 { |
|
1413 octave_value retval; |
|
1414 |
|
1415 if (args.length () == 1) |
|
1416 retval = args(0).is_real_type (); |
|
1417 else |
5823
|
1418 print_usage (); |
3258
|
1419 |
|
1420 return retval; |
|
1421 } |
|
1422 |
3202
|
1423 DEFUN (isempty, args, , |
3373
|
1424 "-*- texinfo -*-\n\ |
|
1425 @deftypefn {Built-in Function} {} isempty (@var{a})\n\ |
|
1426 Return 1 if @var{a} is an empty matrix (either the number of rows, or\n\ |
|
1427 the number of columns, or both are zero). Otherwise, return 0.\n\ |
|
1428 @end deftypefn") |
3202
|
1429 { |
4233
|
1430 octave_value retval = false; |
3202
|
1431 |
|
1432 if (args.length () == 1) |
4559
|
1433 retval = args(0).is_empty (); |
3202
|
1434 else |
5823
|
1435 print_usage (); |
3202
|
1436 |
|
1437 return retval; |
|
1438 } |
|
1439 |
3206
|
1440 DEFUN (isnumeric, args, , |
3428
|
1441 "-*- texinfo -*-\n\ |
|
1442 @deftypefn {Built-in Function} {} isnumeric (@var{x})\n\ |
|
1443 Return nonzero if @var{x} is a numeric object.\n\ |
|
1444 @end deftypefn") |
3206
|
1445 { |
|
1446 octave_value retval; |
|
1447 |
|
1448 if (args.length () == 1) |
3258
|
1449 retval = args(0).is_numeric_type (); |
3206
|
1450 else |
5823
|
1451 print_usage (); |
3206
|
1452 |
|
1453 return retval; |
|
1454 } |
|
1455 |
4028
|
1456 DEFUN (islist, args, , |
3526
|
1457 "-*- texinfo -*-\n\ |
4028
|
1458 @deftypefn {Built-in Function} {} islist (@var{x})\n\ |
3428
|
1459 Return nonzero if @var{x} is a list.\n\ |
|
1460 @end deftypefn") |
3204
|
1461 { |
|
1462 octave_value retval; |
|
1463 |
|
1464 if (args.length () == 1) |
3258
|
1465 retval = args(0).is_list (); |
3204
|
1466 else |
5823
|
1467 print_usage (); |
3204
|
1468 |
|
1469 return retval; |
|
1470 } |
|
1471 |
4028
|
1472 DEFUN (ismatrix, args, , |
3321
|
1473 "-*- texinfo -*-\n\ |
4028
|
1474 @deftypefn {Built-in Function} {} ismatrix (@var{a})\n\ |
3321
|
1475 Return 1 if @var{a} is a matrix. Otherwise, return 0.\n\ |
3333
|
1476 @end deftypefn") |
3202
|
1477 { |
4233
|
1478 octave_value retval = false; |
3202
|
1479 |
|
1480 if (args.length () == 1) |
|
1481 { |
|
1482 octave_value arg = args(0); |
|
1483 |
3212
|
1484 if (arg.is_scalar_type () || arg.is_range ()) |
4233
|
1485 retval = true; |
3202
|
1486 else if (arg.is_matrix_type ()) |
4233
|
1487 retval = (arg.rows () >= 1 && arg.columns () >= 1); |
3202
|
1488 } |
|
1489 else |
5823
|
1490 print_usage (); |
3202
|
1491 |
|
1492 return retval; |
|
1493 } |
|
1494 |
3354
|
1495 static octave_value |
5747
|
1496 fill_matrix (const octave_value_list& args, int val, const char *fcn) |
523
|
1497 { |
3354
|
1498 octave_value retval; |
523
|
1499 |
|
1500 int nargin = args.length (); |
|
1501 |
4946
|
1502 oct_data_conv::data_type dt = oct_data_conv::dt_double; |
4481
|
1503 |
4946
|
1504 dim_vector dims (1, 1); |
4481
|
1505 |
|
1506 if (nargin > 0 && args(nargin-1).is_string ()) |
|
1507 { |
4946
|
1508 std::string nm = args(nargin-1).string_value (); |
4481
|
1509 nargin--; |
|
1510 |
4946
|
1511 dt = oct_data_conv::string_to_data_type (nm); |
|
1512 |
|
1513 if (error_state) |
|
1514 return retval; |
4481
|
1515 } |
|
1516 |
523
|
1517 switch (nargin) |
|
1518 { |
712
|
1519 case 0: |
|
1520 break; |
777
|
1521 |
610
|
1522 case 1: |
4481
|
1523 get_dimensions (args(0), fcn, dims); |
610
|
1524 break; |
777
|
1525 |
4563
|
1526 default: |
|
1527 { |
|
1528 dims.resize (nargin); |
4481
|
1529 |
4563
|
1530 for (int i = 0; i < nargin; i++) |
|
1531 { |
6133
|
1532 dims(i) = args(i).is_empty () ? 0 : args(i).idx_type_value (); |
4481
|
1533 |
4563
|
1534 if (error_state) |
|
1535 { |
4732
|
1536 error ("%s: expecting scalar integer arguments", fcn); |
4563
|
1537 break; |
|
1538 } |
|
1539 } |
|
1540 } |
|
1541 break; |
4481
|
1542 } |
|
1543 |
|
1544 if (! error_state) |
|
1545 { |
4946
|
1546 dims.chop_trailing_singletons (); |
4565
|
1547 |
4481
|
1548 check_dimensions (dims, fcn); |
3354
|
1549 |
5775
|
1550 // FIXME -- perhaps this should be made extensible by |
4946
|
1551 // using the class name to lookup a function to call to create |
|
1552 // the new value. |
|
1553 |
|
1554 // Note that automatic narrowing will handle conversion from |
|
1555 // NDArray to scalar. |
|
1556 |
4481
|
1557 if (! error_state) |
|
1558 { |
4946
|
1559 switch (dt) |
|
1560 { |
|
1561 case oct_data_conv::dt_int8: |
|
1562 retval = int8NDArray (dims, val); |
|
1563 break; |
4481
|
1564 |
4946
|
1565 case oct_data_conv::dt_uint8: |
|
1566 retval = uint8NDArray (dims, val); |
|
1567 break; |
|
1568 |
|
1569 case oct_data_conv::dt_int16: |
|
1570 retval = int16NDArray (dims, val); |
|
1571 break; |
|
1572 |
|
1573 case oct_data_conv::dt_uint16: |
|
1574 retval = uint16NDArray (dims, val); |
|
1575 break; |
|
1576 |
|
1577 case oct_data_conv::dt_int32: |
|
1578 retval = int32NDArray (dims, val); |
|
1579 break; |
777
|
1580 |
4946
|
1581 case oct_data_conv::dt_uint32: |
|
1582 retval = uint32NDArray (dims, val); |
|
1583 break; |
|
1584 |
|
1585 case oct_data_conv::dt_int64: |
|
1586 retval = int64NDArray (dims, val); |
|
1587 break; |
4481
|
1588 |
4946
|
1589 case oct_data_conv::dt_uint64: |
|
1590 retval = uint64NDArray (dims, val); |
|
1591 break; |
4481
|
1592 |
5775
|
1593 case oct_data_conv::dt_single: // FIXME |
4946
|
1594 case oct_data_conv::dt_double: |
|
1595 retval = NDArray (dims, val); |
|
1596 break; |
|
1597 |
4986
|
1598 case oct_data_conv::dt_logical: |
|
1599 retval = boolNDArray (dims, val); |
|
1600 break; |
|
1601 |
4946
|
1602 default: |
|
1603 error ("%s: invalid class name", fcn); |
|
1604 break; |
4481
|
1605 } |
|
1606 } |
523
|
1607 } |
|
1608 |
|
1609 return retval; |
|
1610 } |
|
1611 |
5747
|
1612 static octave_value |
|
1613 fill_matrix (const octave_value_list& args, double val, const char *fcn) |
|
1614 { |
|
1615 octave_value retval; |
|
1616 |
|
1617 int nargin = args.length (); |
|
1618 |
|
1619 oct_data_conv::data_type dt = oct_data_conv::dt_double; |
|
1620 |
|
1621 dim_vector dims (1, 1); |
|
1622 |
|
1623 if (nargin > 0 && args(nargin-1).is_string ()) |
|
1624 { |
|
1625 std::string nm = args(nargin-1).string_value (); |
|
1626 nargin--; |
|
1627 |
|
1628 dt = oct_data_conv::string_to_data_type (nm); |
|
1629 |
|
1630 if (error_state) |
|
1631 return retval; |
|
1632 } |
|
1633 |
|
1634 switch (nargin) |
|
1635 { |
|
1636 case 0: |
|
1637 break; |
|
1638 |
|
1639 case 1: |
|
1640 get_dimensions (args(0), fcn, dims); |
|
1641 break; |
|
1642 |
|
1643 default: |
|
1644 { |
|
1645 dims.resize (nargin); |
|
1646 |
|
1647 for (int i = 0; i < nargin; i++) |
|
1648 { |
6133
|
1649 dims(i) = args(i).is_empty () ? 0 : args(i).idx_type_value (); |
5747
|
1650 |
|
1651 if (error_state) |
|
1652 { |
|
1653 error ("%s: expecting scalar integer arguments", fcn); |
|
1654 break; |
|
1655 } |
|
1656 } |
|
1657 } |
|
1658 break; |
|
1659 } |
|
1660 |
|
1661 if (! error_state) |
|
1662 { |
|
1663 dims.chop_trailing_singletons (); |
|
1664 |
|
1665 check_dimensions (dims, fcn); |
|
1666 |
|
1667 // Note that automatic narrowing will handle conversion from |
|
1668 // NDArray to scalar. |
|
1669 |
|
1670 if (! error_state) |
|
1671 { |
|
1672 switch (dt) |
|
1673 { |
5775
|
1674 case oct_data_conv::dt_single: // FIXME |
5747
|
1675 case oct_data_conv::dt_double: |
|
1676 retval = NDArray (dims, val); |
|
1677 break; |
|
1678 |
|
1679 default: |
|
1680 error ("%s: invalid class name", fcn); |
|
1681 break; |
|
1682 } |
|
1683 } |
|
1684 } |
|
1685 |
|
1686 return retval; |
|
1687 } |
|
1688 |
|
1689 static octave_value |
|
1690 fill_matrix (const octave_value_list& args, const Complex& val, |
|
1691 const char *fcn) |
|
1692 { |
|
1693 octave_value retval; |
|
1694 |
|
1695 int nargin = args.length (); |
|
1696 |
|
1697 oct_data_conv::data_type dt = oct_data_conv::dt_double; |
|
1698 |
|
1699 dim_vector dims (1, 1); |
|
1700 |
|
1701 if (nargin > 0 && args(nargin-1).is_string ()) |
|
1702 { |
|
1703 std::string nm = args(nargin-1).string_value (); |
|
1704 nargin--; |
|
1705 |
|
1706 dt = oct_data_conv::string_to_data_type (nm); |
|
1707 |
|
1708 if (error_state) |
|
1709 return retval; |
|
1710 } |
|
1711 |
|
1712 switch (nargin) |
|
1713 { |
|
1714 case 0: |
|
1715 break; |
|
1716 |
|
1717 case 1: |
|
1718 get_dimensions (args(0), fcn, dims); |
|
1719 break; |
|
1720 |
|
1721 default: |
|
1722 { |
|
1723 dims.resize (nargin); |
|
1724 |
|
1725 for (int i = 0; i < nargin; i++) |
|
1726 { |
6133
|
1727 dims(i) = args(i).is_empty () ? 0 : args(i).idx_type_value (); |
5747
|
1728 |
|
1729 if (error_state) |
|
1730 { |
|
1731 error ("%s: expecting scalar integer arguments", fcn); |
|
1732 break; |
|
1733 } |
|
1734 } |
|
1735 } |
|
1736 break; |
|
1737 } |
|
1738 |
|
1739 if (! error_state) |
|
1740 { |
|
1741 dims.chop_trailing_singletons (); |
|
1742 |
|
1743 check_dimensions (dims, fcn); |
|
1744 |
|
1745 // Note that automatic narrowing will handle conversion from |
|
1746 // NDArray to scalar. |
|
1747 |
|
1748 if (! error_state) |
|
1749 { |
|
1750 switch (dt) |
|
1751 { |
5775
|
1752 case oct_data_conv::dt_single: // FIXME |
5747
|
1753 case oct_data_conv::dt_double: |
|
1754 retval = ComplexNDArray (dims, val); |
|
1755 break; |
|
1756 |
|
1757 default: |
|
1758 error ("%s: invalid class name", fcn); |
|
1759 break; |
|
1760 } |
|
1761 } |
|
1762 } |
|
1763 |
|
1764 return retval; |
|
1765 } |
|
1766 |
|
1767 static octave_value |
|
1768 fill_matrix (const octave_value_list& args, bool val, const char *fcn) |
|
1769 { |
|
1770 octave_value retval; |
|
1771 |
|
1772 int nargin = args.length (); |
|
1773 |
|
1774 dim_vector dims (1, 1); |
|
1775 |
|
1776 switch (nargin) |
|
1777 { |
|
1778 case 0: |
|
1779 break; |
|
1780 |
|
1781 case 1: |
|
1782 get_dimensions (args(0), fcn, dims); |
|
1783 break; |
|
1784 |
|
1785 default: |
|
1786 { |
|
1787 dims.resize (nargin); |
|
1788 |
|
1789 for (int i = 0; i < nargin; i++) |
|
1790 { |
6133
|
1791 dims(i) = args(i).is_empty () ? 0 : args(i).idx_type_value (); |
5747
|
1792 |
|
1793 if (error_state) |
|
1794 { |
|
1795 error ("%s: expecting scalar integer arguments", fcn); |
|
1796 break; |
|
1797 } |
|
1798 } |
|
1799 } |
|
1800 break; |
|
1801 } |
|
1802 |
|
1803 if (! error_state) |
|
1804 { |
|
1805 dims.chop_trailing_singletons (); |
|
1806 |
|
1807 check_dimensions (dims, fcn); |
|
1808 |
|
1809 // Note that automatic narrowing will handle conversion from |
|
1810 // NDArray to scalar. |
|
1811 |
|
1812 if (! error_state) |
|
1813 retval = boolNDArray (dims, val); |
|
1814 } |
|
1815 |
|
1816 return retval; |
|
1817 } |
|
1818 |
3354
|
1819 DEFUN (ones, args, , |
3369
|
1820 "-*- texinfo -*-\n\ |
|
1821 @deftypefn {Built-in Function} {} ones (@var{x})\n\ |
|
1822 @deftypefnx {Built-in Function} {} ones (@var{n}, @var{m})\n\ |
4948
|
1823 @deftypefnx {Built-in Function} {} ones (@var{n}, @var{m}, @var{k}, @dots{})\n\ |
|
1824 @deftypefnx {Built-in Function} {} ones (@dots{}, @var{class})\n\ |
4481
|
1825 Return a matrix or N-dimensional array whose elements are all 1.\n\ |
|
1826 The arguments are handled the same as the arguments for @code{eye}.\n\ |
3369
|
1827 \n\ |
|
1828 If you need to create a matrix whose values are all the same, you should\n\ |
|
1829 use an expression like\n\ |
|
1830 \n\ |
|
1831 @example\n\ |
|
1832 val_matrix = val * ones (n, m)\n\ |
|
1833 @end example\n\ |
4945
|
1834 \n\ |
|
1835 The optional argument @var{class}, allows @code{ones} to return an array of\n\ |
5747
|
1836 the specified type, for example\n\ |
4945
|
1837 \n\ |
|
1838 @example\n\ |
|
1839 val = ones (n,m, \"uint8\")\n\ |
|
1840 @end example\n\ |
3369
|
1841 @end deftypefn") |
523
|
1842 { |
5747
|
1843 return fill_matrix (args, 1, "ones"); |
523
|
1844 } |
|
1845 |
3354
|
1846 DEFUN (zeros, args, , |
3369
|
1847 "-*- texinfo -*-\n\ |
|
1848 @deftypefn {Built-in Function} {} zeros (@var{x})\n\ |
|
1849 @deftypefnx {Built-in Function} {} zeros (@var{n}, @var{m})\n\ |
4948
|
1850 @deftypefnx {Built-in Function} {} zeros (@var{n}, @var{m}, @var{k}, @dots{})\n\ |
|
1851 @deftypefnx {Built-in Function} {} zeros (@dots{}, @var{class})\n\ |
4481
|
1852 Return a matrix or N-dimensional array whose elements are all 0.\n\ |
|
1853 The arguments are handled the same as the arguments for @code{eye}.\n\ |
4945
|
1854 \n\ |
|
1855 The optional argument @var{class}, allows @code{zeros} to return an array of\n\ |
5747
|
1856 the specified type, for example\n\ |
4945
|
1857 \n\ |
|
1858 @example\n\ |
|
1859 val = zeros (n,m, \"uint8\")\n\ |
|
1860 @end example\n\ |
3369
|
1861 @end deftypefn") |
523
|
1862 { |
5747
|
1863 return fill_matrix (args, 0, "zeros"); |
|
1864 } |
|
1865 |
|
1866 DEFUN (Inf, args, , |
|
1867 "-*- texinfo -*-\n\ |
|
1868 @deftypefn {Built-in Function} {} Inf (@var{x})\n\ |
|
1869 @deftypefnx {Built-in Function} {} Inf (@var{n}, @var{m})\n\ |
|
1870 @deftypefnx {Built-in Function} {} Inf (@var{n}, @var{m}, @var{k}, @dots{})\n\ |
|
1871 @deftypefnx {Built-in Function} {} Inf (@dots{}, @var{class})\n\ |
|
1872 Return a matrix or N-dimensional array whose elements are all Infinity.\n\ |
|
1873 The arguments are handled the same as the arguments for @code{eye}.\n\ |
|
1874 The optional argument @var{class} may be either @samp{\"single\"} or\n\ |
5798
|
1875 @samp{\"double\"}. The default is @samp{\"double\"}.\n\ |
5747
|
1876 @end deftypefn") |
|
1877 { |
|
1878 return fill_matrix (args, lo_ieee_inf_value (), "Inf"); |
|
1879 } |
|
1880 |
|
1881 DEFALIAS (inf, Inf); |
|
1882 |
|
1883 DEFUN (NaN, args, , |
|
1884 "-*- texinfo -*-\n\ |
|
1885 @deftypefn {Built-in Function} {} NaN (@var{x})\n\ |
|
1886 @deftypefnx {Built-in Function} {} NaN (@var{n}, @var{m})\n\ |
|
1887 @deftypefnx {Built-in Function} {} NaN (@var{n}, @var{m}, @var{k}, @dots{})\n\ |
|
1888 @deftypefnx {Built-in Function} {} NaN (@dots{}, @var{class})\n\ |
|
1889 Return a matrix or N-dimensional array whose elements are all NaN\n\ |
|
1890 (Not a Number). The value NaN is the result of an operation like\n\ |
|
1891 @iftex\n\ |
|
1892 @tex\n\ |
|
1893 $0/0$, or $\\infty - \\infty$,\n\ |
|
1894 @end tex\n\ |
|
1895 @end iftex\n\ |
|
1896 @ifinfo\n\ |
|
1897 0/0, or @samp{Inf - Inf},\n\ |
|
1898 @end ifinfo\n\ |
|
1899 or any operation with a NaN.\n\ |
|
1900 \n\ |
|
1901 Note that NaN always compares not equal to NaN. This behavior is\n\ |
|
1902 specified by the IEEE standard for floating point arithmetic. To\n\ |
|
1903 find NaN values, you must use the @code{isnan} function.\n\ |
|
1904 \n\ |
|
1905 The arguments are handled the same as the arguments for @code{eye}.\n\ |
|
1906 The optional argument @var{class} may be either @samp{\"single\"} or\n\ |
5798
|
1907 @samp{\"double\"}. The default is @samp{\"double\"}.\n\ |
5747
|
1908 @end deftypefn") |
|
1909 { |
|
1910 return fill_matrix (args, lo_ieee_nan_value (), "NaN"); |
|
1911 } |
|
1912 |
|
1913 DEFALIAS (nan, NaN); |
|
1914 |
|
1915 DEFUN (e, args, , |
|
1916 "-*- texinfo -*-\n\ |
|
1917 @deftypefn {Built-in Function} {} e (@var{x})\n\ |
|
1918 @deftypefnx {Built-in Function} {} e (@var{n}, @var{m})\n\ |
|
1919 @deftypefnx {Built-in Function} {} e (@var{n}, @var{m}, @var{k}, @dots{})\n\ |
|
1920 @deftypefnx {Built-in Function} {} e (@dots{}, @var{class})\n\ |
|
1921 Return a matrix or N-dimensional array whose elements are all equal\n\ |
|
1922 to the base of natural logarithms. The constant\n\ |
|
1923 @iftex\n\ |
|
1924 @tex\n\ |
|
1925 $e$\n\ |
|
1926 @end tex\n\ |
|
1927 @end iftex\n\ |
|
1928 @ifinfo\n\ |
|
1929 @var{e}\n\ |
|
1930 @end ifinfo\n\ |
|
1931 satisfies the equation\n\ |
|
1932 @iftex\n\ |
|
1933 @tex\n\ |
|
1934 $\\log (e) = 1$.\n\ |
|
1935 @end tex\n\ |
|
1936 @end iftex\n\ |
|
1937 @ifinfo\n\ |
|
1938 @code{log} (@var{e}) = 1.\n\ |
|
1939 @end ifinfo\n\ |
|
1940 @end deftypefn") |
|
1941 { |
|
1942 #if defined (M_E) |
|
1943 double e_val = M_E; |
|
1944 #else |
|
1945 double e_val = exp (1.0); |
|
1946 #endif |
|
1947 |
|
1948 return fill_matrix (args, e_val, "e"); |
|
1949 } |
|
1950 |
|
1951 DEFUN (eps, args, , |
|
1952 "-*- texinfo -*-\n\ |
|
1953 @deftypefn {Built-in Function} {} eps (@var{x})\n\ |
|
1954 @deftypefnx {Built-in Function} {} eps (@var{n}, @var{m})\n\ |
|
1955 @deftypefnx {Built-in Function} {} eps (@var{n}, @var{m}, @var{k}, @dots{})\n\ |
|
1956 @deftypefnx {Built-in Function} {} eps (@dots{}, @var{class})\n\ |
|
1957 Return a matrix or N-dimensional array whose elements are all eps,\n\ |
|
1958 the machine precision. More precisely, @code{eps} is the largest\n\ |
|
1959 relative spacing between any two adjacent numbers in the machine's\n\ |
|
1960 floating point system. This number is obviously system-dependent. On\n\ |
|
1961 machines that support 64 bit IEEE floating point arithmetic, @code{eps}\n\ |
|
1962 is approximately\n\ |
|
1963 @ifinfo\n\ |
|
1964 2.2204e-16.\n\ |
|
1965 @end ifinfo\n\ |
|
1966 @iftex\n\ |
|
1967 @tex\n\ |
|
1968 $2.2204\\times10^{-16}$.\n\ |
|
1969 @end tex\n\ |
|
1970 @end iftex\n\ |
|
1971 @end deftypefn") |
|
1972 { |
|
1973 return fill_matrix (args, DBL_EPSILON, "eps"); |
|
1974 } |
|
1975 |
|
1976 DEFUN (pi, args, , |
|
1977 "-*- texinfo -*-\n\ |
|
1978 @deftypefn {Built-in Function} {} pi (@var{x})\n\ |
|
1979 @deftypefnx {Built-in Function} {} pi (@var{n}, @var{m})\n\ |
|
1980 @deftypefnx {Built-in Function} {} pi (@var{n}, @var{m}, @var{k}, @dots{})\n\ |
|
1981 @deftypefnx {Built-in Function} {} pi (@dots{}, @var{class})\n\ |
|
1982 Return a matrix or N-dimensional array whose elements are all equal\n\ |
|
1983 to the ratio of the circumference of a circle to its diameter.\n\ |
|
1984 Internally, @code{pi} is computed as @samp{4.0 * atan (1.0)}.\n\ |
|
1985 @end deftypefn") |
|
1986 { |
|
1987 #if defined (M_PI) |
|
1988 double pi_val = M_PI; |
|
1989 #else |
|
1990 double pi_val = 4.0 * atan (1.0); |
|
1991 #endif |
|
1992 |
|
1993 return fill_matrix (args, pi_val, "pi"); |
|
1994 } |
|
1995 |
|
1996 DEFUN (realmax, args, , |
|
1997 "-*- texinfo -*-\n\ |
|
1998 @deftypefn {Built-in Function} {} realmax (@var{x})\n\ |
|
1999 @deftypefnx {Built-in Function} {} realmax (@var{n}, @var{m})\n\ |
|
2000 @deftypefnx {Built-in Function} {} realmax (@var{n}, @var{m}, @var{k}, @dots{})\n\ |
|
2001 @deftypefnx {Built-in Function} {} realmax (@dots{}, @var{class})\n\ |
|
2002 Return a matrix or N-dimensional array whose elements are all equal\n\ |
|
2003 to the largest floating point number that is representable. The actual\n\ |
|
2004 value is system-dependent. On machines that support 64-bit IEEE\n\ |
|
2005 floating point arithmetic, @code{realmax} is approximately\n\ |
|
2006 @ifinfo\n\ |
|
2007 1.7977e+308\n\ |
|
2008 @end ifinfo\n\ |
|
2009 @iftex\n\ |
|
2010 @tex\n\ |
|
2011 $1.7977\\times10^{308}$.\n\ |
|
2012 @end tex\n\ |
|
2013 @end iftex\n\ |
|
2014 @seealso{realmin}\n\ |
|
2015 @end deftypefn") |
|
2016 { |
|
2017 return fill_matrix (args, DBL_MAX, "realmax"); |
|
2018 } |
|
2019 |
|
2020 DEFUN (realmin, args, , |
|
2021 "-*- texinfo -*-\n\ |
|
2022 @deftypefn {Built-in Function} {} realmin (@var{x})\n\ |
|
2023 @deftypefnx {Built-in Function} {} realmin (@var{n}, @var{m})\n\ |
|
2024 @deftypefnx {Built-in Function} {} realmin (@var{n}, @var{m}, @var{k}, @dots{})\n\ |
|
2025 @deftypefnx {Built-in Function} {} realmin (@dots{}, @var{class})\n\ |
|
2026 Return a matrix or N-dimensional array whose elements are all equal\n\ |
|
2027 to the smallest normalized floating point number that is representable.\n\ |
|
2028 The actual value is system-dependent. On machines that support\n\ |
|
2029 64-bit IEEE floating point arithmetic, @code{realmin} is approximately\n\ |
|
2030 @ifinfo\n\ |
|
2031 2.2251e-308\n\ |
|
2032 @end ifinfo\n\ |
|
2033 @iftex\n\ |
|
2034 @tex\n\ |
|
2035 $2.2251\\times10^{-308}$.\n\ |
|
2036 @end tex\n\ |
|
2037 @end iftex\n\ |
|
2038 @seealso{realmax}\n\ |
|
2039 @end deftypefn") |
|
2040 { |
|
2041 return fill_matrix (args, DBL_MIN, "realmin"); |
|
2042 } |
|
2043 |
|
2044 DEFUN (I, args, , |
|
2045 "-*- texinfo -*-\n\ |
|
2046 @deftypefn {Built-in Function} {} I (@var{x})\n\ |
|
2047 @deftypefnx {Built-in Function} {} I (@var{n}, @var{m})\n\ |
|
2048 @deftypefnx {Built-in Function} {} I (@var{n}, @var{m}, @var{k}, @dots{})\n\ |
|
2049 @deftypefnx {Built-in Function} {} I (@dots{}, @var{class})\n\ |
|
2050 Return a matrix or N-dimensional array whose elements are all equal\n\ |
|
2051 to the pure imaginary unit, defined as\n\ |
|
2052 @iftex\n\ |
|
2053 @tex\n\ |
|
2054 $\\sqrt{-1}$.\n\ |
|
2055 @end tex\n\ |
|
2056 @end iftex\n\ |
|
2057 @ifinfo\n\ |
|
2058 @code{sqrt (-1)}.\n\ |
|
2059 @end ifinfo\n\ |
7001
|
2060 Since I (also i, J, and j) is a function, you can use the name(s) for\n\ |
5747
|
2061 other purposes.\n\ |
|
2062 @end deftypefn") |
|
2063 { |
|
2064 return fill_matrix (args, Complex (0.0, 1.0), "I"); |
|
2065 } |
|
2066 |
|
2067 DEFALIAS (i, I); |
|
2068 DEFALIAS (J, I); |
|
2069 DEFALIAS (j, I); |
|
2070 |
|
2071 DEFUN (NA, args, , |
|
2072 "-*- texinfo -*-\n\ |
|
2073 @deftypefn {Built-in Function} {} NA (@var{x})\n\ |
|
2074 @deftypefnx {Built-in Function} {} NA (@var{n}, @var{m})\n\ |
|
2075 @deftypefnx {Built-in Function} {} NA (@var{n}, @var{m}, @var{k}, @dots{})\n\ |
|
2076 @deftypefnx {Built-in Function} {} NA (@dots{}, @var{class})\n\ |
|
2077 Return a matrix or N-dimensional array whose elements are all equal\n\ |
|
2078 to the special constant used to designate missing values.\n\ |
|
2079 @end deftypefn") |
|
2080 { |
|
2081 return fill_matrix (args, lo_ieee_na_value (), "NA"); |
|
2082 } |
|
2083 |
|
2084 DEFUN (false, args, , |
|
2085 "-*- texinfo -*-\n\ |
|
2086 @deftypefn {Built-in Function} {} false (@var{x})\n\ |
|
2087 @deftypefnx {Built-in Function} {} false (@var{n}, @var{m})\n\ |
|
2088 @deftypefnx {Built-in Function} {} false (@var{n}, @var{m}, @var{k}, @dots{})\n\ |
|
2089 Return a matrix or N-dimensional array whose elements are all logical 0.\n\ |
|
2090 The arguments are handled the same as the arguments for @code{eye}.\n\ |
|
2091 @end deftypefn") |
|
2092 { |
|
2093 return fill_matrix (args, false, "false"); |
|
2094 } |
|
2095 |
|
2096 DEFUN (true, args, , |
|
2097 "-*- texinfo -*-\n\ |
|
2098 @deftypefn {Built-in Function} {} true (@var{x})\n\ |
|
2099 @deftypefnx {Built-in Function} {} true (@var{n}, @var{m})\n\ |
|
2100 @deftypefnx {Built-in Function} {} true (@var{n}, @var{m}, @var{k}, @dots{})\n\ |
|
2101 Return a matrix or N-dimensional array whose elements are all logical 1.\n\ |
|
2102 The arguments are handled the same as the arguments for @code{eye}.\n\ |
|
2103 @end deftypefn") |
|
2104 { |
|
2105 return fill_matrix (args, true, "true"); |
3354
|
2106 } |
523
|
2107 |
4946
|
2108 template <class MT> |
|
2109 octave_value |
|
2110 identity_matrix (int nr, int nc) |
|
2111 { |
|
2112 octave_value retval; |
|
2113 |
|
2114 typename octave_array_type_traits<MT>::element_type one (1); |
|
2115 |
|
2116 if (nr == 1 && nc == 1) |
|
2117 retval = one; |
|
2118 else |
|
2119 { |
|
2120 dim_vector dims (nr, nc); |
|
2121 |
|
2122 typename octave_array_type_traits<MT>::element_type zero (0); |
|
2123 |
|
2124 MT m (dims, zero); |
|
2125 |
|
2126 if (nr > 0 && nc > 0) |
|
2127 { |
|
2128 int n = std::min (nr, nc); |
|
2129 |
|
2130 for (int i = 0; i < n; i++) |
|
2131 m(i,i) = one; |
|
2132 } |
|
2133 |
|
2134 retval = m; |
|
2135 } |
|
2136 |
|
2137 return retval; |
|
2138 } |
|
2139 |
5058
|
2140 #define INSTANTIATE_EYE(T) \ |
|
2141 template octave_value identity_matrix<T> (int, int) |
|
2142 |
|
2143 INSTANTIATE_EYE (int8NDArray); |
|
2144 INSTANTIATE_EYE (uint8NDArray); |
|
2145 INSTANTIATE_EYE (int16NDArray); |
|
2146 INSTANTIATE_EYE (uint16NDArray); |
|
2147 INSTANTIATE_EYE (int32NDArray); |
|
2148 INSTANTIATE_EYE (uint32NDArray); |
|
2149 INSTANTIATE_EYE (int64NDArray); |
|
2150 INSTANTIATE_EYE (uint64NDArray); |
|
2151 INSTANTIATE_EYE (NDArray); |
|
2152 INSTANTIATE_EYE (boolNDArray); |
|
2153 |
4945
|
2154 static octave_value |
4948
|
2155 identity_matrix (int nr, int nc, oct_data_conv::data_type dt) |
4945
|
2156 { |
|
2157 octave_value retval; |
|
2158 |
5775
|
2159 // FIXME -- perhaps this should be made extensible by using |
4946
|
2160 // the class name to lookup a function to call to create the new |
|
2161 // value. |
|
2162 |
|
2163 if (! error_state) |
|
2164 { |
|
2165 switch (dt) |
|
2166 { |
|
2167 case oct_data_conv::dt_int8: |
|
2168 retval = identity_matrix<int8NDArray> (nr, nc); |
|
2169 break; |
|
2170 |
|
2171 case oct_data_conv::dt_uint8: |
|
2172 retval = identity_matrix<uint8NDArray> (nr, nc); |
|
2173 break; |
|
2174 |
|
2175 case oct_data_conv::dt_int16: |
|
2176 retval = identity_matrix<int16NDArray> (nr, nc); |
|
2177 break; |
4945
|
2178 |
4946
|
2179 case oct_data_conv::dt_uint16: |
|
2180 retval = identity_matrix<uint16NDArray> (nr, nc); |
|
2181 break; |
|
2182 |
|
2183 case oct_data_conv::dt_int32: |
|
2184 retval = identity_matrix<int32NDArray> (nr, nc); |
|
2185 break; |
|
2186 |
|
2187 case oct_data_conv::dt_uint32: |
|
2188 retval = identity_matrix<uint32NDArray> (nr, nc); |
|
2189 break; |
4945
|
2190 |
4946
|
2191 case oct_data_conv::dt_int64: |
|
2192 retval = identity_matrix<int64NDArray> (nr, nc); |
|
2193 break; |
|
2194 |
|
2195 case oct_data_conv::dt_uint64: |
|
2196 retval = identity_matrix<uint64NDArray> (nr, nc); |
|
2197 break; |
4945
|
2198 |
5775
|
2199 case oct_data_conv::dt_single: // FIXME |
4946
|
2200 case oct_data_conv::dt_double: |
|
2201 retval = identity_matrix<NDArray> (nr, nc); |
|
2202 break; |
4945
|
2203 |
4986
|
2204 case oct_data_conv::dt_logical: |
|
2205 retval = identity_matrix<boolNDArray> (nr, nc); |
|
2206 break; |
|
2207 |
4946
|
2208 default: |
|
2209 error ("eye: invalid class name"); |
|
2210 break; |
4945
|
2211 } |
|
2212 } |
|
2213 |
|
2214 return retval; |
|
2215 } |
|
2216 |
4946
|
2217 #undef INT_EYE_MATRIX |
|
2218 |
1957
|
2219 DEFUN (eye, args, , |
3369
|
2220 "-*- texinfo -*-\n\ |
|
2221 @deftypefn {Built-in Function} {} eye (@var{x})\n\ |
|
2222 @deftypefnx {Built-in Function} {} eye (@var{n}, @var{m})\n\ |
4948
|
2223 @deftypefnx {Built-in Function} {} eye (@dots{}, @var{class})\n\ |
3369
|
2224 Return an identity matrix. If invoked with a single scalar argument,\n\ |
|
2225 @code{eye} returns a square matrix with the dimension specified. If you\n\ |
|
2226 supply two scalar arguments, @code{eye} takes them to be the number of\n\ |
|
2227 rows and columns. If given a vector with two elements, @code{eye} uses\n\ |
|
2228 the values of the elements as the number of rows and columns,\n\ |
|
2229 respectively. For example,\n\ |
|
2230 \n\ |
|
2231 @example\n\ |
|
2232 @group\n\ |
|
2233 eye (3)\n\ |
|
2234 @result{} 1 0 0\n\ |
|
2235 0 1 0\n\ |
|
2236 0 0 1\n\ |
|
2237 @end group\n\ |
|
2238 @end example\n\ |
|
2239 \n\ |
|
2240 The following expressions all produce the same result:\n\ |
|
2241 \n\ |
|
2242 @example\n\ |
|
2243 @group\n\ |
|
2244 eye (2)\n\ |
|
2245 @equiv{}\n\ |
|
2246 eye (2, 2)\n\ |
|
2247 @equiv{}\n\ |
|
2248 eye (size ([1, 2; 3, 4])\n\ |
|
2249 @end group\n\ |
|
2250 @end example\n\ |
|
2251 \n\ |
4945
|
2252 The optional argument @var{class}, allows @code{eye} to return an array of\n\ |
|
2253 the specified type, like\n\ |
|
2254 \n\ |
|
2255 @example\n\ |
|
2256 val = zeros (n,m, \"uint8\")\n\ |
|
2257 @end example\n\ |
|
2258 \n\ |
6556
|
2259 Calling @code{eye} with no arguments is equivalent to calling it\n\ |
|
2260 with an argument of 1. This odd definition is for compatibility\n\ |
|
2261 with @sc{Matlab}.\n\ |
3369
|
2262 @end deftypefn") |
523
|
2263 { |
3354
|
2264 octave_value retval; |
523
|
2265 |
4948
|
2266 int nargin = args.length (); |
4945
|
2267 |
4948
|
2268 oct_data_conv::data_type dt = oct_data_conv::dt_double; |
523
|
2269 |
4945
|
2270 // Check for type information. |
|
2271 |
|
2272 if (nargin > 0 && args(nargin-1).is_string ()) |
|
2273 { |
4948
|
2274 std::string nm = args(nargin-1).string_value (); |
4945
|
2275 nargin--; |
4948
|
2276 |
|
2277 dt = oct_data_conv::string_to_data_type (nm); |
|
2278 |
|
2279 if (error_state) |
|
2280 return retval; |
4945
|
2281 } |
|
2282 |
523
|
2283 switch (nargin) |
|
2284 { |
712
|
2285 case 0: |
4948
|
2286 retval = identity_matrix (1, 1, dt); |
712
|
2287 break; |
777
|
2288 |
610
|
2289 case 1: |
3354
|
2290 { |
5275
|
2291 octave_idx_type nr, nc; |
3354
|
2292 get_dimensions (args(0), "eye", nr, nc); |
|
2293 |
|
2294 if (! error_state) |
4948
|
2295 retval = identity_matrix (nr, nc, dt); |
3354
|
2296 } |
610
|
2297 break; |
777
|
2298 |
523
|
2299 case 2: |
3354
|
2300 { |
5275
|
2301 octave_idx_type nr, nc; |
3354
|
2302 get_dimensions (args(0), args(1), "eye", nr, nc); |
|
2303 |
|
2304 if (! error_state) |
4948
|
2305 retval = identity_matrix (nr, nc, dt); |
3354
|
2306 } |
523
|
2307 break; |
777
|
2308 |
523
|
2309 default: |
5823
|
2310 print_usage (); |
523
|
2311 break; |
|
2312 } |
|
2313 |
|
2314 return retval; |
|
2315 } |
|
2316 |
1957
|
2317 DEFUN (linspace, args, , |
3369
|
2318 "-*- texinfo -*-\n\ |
|
2319 @deftypefn {Built-in Function} {} linspace (@var{base}, @var{limit}, @var{n})\n\ |
|
2320 Return a row vector with @var{n} linearly spaced elements between\n\ |
6630
|
2321 @var{base} and @var{limit}. If the number of elements is greater than one,\n\ |
|
2322 then the @var{base} and @var{limit} are always included in\n\ |
3369
|
2323 the range. If @var{base} is greater than @var{limit}, the elements are\n\ |
|
2324 stored in decreasing order. If the number of points is not specified, a\n\ |
|
2325 value of 100 is used.\n\ |
1100
|
2326 \n\ |
4455
|
2327 The @code{linspace} function always returns a row vector.\n\ |
6630
|
2328 \n\ |
|
2329 For compatibility with @sc{Matlab}, return the second argument if\n\ |
|
2330 fewer than two values are requested.\n\ |
3369
|
2331 @end deftypefn") |
1100
|
2332 { |
3418
|
2333 octave_value retval; |
1100
|
2334 |
|
2335 int nargin = args.length (); |
|
2336 |
6133
|
2337 octave_idx_type npoints = 100; |
1100
|
2338 |
1940
|
2339 if (nargin != 2 && nargin != 3) |
|
2340 { |
5823
|
2341 print_usage (); |
1940
|
2342 return retval; |
|
2343 } |
|
2344 |
1100
|
2345 if (nargin == 3) |
6133
|
2346 npoints = args(2).idx_type_value (); |
1100
|
2347 |
|
2348 if (! error_state) |
|
2349 { |
3322
|
2350 octave_value arg_1 = args(0); |
|
2351 octave_value arg_2 = args(1); |
1100
|
2352 |
3322
|
2353 if (arg_1.is_complex_type () || arg_2.is_complex_type ()) |
|
2354 { |
|
2355 Complex x1 = arg_1.complex_value (); |
|
2356 Complex x2 = arg_2.complex_value (); |
|
2357 |
|
2358 if (! error_state) |
1100
|
2359 { |
3322
|
2360 ComplexRowVector rv = linspace (x1, x2, npoints); |
1100
|
2361 |
|
2362 if (! error_state) |
3418
|
2363 retval = rv; |
1100
|
2364 } |
|
2365 } |
|
2366 else |
3322
|
2367 { |
|
2368 double x1 = arg_1.double_value (); |
|
2369 double x2 = arg_2.double_value (); |
|
2370 |
|
2371 if (! error_state) |
|
2372 { |
|
2373 RowVector rv = linspace (x1, x2, npoints); |
|
2374 |
|
2375 if (! error_state) |
3418
|
2376 retval = rv; |
3322
|
2377 } |
|
2378 } |
1100
|
2379 } |
4732
|
2380 else |
|
2381 error ("linspace: expecting third argument to be an integer"); |
1100
|
2382 |
|
2383 return retval; |
|
2384 } |
|
2385 |
5775
|
2386 // FIXME -- should accept dimensions as separate args for N-d |
5734
|
2387 // arrays as well as 1-d and 2-d arrays. |
|
2388 |
5731
|
2389 DEFUN (resize, args, , |
|
2390 "-*- texinfo -*-\n\ |
|
2391 @deftypefn {Built-in Function} {} resize (@var{x}, @var{m})\n\ |
|
2392 @deftypefnx {Built-in Function} {} resize (@var{x}, @var{m}, @var{n})\n\ |
6174
|
2393 Destructively resize @var{x}.\n\ |
|
2394 \n\ |
|
2395 @strong{Values in @var{x} are not preserved as they are with\n\ |
6175
|
2396 @code{reshape}.}\n\ |
6174
|
2397 \n\ |
|
2398 If only @var{m} is supplied and it is a scalar, the dimension of the\n\ |
|
2399 result is @var{m}-by-@var{m}. If @var{m} is a vector, then the\n\ |
|
2400 dimensions of the result are given by the elements of @var{m}.\n\ |
|
2401 If both @var{m} and @var{n} are scalars, then the dimensions of\n\ |
|
2402 the result are @var{m}-by-@var{n}.\n\ |
|
2403 @seealso{reshape}\n\ |
5731
|
2404 @end deftypefn") |
|
2405 { |
|
2406 octave_value retval; |
|
2407 int nargin = args.length (); |
|
2408 |
|
2409 if (nargin == 2) |
|
2410 { |
|
2411 Array<double> vec = args(1).vector_value (); |
|
2412 int ndim = vec.length (); |
|
2413 if (ndim == 1) |
|
2414 { |
|
2415 octave_idx_type m = static_cast<octave_idx_type> (vec(0)); |
|
2416 retval = args(0); |
|
2417 retval = retval.resize (dim_vector (m, m), true); |
|
2418 } |
|
2419 else |
|
2420 { |
|
2421 dim_vector dv; |
|
2422 dv.resize (ndim); |
|
2423 for (int i = 0; i < ndim; i++) |
|
2424 dv(i) = static_cast<octave_idx_type> (vec(i)); |
|
2425 retval = args(0); |
|
2426 retval = retval.resize (dv, true); |
|
2427 } |
|
2428 } |
|
2429 else if (nargin == 3) |
|
2430 { |
|
2431 octave_idx_type m = static_cast<octave_idx_type> |
|
2432 (args(1).scalar_value()); |
|
2433 octave_idx_type n = static_cast<octave_idx_type> |
|
2434 (args(2).scalar_value()); |
|
2435 if (!error_state) |
|
2436 { |
|
2437 retval = args(0); |
|
2438 retval = retval.resize (dim_vector (m, n), true); |
|
2439 } |
|
2440 } |
|
2441 else |
5823
|
2442 print_usage (); |
5731
|
2443 return retval; |
|
2444 } |
|
2445 |
5775
|
2446 // FIXME -- should use octave_idx_type for dimensions. |
5734
|
2447 |
4567
|
2448 DEFUN (reshape, args, , |
|
2449 "-*- texinfo -*-\n\ |
6671
|
2450 @deftypefn {Built-in Function} {} reshape (@var{a}, @var{m}, @var{n}, @dots{})\n\ |
|
2451 @deftypefnx {Built-in Function} {} reshape (@var{a}, @var{siz})\n\ |
4567
|
2452 Return a matrix with the given dimensions whose elements are taken\n\ |
6671
|
2453 from the matrix @var{a}. The elements of the matrix are accessed in\n\ |
4567
|
2454 column-major order (like Fortran arrays are stored).\n\ |
|
2455 \n\ |
|
2456 For example,\n\ |
|
2457 \n\ |
|
2458 @example\n\ |
|
2459 @group\n\ |
|
2460 reshape ([1, 2, 3, 4], 2, 2)\n\ |
|
2461 @result{} 1 3\n\ |
|
2462 2 4\n\ |
|
2463 @end group\n\ |
|
2464 @end example\n\ |
|
2465 \n\ |
|
2466 @noindent\n\ |
|
2467 Note that the total number of elements in the original\n\ |
|
2468 matrix must match the total number of elements in the new matrix.\n\ |
5013
|
2469 \n\ |
|
2470 A single dimension of the return matrix can be unknown and is flagged\n\ |
|
2471 by an empty argument.\n\ |
4567
|
2472 @end deftypefn") |
|
2473 { |
|
2474 octave_value retval; |
|
2475 |
|
2476 int nargin = args.length (); |
|
2477 |
|
2478 Array<int> new_size; |
|
2479 |
|
2480 if (nargin == 2) |
|
2481 new_size = args(1).int_vector_value (); |
|
2482 else if (nargin > 2) |
|
2483 { |
|
2484 new_size.resize (nargin-1); |
5013
|
2485 int empty_dim = -1; |
|
2486 |
4567
|
2487 for (int i = 1; i < nargin; i++) |
|
2488 { |
5013
|
2489 if (args(i).is_empty ()) |
|
2490 if (empty_dim > 0) |
|
2491 { |
|
2492 error ("reshape: only a single dimension can be unknown"); |
|
2493 break; |
|
2494 } |
|
2495 else |
|
2496 { |
|
2497 empty_dim = i; |
|
2498 new_size(i-1) = 1; |
|
2499 } |
|
2500 else |
|
2501 { |
6133
|
2502 new_size(i-1) = args(i).idx_type_value (); |
4567
|
2503 |
5013
|
2504 if (error_state) |
|
2505 break; |
|
2506 } |
|
2507 } |
|
2508 |
|
2509 if (! error_state && (empty_dim > 0)) |
|
2510 { |
|
2511 int nel = 1; |
|
2512 for (int i = 0; i < nargin - 1; i++) |
|
2513 nel *= new_size(i); |
|
2514 |
|
2515 if (nel == 0) |
|
2516 new_size(empty_dim-1) = 0; |
|
2517 else |
|
2518 { |
|
2519 int size_empty_dim = args(0).numel () / nel; |
|
2520 |
|
2521 if (args(0).numel () != size_empty_dim * nel) |
|
2522 error ("reshape: size is not divisble by the product of known dimensions (= %d)", nel); |
|
2523 else |
|
2524 new_size(empty_dim-1) = size_empty_dim; |
|
2525 } |
4567
|
2526 } |
|
2527 } |
|
2528 else |
|
2529 { |
5823
|
2530 print_usage (); |
4567
|
2531 return retval; |
|
2532 } |
|
2533 |
|
2534 if (error_state) |
|
2535 { |
|
2536 error ("reshape: invalid arguments"); |
|
2537 return retval; |
|
2538 } |
|
2539 |
4739
|
2540 // Remove trailing singletons in new_size, but leave at least 2 |
|
2541 // elements. |
|
2542 |
4567
|
2543 int n = new_size.length (); |
|
2544 |
4739
|
2545 while (n > 2) |
|
2546 { |
|
2547 if (new_size(n-1) == 1) |
|
2548 n--; |
|
2549 else |
|
2550 break; |
|
2551 } |
|
2552 |
|
2553 new_size.resize (n); |
|
2554 |
4567
|
2555 if (n < 2) |
|
2556 { |
|
2557 error ("reshape: expecting size to be vector with at least 2 elements"); |
|
2558 return retval; |
|
2559 } |
|
2560 |
|
2561 dim_vector new_dims; |
|
2562 |
|
2563 new_dims.resize (n); |
|
2564 |
5275
|
2565 for (octave_idx_type i = 0; i < n; i++) |
4567
|
2566 new_dims(i) = new_size(i); |
|
2567 |
|
2568 octave_value arg = args(0); |
|
2569 |
|
2570 if (new_dims.numel () == arg.numel ()) |
|
2571 retval = (new_dims == arg.dims ()) ? arg : arg.reshape (new_dims); |
|
2572 else |
|
2573 error ("reshape: size mismatch"); |
|
2574 |
|
2575 return retval; |
|
2576 } |
|
2577 |
4532
|
2578 DEFUN (squeeze, args, , |
|
2579 "-*- texinfo -*-\n\ |
|
2580 @deftypefn {Built-in Function} {} squeeze (@var{x})\n\ |
|
2581 Remove singleton dimensions from @var{x} and return the result.\n\ |
6999
|
2582 Note that for compatibility with @sc{Matlab}, all objects have\n\ |
|
2583 a minimum of two dimensions.\n\ |
4532
|
2584 @end deftypefn") |
|
2585 { |
|
2586 octave_value retval; |
|
2587 |
|
2588 if (args.length () == 1) |
4545
|
2589 retval = args(0).squeeze (); |
4532
|
2590 else |
5823
|
2591 print_usage (); |
4532
|
2592 |
|
2593 return retval; |
|
2594 } |
|
2595 |
6953
|
2596 /* |
|
2597 %!shared x |
|
2598 %! x = [1, -3, 4, 5, -7]; |
|
2599 %!assert(norm(x,1), 20); |
|
2600 %!assert(norm(x,2), 10); |
|
2601 %!assert(norm(x,3), 8.24257059961711, -4*eps); |
|
2602 %!assert(norm(x,Inf), 7); |
|
2603 %!assert(norm(x,-Inf), 1); |
|
2604 %!assert(norm(x,"inf"), 7); |
|
2605 %!assert(norm(x,"fro"), 10); |
|
2606 %!assert(norm(x), 10); |
|
2607 %!assert(norm([1e200, 1]), 1e200); |
|
2608 %!assert(norm([3+4i, 3-4i, sqrt(31)]), 9, -4*eps); |
|
2609 %!shared m |
|
2610 %! m = magic (4); |
|
2611 %!assert(norm(m,1), 34); |
|
2612 %!assert(norm(m,2), 34); |
|
2613 %!assert(norm(m,Inf), 34); |
|
2614 %!assert(norm(m,"inf"), 34); |
|
2615 */ |
|
2616 |
6945
|
2617 // Compute various norms of the vector X. |
|
2618 |
6953
|
2619 DEFUN (norm, args, , |
6508
|
2620 "-*- texinfo -*-\n\ |
6953
|
2621 @deftypefn {Function File} {} norm (@var{a}, @var{p})\n\ |
|
2622 Compute the p-norm of the matrix @var{a}. If the second argument is\n\ |
|
2623 missing, @code{p = 2} is assumed.\n\ |
|
2624 \n\ |
|
2625 If @var{a} is a matrix:\n\ |
|
2626 \n\ |
|
2627 @table @asis\n\ |
|
2628 @item @var{p} = @code{1}\n\ |
|
2629 1-norm, the largest column sum of the absolute values of @var{a}.\n\ |
|
2630 \n\ |
|
2631 @item @var{p} = @code{2}\n\ |
|
2632 Largest singular value of @var{a}.\n\ |
|
2633 \n\ |
|
2634 @item @var{p} = @code{Inf}\n\ |
|
2635 @cindex infinity norm\n\ |
|
2636 Infinity norm, the largest row sum of the absolute values of @var{a}.\n\ |
|
2637 \n\ |
|
2638 @item @var{p} = @code{\"fro\"}\n\ |
|
2639 @cindex Frobenius norm\n\ |
|
2640 Frobenius norm of @var{a}, @code{sqrt (sum (diag (@var{a}' * @var{a})))}.\n\ |
|
2641 @end table\n\ |
|
2642 \n\ |
|
2643 If @var{a} is a vector or a scalar:\n\ |
|
2644 \n\ |
|
2645 @table @asis\n\ |
|
2646 @item @var{p} = @code{Inf}\n\ |
|
2647 @code{max (abs (@var{a}))}.\n\ |
|
2648 \n\ |
|
2649 @item @var{p} = @code{-Inf}\n\ |
|
2650 @code{min (abs (@var{a}))}.\n\ |
|
2651 \n\ |
|
2652 @item other\n\ |
|
2653 p-norm of @var{a}, @code{(sum (abs (@var{a}) .^ @var{p})) ^ (1/@var{p})}.\n\ |
|
2654 @end table\n\ |
|
2655 @seealso{cond, svd}\n\ |
6508
|
2656 @end deftypefn") |
|
2657 { |
6953
|
2658 // Currently only handles vector norms for full double/complex |
|
2659 // vectors internally. Other cases are handled by __norm__.m. |
|
2660 |
|
2661 octave_value_list retval; |
6508
|
2662 |
|
2663 int nargin = args.length (); |
|
2664 |
|
2665 if (nargin == 1 || nargin == 2) |
|
2666 { |
6953
|
2667 octave_value x_arg = args(0); |
|
2668 |
|
2669 if (x_arg.is_empty ()) |
|
2670 retval(0) = 0.0; |
|
2671 else if (x_arg.ndims () == 2) |
6508
|
2672 { |
6953
|
2673 if ((x_arg.rows () == 1 || x_arg.columns () == 1) |
|
2674 && ! (x_arg.is_sparse_type () || x_arg.is_integer_type ())) |
|
2675 { |
|
2676 double p_val; |
|
2677 |
|
2678 octave_value p_arg; |
|
2679 |
|
2680 if (nargin == 1) |
|
2681 p_arg = 2; |
|
2682 else |
|
2683 p_arg = args(1); |
|
2684 |
|
2685 if (p_arg.is_string ()) |
|
2686 { |
|
2687 std::string p = args(1).string_value (); |
|
2688 |
|
2689 if (p == "inf") |
|
2690 p_val = octave_Inf; |
|
2691 else if (p == "fro") |
|
2692 p_val = -1; |
|
2693 else |
|
2694 error ("norm: unrecognized norm `%s'", p.c_str ()); |
|
2695 } |
|
2696 else |
|
2697 { |
|
2698 p_val = p_arg.double_value (); |
|
2699 |
|
2700 if (error_state) |
|
2701 error ("norm: unrecognized norm value"); |
|
2702 } |
|
2703 |
|
2704 if (! error_state) |
|
2705 { |
|
2706 if (x_arg.is_real_type ()) |
|
2707 { |
|
2708 MArray<double> x (x_arg.array_value ()); |
|
2709 |
|
2710 if (! error_state) |
|
2711 retval(0) = x.norm (p_val); |
|
2712 else |
|
2713 error ("norm: expecting real vector"); |
|
2714 } |
|
2715 else |
|
2716 { |
|
2717 MArray<Complex> x (x_arg.complex_array_value ()); |
|
2718 |
|
2719 if (! error_state) |
|
2720 retval(0) = x.norm (p_val); |
|
2721 else |
|
2722 error ("norm: expecting complex vector"); |
|
2723 } |
|
2724 } |
|
2725 } |
6508
|
2726 else |
6953
|
2727 retval = feval ("__norm__", args); |
6508
|
2728 } |
|
2729 else |
6953
|
2730 error ("norm: only valid for 2-D objects"); |
6508
|
2731 } |
|
2732 else |
|
2733 print_usage (); |
|
2734 |
|
2735 return retval; |
|
2736 } |
|
2737 |
6518
|
2738 #define UNARY_OP_DEFUN_BODY(F) \ |
|
2739 \ |
|
2740 octave_value retval; \ |
|
2741 \ |
|
2742 if (args.length () == 1) \ |
|
2743 retval = F (args(0)); \ |
|
2744 else \ |
|
2745 print_usage (); \ |
|
2746 \ |
|
2747 return retval |
|
2748 |
|
2749 DEFUN (not, args, , |
|
2750 "-*- texinfo -*-\n\ |
|
2751 @deftypefn {Built-in Function} {} not (@var{x})\n\ |
|
2752 This function is equivalent to @code{! x}.\n\ |
|
2753 @end deftypefn") |
|
2754 { |
|
2755 UNARY_OP_DEFUN_BODY (op_not); |
|
2756 } |
|
2757 |
|
2758 DEFUN (uplus, args, , |
|
2759 "-*- texinfo -*-\n\ |
|
2760 @deftypefn {Built-in Function} {} uplus (@var{x})\n\ |
|
2761 This function is equivalent to @code{+ x}.\n\ |
|
2762 @end deftypefn") |
|
2763 { |
|
2764 UNARY_OP_DEFUN_BODY (op_uplus); |
|
2765 } |
|
2766 |
|
2767 DEFUN (uminus, args, , |
|
2768 "-*- texinfo -*-\n\ |
|
2769 @deftypefn {Built-in Function} {} uminus (@var{x})\n\ |
|
2770 This function is equivalent to @code{- x}.\n\ |
|
2771 @end deftypefn") |
|
2772 { |
|
2773 UNARY_OP_DEFUN_BODY (op_uminus); |
|
2774 } |
|
2775 |
|
2776 DEFUN (transpose, args, , |
|
2777 "-*- texinfo -*-\n\ |
|
2778 @deftypefn {Built-in Function} {} transpose (@var{x})\n\ |
|
2779 This function is equivalent to @code{x.'}.\n\ |
|
2780 @end deftypefn") |
|
2781 { |
|
2782 UNARY_OP_DEFUN_BODY (op_transpose); |
|
2783 } |
|
2784 |
|
2785 DEFUN (ctranspose, args, , |
|
2786 "-*- texinfo -*-\n\ |
|
2787 @deftypefn {Built-in Function} {} ctranspose (@var{x})\n\ |
|
2788 This function is equivalent to @code{x'}.\n\ |
|
2789 @end deftypefn") |
|
2790 { |
|
2791 UNARY_OP_DEFUN_BODY (op_hermitian); |
|
2792 } |
|
2793 |
|
2794 #define BINARY_OP_DEFUN_BODY(F) \ |
|
2795 \ |
|
2796 octave_value retval; \ |
|
2797 \ |
|
2798 if (args.length () == 2) \ |
|
2799 retval = F (args(0), args(1)); \ |
|
2800 else \ |
|
2801 print_usage (); \ |
|
2802 \ |
|
2803 return retval |
|
2804 |
|
2805 DEFUN (plus, args, , |
|
2806 "-*- texinfo -*-\n\ |
|
2807 @deftypefn {Built-in Function} {} plus (@var{x}, @var{y})\n\ |
|
2808 This function is equivalent to @code{x + y}.\n\ |
|
2809 @end deftypefn") |
|
2810 { |
|
2811 BINARY_OP_DEFUN_BODY (op_add); |
|
2812 } |
|
2813 |
|
2814 DEFUN (minus, args, , |
|
2815 "-*- texinfo -*-\n\ |
|
2816 @deftypefn {Built-in Function} {} minus (@var{x}, @var{y})\n\ |
|
2817 This function is equivalent to @code{x - y}.\n\ |
|
2818 @end deftypefn") |
|
2819 { |
|
2820 BINARY_OP_DEFUN_BODY (op_sub); |
|
2821 } |
|
2822 |
|
2823 DEFUN (mtimes, args, , |
|
2824 "-*- texinfo -*-\n\ |
|
2825 @deftypefn {Built-in Function} {} mtimes (@var{x}, @var{y})\n\ |
|
2826 This function is equivalent to @code{x * y}.\n\ |
|
2827 @end deftypefn") |
|
2828 { |
|
2829 BINARY_OP_DEFUN_BODY (op_mul); |
|
2830 } |
|
2831 |
|
2832 DEFUN (mrdivide, args, , |
|
2833 "-*- texinfo -*-\n\ |
|
2834 @deftypefn {Built-in Function} {} mrdivide (@var{x}, @var{y})\n\ |
|
2835 This function is equivalent to @code{x / y}.\n\ |
|
2836 @end deftypefn") |
|
2837 { |
|
2838 BINARY_OP_DEFUN_BODY (op_div); |
|
2839 } |
|
2840 |
|
2841 DEFUN (mpower, args, , |
|
2842 "-*- texinfo -*-\n\ |
|
2843 @deftypefn {Built-in Function} {} mpower (@var{x}, @var{y})\n\ |
|
2844 This function is equivalent to @code{x ^ y}.\n\ |
|
2845 @end deftypefn") |
|
2846 { |
|
2847 BINARY_OP_DEFUN_BODY (op_pow); |
|
2848 } |
|
2849 |
|
2850 DEFUN (mldivide, args, , |
|
2851 "-*- texinfo -*-\n\ |
|
2852 @deftypefn {Built-in Function} {} mldivide (@var{x}, @var{y})\n\ |
|
2853 This function is equivalent to @code{x \\ y}.\n\ |
|
2854 @end deftypefn") |
|
2855 { |
|
2856 BINARY_OP_DEFUN_BODY (op_ldiv); |
|
2857 } |
|
2858 |
|
2859 DEFUN (lt, args, , |
|
2860 "-*- texinfo -*-\n\ |
|
2861 @deftypefn {Built-in Function} {} lt (@var{x}, @var{y})\n\ |
|
2862 This function is equivalent to @code{x < y}.\n\ |
|
2863 @end deftypefn") |
|
2864 { |
|
2865 BINARY_OP_DEFUN_BODY (op_lt); |
|
2866 } |
|
2867 |
|
2868 DEFUN (le, args, , |
|
2869 "-*- texinfo -*-\n\ |
|
2870 @deftypefn {Built-in Function} {} le (@var{x}, @var{y})\n\ |
|
2871 This function is equivalent to @code{x <= y}.\n\ |
|
2872 @end deftypefn") |
|
2873 { |
|
2874 BINARY_OP_DEFUN_BODY (op_le); |
|
2875 } |
|
2876 |
|
2877 DEFUN (eq, args, , |
|
2878 "-*- texinfo -*-\n\ |
|
2879 @deftypefn {Built-in Function} {} eq (@var{x}, @var{y})\n\ |
|
2880 This function is equivalent to @code{x == y}.\n\ |
|
2881 @end deftypefn") |
|
2882 { |
|
2883 BINARY_OP_DEFUN_BODY (op_eq); |
|
2884 } |
|
2885 |
|
2886 DEFUN (ge, args, , |
|
2887 "-*- texinfo -*-\n\ |
|
2888 @deftypefn {Built-in Function} {} ge (@var{x}, @var{y})\n\ |
|
2889 This function is equivalent to @code{x >= y}.\n\ |
|
2890 @end deftypefn") |
|
2891 { |
|
2892 BINARY_OP_DEFUN_BODY (op_ge); |
|
2893 } |
|
2894 |
|
2895 DEFUN (gt, args, , |
|
2896 "-*- texinfo -*-\n\ |
|
2897 @deftypefn {Built-in Function} {} gt (@var{x}, @var{y})\n\ |
|
2898 This function is equivalent to @code{x > y}.\n\ |
|
2899 @end deftypefn") |
|
2900 { |
|
2901 BINARY_OP_DEFUN_BODY (op_gt); |
|
2902 } |
|
2903 |
|
2904 DEFUN (ne, args, , |
|
2905 "-*- texinfo -*-\n\ |
|
2906 @deftypefn {Built-in Function} {} ne (@var{x}, @var{y})\n\ |
|
2907 This function is equivalent to @code{x != y}.\n\ |
|
2908 @end deftypefn") |
|
2909 { |
|
2910 BINARY_OP_DEFUN_BODY (op_ne); |
|
2911 } |
|
2912 |
|
2913 DEFUN (times, args, , |
|
2914 "-*- texinfo -*-\n\ |
|
2915 @deftypefn {Built-in Function} {} times (@var{x}, @var{y})\n\ |
|
2916 This function is equivalent to @code{x .* y}.\n\ |
|
2917 @end deftypefn") |
|
2918 { |
|
2919 BINARY_OP_DEFUN_BODY (op_el_mul); |
|
2920 } |
|
2921 |
|
2922 DEFUN (rdivide, args, , |
|
2923 "-*- texinfo -*-\n\ |
|
2924 @deftypefn {Built-in Function} {} rdivide (@var{x}, @var{y})\n\ |
|
2925 This function is equivalent to @code{x ./ y}.\n\ |
|
2926 @end deftypefn") |
|
2927 { |
|
2928 BINARY_OP_DEFUN_BODY (op_el_div); |
|
2929 } |
|
2930 |
|
2931 DEFUN (power, args, , |
|
2932 "-*- texinfo -*-\n\ |
|
2933 @deftypefn {Built-in Function} {} power (@var{x}, @var{y})\n\ |
|
2934 This function is equivalent to @code{x .\\ y}.\n\ |
|
2935 @end deftypefn") |
|
2936 { |
|
2937 BINARY_OP_DEFUN_BODY (op_el_pow); |
|
2938 } |
|
2939 |
|
2940 DEFUN (ldivide, args, , |
|
2941 "-*- texinfo -*-\n\ |
|
2942 @deftypefn {Built-in Function} {} ldivide (@var{x}, @var{y})\n\ |
|
2943 @end deftypefn") |
|
2944 { |
|
2945 BINARY_OP_DEFUN_BODY (op_el_ldiv); |
|
2946 } |
|
2947 |
|
2948 DEFUN (and, args, , |
|
2949 "-*- texinfo -*-\n\ |
|
2950 @deftypefn {Built-in Function} {} and (@var{x}, @var{y})\n\ |
|
2951 This function is equivalent to @code{x & y}.\n\ |
|
2952 @end deftypefn") |
|
2953 { |
|
2954 BINARY_OP_DEFUN_BODY (op_el_and); |
|
2955 } |
|
2956 |
|
2957 DEFUN (or, args, , |
|
2958 "-*- texinfo -*-\n\ |
|
2959 @deftypefn {Built-in Function} {} or (@var{x}, @var{y})\n\ |
|
2960 This function is equivalent to @code{x | y}.\n\ |
|
2961 @end deftypefn") |
|
2962 { |
|
2963 BINARY_OP_DEFUN_BODY (op_el_or); |
|
2964 } |
|
2965 |
523
|
2966 /* |
|
2967 ;;; Local Variables: *** |
|
2968 ;;; mode: C++ *** |
|
2969 ;;; End: *** |
|
2970 */ |