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