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 |
1315
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
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 |
1352
|
36 #include "defun.h" |
|
37 #include "error.h" |
|
38 #include "gripes.h" |
2366
|
39 #include "ov.h" |
|
40 #include "variables.h" |
1742
|
41 #include "oct-obj.h" |
523
|
42 #include "utils.h" |
4806
|
43 #include "Cell.h" |
|
44 #include "oct-map.h" |
523
|
45 |
4015
|
46 #define ANY_ALL(FCN) \ |
|
47 \ |
4233
|
48 octave_value retval; \ |
4015
|
49 \ |
|
50 int nargin = args.length (); \ |
|
51 \ |
4021
|
52 if (nargin == 1 || nargin == 2) \ |
4015
|
53 { \ |
4021
|
54 int dim = (nargin == 1 ? -1 : args(1).int_value (true) - 1); \ |
|
55 \ |
|
56 if (! error_state) \ |
|
57 { \ |
4556
|
58 if (dim >= -1) \ |
4015
|
59 retval = args(0).FCN (dim); \ |
4021
|
60 else \ |
|
61 error (#FCN ": invalid dimension argument = %d", dim + 1); \ |
|
62 } \ |
4015
|
63 else \ |
4021
|
64 error (#FCN ": expecting dimension argument to be an integer"); \ |
4015
|
65 } \ |
4021
|
66 else \ |
|
67 print_usage (#FCN); \ |
4015
|
68 \ |
|
69 return retval |
|
70 |
1957
|
71 DEFUN (all, args, , |
3369
|
72 "-*- texinfo -*-\n\ |
4015
|
73 @deftypefn {Built-in Function} {} all (@var{x}, @var{dim})\n\ |
3369
|
74 The function @code{all} behaves like the function @code{any}, except\n\ |
|
75 that it returns true only if all the elements of a vector, or all the\n\ |
4015
|
76 elements along dimension @var{dim} of a matrix, are nonzero.\n\ |
3369
|
77 @end deftypefn") |
523
|
78 { |
4015
|
79 ANY_ALL (all); |
523
|
80 } |
|
81 |
1957
|
82 DEFUN (any, args, , |
3369
|
83 "-*- texinfo -*-\n\ |
4015
|
84 @deftypefn {Built-in Function} {} any (@var{x}, @var{dim})\n\ |
3369
|
85 For a vector argument, return 1 if any element of the vector is\n\ |
|
86 nonzero.\n\ |
|
87 \n\ |
|
88 For a matrix argument, return a row vector of ones and\n\ |
|
89 zeros with each element indicating whether any of the elements of the\n\ |
|
90 corresponding column of the matrix are nonzero. For example,\n\ |
|
91 \n\ |
|
92 @example\n\ |
|
93 @group\n\ |
|
94 any (eye (2, 4))\n\ |
|
95 @result{} [ 1, 1, 0, 0 ]\n\ |
|
96 @end group\n\ |
|
97 @end example\n\ |
|
98 \n\ |
4015
|
99 If the optional argument @var{dim} is supplied, work along dimension\n\ |
|
100 @var{dim}. For example,\n\ |
3369
|
101 \n\ |
|
102 @example\n\ |
4015
|
103 @group\n\ |
|
104 any (eye (2, 4), 2)\n\ |
|
105 @result{} [ 1; 1 ]\n\ |
|
106 @end group\n\ |
3369
|
107 @end example\n\ |
|
108 @end deftypefn") |
523
|
109 { |
4015
|
110 ANY_ALL (any); |
523
|
111 } |
|
112 |
649
|
113 // These mapping functions may also be useful in other places, eh? |
|
114 |
|
115 typedef double (*d_dd_fcn) (double, double); |
|
116 |
|
117 static Matrix |
2672
|
118 map_d_m (d_dd_fcn f, double x, const Matrix& y) |
649
|
119 { |
|
120 int nr = y.rows (); |
|
121 int nc = y.columns (); |
|
122 |
|
123 Matrix retval (nr, nc); |
|
124 |
|
125 for (int j = 0; j < nc; j++) |
|
126 for (int i = 0; i < nr; i++) |
4153
|
127 { |
|
128 OCTAVE_QUIT; |
|
129 retval (i, j) = f (x, y (i, j)); |
|
130 } |
649
|
131 |
|
132 return retval; |
|
133 } |
|
134 |
|
135 static Matrix |
2672
|
136 map_m_d (d_dd_fcn f, const Matrix& x, double y) |
649
|
137 { |
|
138 int nr = x.rows (); |
|
139 int nc = x.columns (); |
|
140 |
|
141 Matrix retval (nr, nc); |
|
142 |
|
143 for (int j = 0; j < nc; j++) |
|
144 for (int i = 0; i < nr; i++) |
4153
|
145 { |
|
146 OCTAVE_QUIT; |
|
147 retval (i, j) = f (x (i, j), y); |
|
148 } |
649
|
149 |
|
150 return retval; |
|
151 } |
|
152 |
|
153 static Matrix |
2672
|
154 map_m_m (d_dd_fcn f, const Matrix& x, const Matrix& y) |
649
|
155 { |
|
156 int x_nr = x.rows (); |
|
157 int x_nc = x.columns (); |
|
158 |
|
159 int y_nr = y.rows (); |
|
160 int y_nc = y.columns (); |
|
161 |
719
|
162 assert (x_nr == y_nr && x_nc == y_nc); |
649
|
163 |
|
164 Matrix retval (x_nr, x_nc); |
|
165 |
|
166 for (int j = 0; j < x_nc; j++) |
|
167 for (int i = 0; i < x_nr; i++) |
4153
|
168 { |
|
169 OCTAVE_QUIT; |
|
170 retval (i, j) = f (x (i, j), y (i, j)); |
|
171 } |
649
|
172 |
|
173 return retval; |
|
174 } |
|
175 |
1957
|
176 DEFUN (atan2, args, , |
3428
|
177 "-*- texinfo -*-\n\ |
|
178 @deftypefn {Mapping Function} {} atan2 (@var{y}, @var{x})\n\ |
|
179 Compute atan (@var{y} / @var{x}) for corresponding elements of @var{y}\n\ |
|
180 and @var{x}. The result is in range -pi to pi.\n\ |
3439
|
181 @end deftypefn") |
649
|
182 { |
4233
|
183 octave_value retval; |
649
|
184 |
712
|
185 int nargin = args.length (); |
|
186 |
|
187 if (nargin == 2 && args(0).is_defined () && args(1).is_defined ()) |
649
|
188 { |
2086
|
189 octave_value arg_y = args(0); |
|
190 octave_value arg_x = args(1); |
649
|
191 |
|
192 int y_nr = arg_y.rows (); |
|
193 int y_nc = arg_y.columns (); |
|
194 |
|
195 int x_nr = arg_x.rows (); |
|
196 int x_nc = arg_x.columns (); |
|
197 |
|
198 int arg_y_empty = empty_arg ("atan2", y_nr, y_nc); |
|
199 int arg_x_empty = empty_arg ("atan2", x_nr, x_nc); |
|
200 |
719
|
201 if (arg_y_empty > 0 && arg_x_empty > 0) |
4233
|
202 return octave_value (Matrix ()); |
719
|
203 else if (arg_y_empty || arg_x_empty) |
649
|
204 return retval; |
|
205 |
|
206 int y_is_scalar = (y_nr == 1 && y_nc == 1); |
|
207 int x_is_scalar = (x_nr == 1 && x_nc == 1); |
|
208 |
|
209 if (y_is_scalar && x_is_scalar) |
|
210 { |
|
211 double y = arg_y.double_value (); |
|
212 |
|
213 if (! error_state) |
|
214 { |
|
215 double x = arg_x.double_value (); |
|
216 |
|
217 if (! error_state) |
|
218 retval = atan2 (y, x); |
|
219 } |
|
220 } |
|
221 else if (y_is_scalar) |
|
222 { |
|
223 double y = arg_y.double_value (); |
|
224 |
|
225 if (! error_state) |
|
226 { |
|
227 Matrix x = arg_x.matrix_value (); |
|
228 |
|
229 if (! error_state) |
2672
|
230 retval = map_d_m (atan2, y, x); |
649
|
231 } |
|
232 } |
|
233 else if (x_is_scalar) |
|
234 { |
|
235 Matrix y = arg_y.matrix_value (); |
|
236 |
|
237 if (! error_state) |
|
238 { |
|
239 double x = arg_x.double_value (); |
|
240 |
|
241 if (! error_state) |
2672
|
242 retval = map_m_d (atan2, y, x); |
649
|
243 } |
|
244 } |
|
245 else if (y_nr == x_nr && y_nc == x_nc) |
|
246 { |
|
247 Matrix y = arg_y.matrix_value (); |
|
248 |
|
249 if (! error_state) |
|
250 { |
|
251 Matrix x = arg_x.matrix_value (); |
|
252 |
|
253 if (! error_state) |
2672
|
254 retval = map_m_m (atan2, y, x); |
649
|
255 } |
|
256 } |
|
257 else |
|
258 error ("atan2: nonconformant matrices"); |
|
259 } |
712
|
260 else |
|
261 print_usage ("atan2"); |
649
|
262 |
|
263 return retval; |
|
264 } |
|
265 |
4311
|
266 DEFUN (fmod, args, , |
|
267 "-*- texinfo -*-\n\ |
|
268 @deftypefn {Mapping Function} {} fmod (@var{x}, @var{y})\n\ |
4685
|
269 Compute the floating point remainder of dividing @var{x} by @var{y}\n\ |
|
270 using the C library function @code{fmod}. The result has the same\n\ |
|
271 sign as @var{x}. If @var{y} is zero, the result implementation-defined.\n\ |
4311
|
272 @end deftypefn") |
|
273 { |
|
274 octave_value retval; |
|
275 |
|
276 int nargin = args.length (); |
|
277 |
|
278 if (nargin == 2 && args(0).is_defined () && args(1).is_defined ()) |
|
279 { |
|
280 octave_value arg_x = args(0); |
|
281 octave_value arg_y = args(1); |
|
282 |
|
283 int y_nr = arg_y.rows (); |
|
284 int y_nc = arg_y.columns (); |
|
285 |
|
286 int x_nr = arg_x.rows (); |
|
287 int x_nc = arg_x.columns (); |
|
288 |
|
289 int arg_y_empty = empty_arg ("fmod", y_nr, y_nc); |
|
290 int arg_x_empty = empty_arg ("fmod", x_nr, x_nc); |
|
291 |
|
292 if (arg_y_empty > 0 && arg_x_empty > 0) |
|
293 return octave_value (Matrix ()); |
|
294 else if (arg_y_empty || arg_x_empty) |
|
295 return retval; |
|
296 |
|
297 int y_is_scalar = (y_nr == 1 && y_nc == 1); |
|
298 int x_is_scalar = (x_nr == 1 && x_nc == 1); |
|
299 |
|
300 if (y_is_scalar && x_is_scalar) |
|
301 { |
|
302 double y = arg_y.double_value (); |
|
303 |
|
304 if (! error_state) |
|
305 { |
|
306 double x = arg_x.double_value (); |
|
307 |
|
308 if (! error_state) |
|
309 retval = fmod (x, y); |
|
310 } |
|
311 } |
|
312 else if (y_is_scalar) |
|
313 { |
|
314 double y = arg_y.double_value (); |
|
315 |
|
316 if (! error_state) |
|
317 { |
|
318 Matrix x = arg_x.matrix_value (); |
|
319 |
|
320 if (! error_state) |
|
321 retval = map_m_d (fmod, x, y); |
|
322 } |
|
323 } |
|
324 else if (x_is_scalar) |
|
325 { |
|
326 Matrix y = arg_y.matrix_value (); |
|
327 |
|
328 if (! error_state) |
|
329 { |
|
330 double x = arg_x.double_value (); |
|
331 |
|
332 if (! error_state) |
|
333 retval = map_d_m (fmod, x, y); |
|
334 } |
|
335 } |
|
336 else if (y_nr == x_nr && y_nc == x_nc) |
|
337 { |
|
338 Matrix y = arg_y.matrix_value (); |
|
339 |
|
340 if (! error_state) |
|
341 { |
|
342 Matrix x = arg_x.matrix_value (); |
|
343 |
|
344 if (! error_state) |
|
345 retval = map_m_m (fmod, x, y); |
|
346 } |
|
347 } |
|
348 else |
|
349 error ("fmod: nonconformant matrices"); |
|
350 } |
|
351 else |
|
352 print_usage ("fmod"); |
|
353 |
|
354 return retval; |
|
355 } |
|
356 |
3723
|
357 #define DATA_REDUCTION(FCN) \ |
|
358 \ |
4233
|
359 octave_value retval; \ |
3723
|
360 \ |
|
361 int nargin = args.length (); \ |
|
362 \ |
|
363 if (nargin == 1 || nargin == 2) \ |
|
364 { \ |
|
365 octave_value arg = args(0); \ |
|
366 \ |
3864
|
367 int dim = (nargin == 1 ? -1 : args(1).int_value (true) - 1); \ |
3723
|
368 \ |
|
369 if (! error_state) \ |
|
370 { \ |
4556
|
371 if (dim >= -1) \ |
3723
|
372 { \ |
|
373 if (arg.is_real_type ()) \ |
|
374 { \ |
4569
|
375 NDArray tmp = arg.array_value (); \ |
3723
|
376 \ |
|
377 if (! error_state) \ |
4233
|
378 retval = tmp.FCN (dim); \ |
3723
|
379 } \ |
|
380 else if (arg.is_complex_type ()) \ |
|
381 { \ |
4569
|
382 ComplexNDArray tmp = arg.complex_array_value (); \ |
3723
|
383 \ |
|
384 if (! error_state) \ |
4233
|
385 retval = tmp.FCN (dim); \ |
3723
|
386 } \ |
|
387 else \ |
|
388 { \ |
|
389 gripe_wrong_type_arg (#FCN, arg); \ |
|
390 return retval; \ |
|
391 } \ |
|
392 } \ |
|
393 else \ |
|
394 error (#FCN ": invalid dimension argument = %d", dim + 1); \ |
|
395 } \ |
|
396 } \ |
|
397 else \ |
|
398 print_usage (#FCN); \ |
|
399 \ |
|
400 return retval |
|
401 |
1957
|
402 DEFUN (cumprod, args, , |
3428
|
403 "-*- texinfo -*-\n\ |
3723
|
404 @deftypefn {Built-in Function} {} cumprod (@var{x}, @var{dim})\n\ |
|
405 Cumulative product of elements along dimension @var{dim}. If\n\ |
|
406 @var{dim} is omitted, it defaults to 1 (column-wise cumulative\n\ |
|
407 products).\n\ |
3428
|
408 @end deftypefn") |
523
|
409 { |
3723
|
410 DATA_REDUCTION (cumprod); |
523
|
411 } |
|
412 |
1957
|
413 DEFUN (cumsum, args, , |
3428
|
414 "-*- texinfo -*-\n\ |
3723
|
415 @deftypefn {Built-in Function} {} cumsum (@var{x}, @var{dim})\n\ |
|
416 Cumulative sum of elements along dimension @var{dim}. If @var{dim}\n\ |
|
417 is omitted, it defaults to 1 (column-wise cumulative sums).\n\ |
3428
|
418 @end deftypefn") |
523
|
419 { |
3723
|
420 DATA_REDUCTION (cumsum); |
523
|
421 } |
|
422 |
3972
|
423 // XXX FIXME XXX -- we could eliminate some duplicate code here with |
|
424 // some template functions or macros. |
|
425 |
2086
|
426 static octave_value |
767
|
427 make_diag (const Matrix& v, int k) |
|
428 { |
|
429 int nr = v.rows (); |
|
430 int nc = v.columns (); |
|
431 assert (nc == 1 || nr == 1); |
|
432 |
2086
|
433 octave_value retval; |
767
|
434 |
|
435 int roff = 0; |
|
436 int coff = 0; |
|
437 if (k > 0) |
|
438 { |
|
439 roff = 0; |
|
440 coff = k; |
|
441 } |
|
442 else if (k < 0) |
|
443 { |
|
444 roff = -k; |
|
445 coff = 0; |
|
446 } |
|
447 |
|
448 if (nr == 1) |
|
449 { |
4479
|
450 int n = nc + std::abs (k); |
767
|
451 Matrix m (n, n, 0.0); |
|
452 for (int i = 0; i < nc; i++) |
2305
|
453 m (i+roff, i+coff) = v (0, i); |
4233
|
454 retval = m; |
767
|
455 } |
|
456 else |
|
457 { |
4479
|
458 int n = nr + std::abs (k); |
767
|
459 Matrix m (n, n, 0.0); |
|
460 for (int i = 0; i < nr; i++) |
2305
|
461 m (i+roff, i+coff) = v (i, 0); |
4233
|
462 retval = m; |
767
|
463 } |
|
464 |
|
465 return retval; |
|
466 } |
|
467 |
2086
|
468 static octave_value |
767
|
469 make_diag (const ComplexMatrix& v, int k) |
|
470 { |
|
471 int nr = v.rows (); |
|
472 int nc = v.columns (); |
|
473 assert (nc == 1 || nr == 1); |
|
474 |
2086
|
475 octave_value retval; |
767
|
476 |
|
477 int roff = 0; |
|
478 int coff = 0; |
|
479 if (k > 0) |
|
480 { |
|
481 roff = 0; |
|
482 coff = k; |
|
483 } |
|
484 else if (k < 0) |
|
485 { |
|
486 roff = -k; |
|
487 coff = 0; |
|
488 } |
|
489 |
|
490 if (nr == 1) |
|
491 { |
4479
|
492 int n = nc + std::abs (k); |
767
|
493 ComplexMatrix m (n, n, 0.0); |
|
494 for (int i = 0; i < nc; i++) |
2305
|
495 m (i+roff, i+coff) = v (0, i); |
4233
|
496 retval = m; |
767
|
497 } |
|
498 else |
|
499 { |
4479
|
500 int n = nr + std::abs (k); |
767
|
501 ComplexMatrix m (n, n, 0.0); |
|
502 for (int i = 0; i < nr; i++) |
2305
|
503 m (i+roff, i+coff) = v (i, 0); |
4233
|
504 retval = m; |
767
|
505 } |
|
506 |
|
507 return retval; |
|
508 } |
|
509 |
2086
|
510 static octave_value |
|
511 make_diag (const octave_value& arg) |
767
|
512 { |
2086
|
513 octave_value retval; |
767
|
514 |
|
515 if (arg.is_real_type ()) |
|
516 { |
|
517 Matrix m = arg.matrix_value (); |
|
518 |
|
519 if (! error_state) |
|
520 { |
|
521 int nr = m.rows (); |
|
522 int nc = m.columns (); |
|
523 |
|
524 if (nr == 0 || nc == 0) |
|
525 retval = Matrix (); |
|
526 else if (nr == 1 || nc == 1) |
|
527 retval = make_diag (m, 0); |
|
528 else |
|
529 { |
|
530 ColumnVector v = m.diag (); |
|
531 if (v.capacity () > 0) |
|
532 retval = v; |
|
533 } |
|
534 } |
|
535 else |
|
536 gripe_wrong_type_arg ("diag", arg); |
|
537 } |
|
538 else if (arg.is_complex_type ()) |
|
539 { |
|
540 ComplexMatrix cm = arg.complex_matrix_value (); |
|
541 |
|
542 if (! error_state) |
|
543 { |
|
544 int nr = cm.rows (); |
|
545 int nc = cm.columns (); |
|
546 |
|
547 if (nr == 0 || nc == 0) |
|
548 retval = Matrix (); |
|
549 else if (nr == 1 || nc == 1) |
|
550 retval = make_diag (cm, 0); |
|
551 else |
|
552 { |
|
553 ComplexColumnVector v = cm.diag (); |
|
554 if (v.capacity () > 0) |
|
555 retval = v; |
|
556 } |
|
557 } |
|
558 else |
|
559 gripe_wrong_type_arg ("diag", arg); |
|
560 } |
|
561 else |
|
562 gripe_wrong_type_arg ("diag", arg); |
|
563 |
|
564 return retval; |
|
565 } |
|
566 |
2086
|
567 static octave_value |
|
568 make_diag (const octave_value& a, const octave_value& b) |
767
|
569 { |
2086
|
570 octave_value retval; |
767
|
571 |
4732
|
572 int k = b.int_value (); |
767
|
573 |
|
574 if (error_state) |
|
575 { |
|
576 error ("diag: invalid second argument"); |
|
577 return retval; |
|
578 } |
|
579 |
|
580 if (a.is_real_type ()) |
|
581 { |
3307
|
582 Matrix m = a.matrix_value (); |
767
|
583 |
3307
|
584 if (! error_state) |
767
|
585 { |
|
586 int nr = m.rows (); |
|
587 int nc = m.columns (); |
|
588 |
3972
|
589 if (nr == 1 || nc == 1) |
|
590 retval = make_diag (m, k); |
|
591 else if (nr == 0 || nc == 0) |
767
|
592 retval = Matrix (); |
|
593 else |
|
594 { |
|
595 ColumnVector d = m.diag (k); |
|
596 retval = d; |
|
597 } |
|
598 } |
|
599 } |
|
600 else if (a.is_complex_type ()) |
|
601 { |
3307
|
602 ComplexMatrix cm = a.complex_matrix_value (); |
767
|
603 |
3307
|
604 if (! error_state) |
767
|
605 { |
|
606 int nr = cm.rows (); |
|
607 int nc = cm.columns (); |
|
608 |
3972
|
609 if (nr == 1 || nc == 1) |
|
610 retval = make_diag (cm, k); |
|
611 else if (nr == 0 || nc == 0) |
767
|
612 retval = Matrix (); |
|
613 else |
|
614 { |
|
615 ComplexColumnVector d = cm.diag (k); |
|
616 retval = d; |
|
617 } |
|
618 } |
|
619 } |
|
620 else |
|
621 gripe_wrong_type_arg ("diag", a); |
|
622 |
|
623 return retval; |
|
624 } |
|
625 |
1957
|
626 DEFUN (diag, args, , |
3369
|
627 "-*- texinfo -*-\n\ |
|
628 @deftypefn {Built-in Function} {} diag (@var{v}, @var{k})\n\ |
|
629 Return a diagonal matrix with vector @var{v} on diagonal @var{k}. The\n\ |
|
630 second argument is optional. If it is positive, the vector is placed on\n\ |
|
631 the @var{k}-th super-diagonal. If it is negative, it is placed on the\n\ |
|
632 @var{-k}-th sub-diagonal. The default value of @var{k} is 0, and the\n\ |
|
633 vector is placed on the main diagonal. For example,\n\ |
|
634 \n\ |
|
635 @example\n\ |
|
636 @group\n\ |
|
637 diag ([1, 2, 3], 1)\n\ |
|
638 @result{} 0 1 0 0\n\ |
|
639 0 0 2 0\n\ |
|
640 0 0 0 3\n\ |
|
641 0 0 0 0\n\ |
|
642 @end group\n\ |
|
643 @end example\n\ |
|
644 @end deftypefn") |
523
|
645 { |
4233
|
646 octave_value retval; |
523
|
647 |
|
648 int nargin = args.length (); |
|
649 |
712
|
650 if (nargin == 1 && args(0).is_defined ()) |
767
|
651 retval = make_diag (args(0)); |
712
|
652 else if (nargin == 2 && args(0).is_defined () && args(1).is_defined ()) |
767
|
653 retval = make_diag (args(0), args(1)); |
523
|
654 else |
|
655 print_usage ("diag"); |
|
656 |
|
657 return retval; |
|
658 } |
|
659 |
1957
|
660 DEFUN (prod, args, , |
3428
|
661 "-*- texinfo -*-\n\ |
3723
|
662 @deftypefn {Built-in Function} {} prod (@var{x}, @var{dim})\n\ |
|
663 Product of elements along dimension @var{dim}. If @var{dim} is\n\ |
|
664 omitted, it defaults to 1 (column-wise products).\n\ |
3428
|
665 @end deftypefn") |
523
|
666 { |
3723
|
667 DATA_REDUCTION (prod); |
523
|
668 } |
|
669 |
4758
|
670 static bool |
|
671 cat_add_dims (dim_vector& dv_new, const dim_vector& dv_arg, int dim) |
|
672 { |
|
673 // dv_arg is [] |
4768
|
674 |
4758
|
675 if (dv_arg.all_zero ()) |
|
676 return true; |
|
677 |
|
678 // dv_new is [] |
4768
|
679 |
4758
|
680 if (dv_new.all_zero ()) |
|
681 { |
|
682 dv_new = dv_arg; |
|
683 return true; |
|
684 } |
|
685 |
|
686 int n_new = dv_new.length (); |
|
687 int n_args = dv_arg.length (); |
|
688 |
|
689 // Find the max and min value of n_new and n_args |
4768
|
690 |
4758
|
691 int n_max = n_new > n_args ? n_new : n_args; |
|
692 int n_min = n_new < n_args ? n_new : n_args; |
|
693 |
|
694 // The elements of the dimension vectors can only differ |
|
695 // if the dim variable differs from the actual dimension |
|
696 // they differ. |
4768
|
697 |
4758
|
698 for (int i = 0; i < n_min; i++) |
|
699 { |
|
700 if (dv_new(i) != dv_arg(i) && dim != i) |
|
701 { |
|
702 error ("cat: dimension mismatch"); |
|
703 return false; |
|
704 } |
|
705 } |
|
706 |
4768
|
707 // Ditto. |
|
708 |
4758
|
709 for (int i = n_min; i < n_max; i++) |
|
710 { |
|
711 if (n_new > n_min) |
|
712 { |
|
713 if (dv_new(i) != 1 && dim != i) |
|
714 { |
|
715 error ("cat: dimension mismatch"); |
|
716 return false; |
|
717 } |
|
718 } |
|
719 else |
|
720 { |
|
721 if (dv_arg(i) != 1 && dim != i) |
|
722 { |
|
723 error ("cat: dimension mismatch"); |
|
724 return false; |
|
725 } |
|
726 } |
|
727 } |
|
728 |
|
729 // If we want to add the dimension vectors at a dimension |
|
730 // larger than both, then we need to set n_max to this number |
|
731 // so that we resize dv_new to the right dimension. |
4768
|
732 |
4758
|
733 n_max = n_max > (dim + 1) ? n_max : (dim + 1); |
|
734 |
|
735 // Resize dv_new to new the appropriate dimensions. |
4768
|
736 |
4758
|
737 if (n_max > n_new) |
|
738 { |
|
739 dv_new.resize (n_max); |
|
740 |
|
741 for (int i = n_new; i < n_max; i++) |
|
742 dv_new.elem (i) = 1; |
|
743 } |
|
744 |
4768
|
745 // Larger or equal since dim has been decremented by one. |
|
746 |
|
747 if (dim >= n_args) |
4758
|
748 dv_new.elem (dim) = dv_new.elem (dim)++; |
|
749 else |
|
750 dv_new.elem (dim) += dv_arg(dim); |
|
751 |
|
752 return true; |
|
753 } |
|
754 |
4824
|
755 static octave_value |
|
756 do_cat (const octave_value_list& args, std::string fname) |
4806
|
757 { |
|
758 octave_value retval; |
|
759 |
4824
|
760 int n_args = args.length (); |
4806
|
761 |
4824
|
762 if (n_args > 2) |
|
763 { |
|
764 int dim = args(0).int_value () - 1; |
4806
|
765 |
4824
|
766 if (error_state) |
4806
|
767 { |
4824
|
768 error ("cat: expecting first argument to be a integer"); |
4806
|
769 return retval; |
|
770 } |
|
771 |
4824
|
772 if (dim >= 0) |
|
773 { |
|
774 |
|
775 dim_vector dv = args(1).dims (); |
|
776 |
|
777 for (int i = 2; i < args.length (); i++) |
|
778 { |
|
779 // add_dims constructs a dimension vector which holds the |
|
780 // dimensions of the final array after concatenation. |
4806
|
781 |
4824
|
782 if (! cat_add_dims (dv, args(i).dims (), dim)) |
4806
|
783 { |
4824
|
784 // Dimensions do not match. |
|
785 // cat_add_dims printed a error msg |
4806
|
786 return retval; |
|
787 } |
4824
|
788 } |
|
789 |
|
790 NDArray cat_re; |
|
791 ComplexNDArray cat_cx; |
|
792 charNDArray cat_ch; |
|
793 Cell cat_cell; |
|
794 Octave_map cat_map; |
|
795 |
|
796 // The final array can be of three types: |
|
797 // |
|
798 // re cx ch c |
|
799 // ---------------- |
|
800 // re |re cx ch X |
|
801 // cx |cx cx X X |
|
802 // ch |ch X ch X |
|
803 // cell |X X X c |
|
804 // (X means incompatible). |
|
805 |
|
806 enum types { REAL, COMPLEX, CHAR, CELL, MAP} t; |
|
807 |
|
808 // Initialize t to right value |
|
809 if (args(1).is_cell ()) |
|
810 { |
|
811 t = CELL; |
|
812 cat_cell = Cell (dv); |
|
813 } |
|
814 else if (args(1).is_map ()) |
|
815 { |
|
816 error ("concatenation of structures is not yet implemented"); |
|
817 return retval; |
|
818 // t = MAP; |
|
819 // cat_map = Octave_map (dv); |
|
820 } |
|
821 else |
|
822 { |
|
823 t = REAL; |
|
824 cat_re = NDArray (dv, 0); |
|
825 } |
|
826 |
|
827 int idx = 0; |
|
828 |
|
829 dim_vector dv_first = args(1).dims (); |
|
830 |
|
831 // n_moves tells us how many times we need to |
|
832 // visit each argument. |
|
833 // |
|
834 // If we are concatenating a 2x2x2 array with a 2x2x2 array |
|
835 // along the second dimensions, we do two iterations |
|
836 // trough the arguments and move 2x2 elements from each |
|
837 // of the arguments into the resulting array on each iteration. |
|
838 int n_moves = 1; |
|
839 |
|
840 for (int i = dim + 1; i < dv_first.length (); i++) |
|
841 n_moves *= dv_first(i); |
|
842 |
|
843 for (int move = 0; move < n_moves ; move++) |
|
844 { |
|
845 for (int i = 1; i < n_args; i++) |
4806
|
846 { |
4824
|
847 octave_value tmp = args (i); |
|
848 |
|
849 if (t == MAP) |
4806
|
850 { |
4824
|
851 error ("concatenation of structures is not yet implemented"); |
4806
|
852 return retval; |
|
853 } |
4824
|
854 else if (t == CELL) |
4806
|
855 { |
4824
|
856 if (! tmp.is_cell ()) |
|
857 { |
|
858 error ("cannot convert argument to cell"); |
|
859 return retval; |
|
860 } |
|
861 else |
|
862 { |
|
863 Cell ra_tmp = args(i).cell_value (); |
4806
|
864 |
4824
|
865 if (error_state) |
|
866 return retval; |
|
867 |
|
868 idx = cat_cell.cat (ra_tmp, dim, idx, move); |
|
869 } |
|
870 } |
|
871 else if (t == REAL) |
|
872 { |
|
873 if (tmp.is_complex_type ()) |
|
874 { |
|
875 cat_cx = ComplexNDArray (cat_re); |
|
876 |
|
877 ComplexNDArray ra_tmp = tmp.complex_array_value (); |
|
878 |
|
879 if (error_state) |
|
880 return retval; |
|
881 |
|
882 idx = cat_cx.cat (ra_tmp, dim, idx, move); |
4806
|
883 |
4824
|
884 t = COMPLEX; |
|
885 } |
|
886 else if (tmp.is_string ()) |
|
887 { |
|
888 // This is a hack to be able to convert a dNDArray |
|
889 // to a chNDArray. |
|
890 |
|
891 cat_ch = charNDArray (octave_value (cat_re).char_array_value ()); |
|
892 |
|
893 charNDArray ra_tmp = tmp.char_array_value (); |
|
894 |
|
895 if (error_state) |
|
896 return retval; |
|
897 |
|
898 idx = cat_ch.cat (ra_tmp, dim, idx, move); |
|
899 |
|
900 t = CHAR; |
|
901 } |
|
902 else //if (tmp.is_real_type ()) |
|
903 { |
|
904 NDArray ra_tmp = tmp.array_value (); |
|
905 |
|
906 if (error_state) |
|
907 return retval; |
|
908 |
|
909 idx = cat_re.cat (ra_tmp, dim, idx, move); |
|
910 } |
4806
|
911 } |
4824
|
912 else if (t == COMPLEX) |
4806
|
913 { |
|
914 ComplexNDArray ra_tmp = tmp.complex_array_value (); |
|
915 |
|
916 if (error_state) |
|
917 return retval; |
|
918 |
|
919 idx = cat_cx.cat (ra_tmp, dim, idx, move); |
|
920 } |
4824
|
921 else if (t == CHAR) |
4806
|
922 { |
4824
|
923 if (tmp.is_complex_type ()) |
|
924 { |
|
925 error ("cannot convert complex type to character type"); |
|
926 return retval; |
|
927 } |
|
928 else |
|
929 { |
|
930 charNDArray ra_tmp = tmp.char_array_value (); |
4806
|
931 |
4824
|
932 if (error_state) |
|
933 return retval; |
4806
|
934 |
4824
|
935 cat_ch.cat (ra_tmp, dim, idx, move); |
|
936 } |
4806
|
937 } |
|
938 } |
|
939 } |
4824
|
940 |
|
941 if (t == REAL) |
|
942 retval = octave_value (cat_re); |
|
943 else if (t == COMPLEX) |
|
944 retval = octave_value (cat_cx); |
|
945 else if (t == CHAR) |
|
946 retval = octave_value (cat_ch); |
|
947 else if (t == CELL) |
|
948 retval = octave_value (cat_cell); |
|
949 else if (t == MAP) |
|
950 retval = octave_value (cat_map); |
4806
|
951 } |
4824
|
952 else print_usage (fname); |
4806
|
953 } |
|
954 else |
4824
|
955 print_usage (fname); |
4806
|
956 |
|
957 return retval; |
|
958 } |
|
959 |
|
960 DEFUN (horzcat, args, , |
4824
|
961 "-*- texinfo -*-\n\ |
4806
|
962 @deftypefn {Built-in Function} {} horzcat (@var{array1}, @var{array2}, @dots{}, @var{arrayN})\n\ |
|
963 Return the horizontal concatenation of N-d array objects, @var{array1},\n\ |
|
964 @var{array2}, @dots{}, @var{arrayN} along dimension 2.\n\ |
|
965 @end deftypefn\n\ |
|
966 @seealso{cat and vertcat}") |
|
967 { |
|
968 octave_value_list args_tmp = args; |
|
969 |
|
970 int dim = 2; |
|
971 |
|
972 octave_value d (dim); |
|
973 |
|
974 args_tmp.prepend (d); |
|
975 |
4824
|
976 return do_cat (args_tmp, "horzcat"); |
4806
|
977 } |
|
978 |
|
979 DEFUN (vertcat, args, , |
|
980 "-*- texinfo -*-\n\ |
|
981 @deftypefn {Built-in Function} {} vertcat (@var{array1}, @var{array2}, @dots{}, @var{arrayN})\n\ |
|
982 Return the vertical concatenation of N-d array objects, @var{array1},\n\ |
|
983 @var{array2}, @dots{}, @var{arrayN} along dimension 1.\n\ |
|
984 @end deftypefn\n\ |
|
985 @seealso{cat and horzcat}") |
|
986 { |
|
987 octave_value_list args_tmp = args; |
|
988 |
|
989 int dim = 1; |
|
990 |
|
991 octave_value d (dim); |
|
992 |
|
993 args_tmp.prepend (d); |
|
994 |
4824
|
995 return do_cat (args_tmp, "vertcat"); |
4806
|
996 } |
|
997 |
4758
|
998 DEFUN (cat, args, , |
|
999 "-*- texinfo -*-\n\ |
|
1000 @deftypefn {Built-in Function} {} cat (@var{dim}, @var{array1}, @var{array2}, @dots{}, @var{arrayN})\n\ |
4806
|
1001 Return the concatenation of N-d array objects, @var{array1},\n\ |
|
1002 @var{array2}, @dots{}, @var{arrayN} along dimension @var{dim}.\n\ |
4758
|
1003 \n\ |
|
1004 @example\n\ |
|
1005 @group\n\ |
|
1006 A = ones (2, 2);\n\ |
|
1007 B = zeros (2, 2);\n\ |
|
1008 cat (2, A, B)\n\ |
|
1009 @result{} ans =\n\ |
|
1010 \n\ |
|
1011 1 1 0 0\n\ |
|
1012 1 1 0 0\n\ |
|
1013 @end group\n\ |
|
1014 @end example\n\ |
|
1015 \n\ |
|
1016 Alternatively, we can concatenate @var{A} and @var{B} along the\n\ |
|
1017 second dimension the following way:\n\ |
|
1018 \n\ |
|
1019 @example\n\ |
|
1020 @group\n\ |
|
1021 [A, B].\n\ |
|
1022 @end group\n\ |
|
1023 @end example\n\ |
|
1024 \n\ |
|
1025 @var{dim} can be larger than the dimensions of the N-d array objects\n\ |
|
1026 and the result will thus have @var{dim} dimensions as the\n\ |
|
1027 following example shows:\n\ |
|
1028 @example\n\ |
|
1029 @group\n\ |
|
1030 cat (4, ones(2, 2), zeros (2, 2))\n\ |
|
1031 @result{} ans =\n\ |
|
1032 \n\ |
|
1033 ans(:,:,1,1) =\n\ |
|
1034 \n\ |
|
1035 1 1\n\ |
|
1036 1 1\n\ |
|
1037 \n\ |
|
1038 ans(:,:,1,2) =\n\ |
|
1039 0 0\n\ |
|
1040 0 0\n\ |
|
1041 @end group\n\ |
|
1042 @end example\n\ |
|
1043 \n\ |
4806
|
1044 @end deftypefn\n\ |
|
1045 @seealso{horzcat and vertcat}") |
4758
|
1046 { |
4824
|
1047 return do_cat (args, "cat"); |
4758
|
1048 } |
|
1049 |
4593
|
1050 static octave_value |
|
1051 do_permute (const octave_value_list& args, bool inv, const std::string& fname) |
|
1052 { |
|
1053 octave_value retval; |
|
1054 |
|
1055 if (args.length () == 2 && args(1).length () == args(0).dims ().length ()) |
|
1056 { |
|
1057 Array<int> vec = args(1).int_vector_value (); |
|
1058 |
|
1059 octave_value ret = args(0).permute (vec, inv); |
|
1060 |
|
1061 if (! error_state) |
|
1062 retval = ret; |
|
1063 } |
|
1064 else |
|
1065 print_usage (fname); |
|
1066 |
|
1067 return retval; |
|
1068 } |
|
1069 |
|
1070 DEFUN (permute, args, , |
|
1071 "-*- texinfo -*-\n\ |
|
1072 @deftypefn {Built-in Function} {} permute (@var{a}, @var{perm})\n\ |
|
1073 Return the generalized transpose for an N-d array object @var{a}.\n\ |
|
1074 The permutation vector @var{perm} must contain the elements\n\ |
|
1075 @code{1:ndims(a)} (in any order, but each element must appear just once).\n\ |
|
1076 \n\ |
|
1077 @end deftypefn\n\ |
|
1078 @seealso{ipermute}") |
|
1079 { |
|
1080 return do_permute (args, false, "permute"); |
|
1081 } |
|
1082 |
|
1083 DEFUN (ipermute, args, , |
|
1084 "-*- texinfo -*-\n\ |
|
1085 @deftypefn {Built-in Function} {} ipermute (@var{a}, @var{iperm})\n\ |
|
1086 The inverse of the @code{permute} function. The expression\n\ |
|
1087 \n\ |
|
1088 @example\n\ |
|
1089 ipermute (permute (a, perm), perm)\n\ |
|
1090 @end example\n\ |
|
1091 returns the original array @var{a}.\n\ |
|
1092 \n\ |
|
1093 @end deftypefn\n\ |
|
1094 @seealso{permute}") |
|
1095 { |
|
1096 return do_permute (args, true, "ipermute"); |
|
1097 } |
|
1098 |
3195
|
1099 DEFUN (length, args, , |
3373
|
1100 "-*- texinfo -*-\n\ |
|
1101 @deftypefn {Built-in Function} {} length (@var{a})\n\ |
4176
|
1102 Return the `length' of the object @var{a}. For matrix objects, the\n\ |
3373
|
1103 length is the number of rows or columns, whichever is greater (this\n\ |
|
1104 odd definition is used for compatibility with Matlab).\n\ |
|
1105 @end deftypefn") |
3195
|
1106 { |
|
1107 octave_value retval; |
|
1108 |
|
1109 if (args.length () == 1) |
|
1110 { |
|
1111 int len = args(0).length (); |
|
1112 |
|
1113 if (! error_state) |
4233
|
1114 retval = len; |
3195
|
1115 } |
|
1116 else |
|
1117 print_usage ("length"); |
|
1118 |
|
1119 return retval; |
|
1120 } |
|
1121 |
4554
|
1122 DEFUN (ndims, args, , |
|
1123 "-*- texinfo -*-\n\ |
|
1124 @deftypefn {Built-in Function} {} ndims (@var{a})\n\ |
|
1125 Returns the number of dimensions of array @var{a}.\n\ |
|
1126 For any array, the result will always be larger than or equal to 2.\n\ |
|
1127 Trailing singleton dimensions are not counted.\n\ |
|
1128 @end deftypefn") |
|
1129 { |
|
1130 octave_value retval; |
|
1131 |
|
1132 if (args.length () == 1) |
|
1133 { |
|
1134 int n_dims = args(0).ndims (); |
|
1135 |
|
1136 if (! error_state) |
|
1137 retval = n_dims; |
|
1138 } |
|
1139 else |
|
1140 print_usage ("ndims"); |
|
1141 |
|
1142 return retval; |
|
1143 } |
|
1144 |
4559
|
1145 DEFUN (numel, args, , |
|
1146 "-*- texinfo -*-\n\ |
|
1147 @deftypefn {Built-in Function} {} numel (@var{a})\n\ |
|
1148 Returns the number of elements in the object @var{a}.\n\ |
|
1149 @end deftypefn") |
|
1150 { |
|
1151 octave_value retval; |
|
1152 |
|
1153 if (args.length () == 1) |
|
1154 { |
|
1155 int numel = args(0).numel (); |
|
1156 |
|
1157 if (! error_state) |
|
1158 { |
|
1159 if (numel < 0) |
|
1160 numel = 0; |
|
1161 |
|
1162 retval = numel; |
|
1163 } |
|
1164 } |
|
1165 else |
|
1166 print_usage ("numel"); |
|
1167 |
|
1168 return retval; |
|
1169 } |
|
1170 |
1957
|
1171 DEFUN (size, args, nargout, |
3373
|
1172 "-*- texinfo -*-\n\ |
|
1173 @deftypefn {Built-in Function} {} size (@var{a}, @var{n})\n\ |
|
1174 Return the number rows and columns of @var{a}.\n\ |
|
1175 \n\ |
|
1176 With one input argument and one output argument, the result is returned\n\ |
4741
|
1177 in a row vector. If there are multiple output arguments, the number of\n\ |
|
1178 rows is assigned to the first, and the number of columns to the second,\n\ |
|
1179 etc. For example,\n\ |
3373
|
1180 \n\ |
|
1181 @example\n\ |
|
1182 @group\n\ |
|
1183 size ([1, 2; 3, 4; 5, 6])\n\ |
|
1184 @result{} [ 3, 2 ]\n\ |
1031
|
1185 \n\ |
3373
|
1186 [nr, nc] = size ([1, 2; 3, 4; 5, 6])\n\ |
|
1187 @result{} nr = 3\n\ |
|
1188 @result{} nc = 2\n\ |
|
1189 @end group\n\ |
|
1190 @end example\n\ |
|
1191 \n\ |
4741
|
1192 If given a second argument, @code{size} will return the size of the\n\ |
|
1193 corresponding dimension. For example\n\ |
1031
|
1194 \n\ |
3373
|
1195 @example\n\ |
|
1196 size ([1, 2; 3, 4; 5, 6], 2)\n\ |
|
1197 @result{} 2\n\ |
|
1198 @end example\n\ |
|
1199 \n\ |
|
1200 @noindent\n\ |
|
1201 returns the number of columns in the given matrix.\n\ |
|
1202 @end deftypefn") |
523
|
1203 { |
2086
|
1204 octave_value_list retval; |
523
|
1205 |
|
1206 int nargin = args.length (); |
|
1207 |
4513
|
1208 if (nargin == 1) |
523
|
1209 { |
4513
|
1210 dim_vector dimensions = args(0).dims (); |
|
1211 |
|
1212 int ndims = dimensions.length (); |
1031
|
1213 |
4513
|
1214 Matrix m (1, ndims); |
|
1215 |
|
1216 if (nargout > 1) |
523
|
1217 { |
4513
|
1218 while (ndims--) |
|
1219 retval(ndims) = dimensions(ndims); |
523
|
1220 } |
4513
|
1221 else |
712
|
1222 { |
4513
|
1223 for (int i = 0; i < ndims; i++) |
|
1224 m(0, i) = dimensions(i); |
|
1225 |
|
1226 retval(0) = m; |
712
|
1227 } |
1031
|
1228 } |
|
1229 else if (nargin == 2 && nargout < 2) |
|
1230 { |
4732
|
1231 int nd = args(1).int_value (true); |
1031
|
1232 |
|
1233 if (error_state) |
|
1234 error ("size: expecting scalar as second argument"); |
712
|
1235 else |
1031
|
1236 { |
4741
|
1237 dim_vector dv = args(0).dims (); |
|
1238 |
|
1239 if (nd > 0 && nd <= dv.length ()) |
|
1240 retval(0) = dv(nd-1); |
1031
|
1241 else |
4741
|
1242 error ("size: requested dimension (= %d) out of range", nd); |
1031
|
1243 } |
523
|
1244 } |
712
|
1245 else |
|
1246 print_usage ("size"); |
523
|
1247 |
|
1248 return retval; |
|
1249 } |
|
1250 |
1957
|
1251 DEFUN (sum, args, , |
3428
|
1252 "-*- texinfo -*-\n\ |
3723
|
1253 @deftypefn {Built-in Function} {} sum (@var{x}, @var{dim})\n\ |
|
1254 Sum of elements along dimension @var{dim}. If @var{dim} is\n\ |
|
1255 omitted, it defaults to 1 (column-wise sum).\n\ |
3428
|
1256 @end deftypefn") |
523
|
1257 { |
3723
|
1258 DATA_REDUCTION (sum); |
523
|
1259 } |
|
1260 |
1957
|
1261 DEFUN (sumsq, args, , |
3428
|
1262 "-*- texinfo -*-\n\ |
3723
|
1263 @deftypefn {Built-in Function} {} sumsq (@var{x}, @var{dim})\n\ |
|
1264 Sum of squares of elements along dimension @var{dim}. If @var{dim}\n\ |
|
1265 is omitted, it defaults to 1 (column-wise sum of squares).\n\ |
3095
|
1266 \n\ |
|
1267 This function is equivalent to computing\n\ |
3723
|
1268 @example\n\ |
|
1269 sum (x .* conj (x), dim)\n\ |
|
1270 @end example\n\ |
|
1271 but it uses less memory and avoids calling conj if @var{x} is real.\n\ |
3428
|
1272 @end deftypefn") |
523
|
1273 { |
3723
|
1274 DATA_REDUCTION (sumsq); |
523
|
1275 } |
|
1276 |
4028
|
1277 DEFUN (isbool, args, , |
3428
|
1278 "-*- texinfo -*-\n\ |
4028
|
1279 @deftypefn {Built-in Functio} {} isbool (@var{x})\n\ |
3428
|
1280 Return true if @var{x} is a boolean object.\n\ |
3439
|
1281 @end deftypefn") |
3209
|
1282 { |
|
1283 octave_value retval; |
|
1284 |
|
1285 if (args.length () == 1) |
3258
|
1286 retval = args(0).is_bool_type (); |
3209
|
1287 else |
4028
|
1288 print_usage ("isbool"); |
3209
|
1289 |
|
1290 return retval; |
|
1291 } |
|
1292 |
4028
|
1293 DEFALIAS (islogical, isbool); |
3209
|
1294 |
4028
|
1295 DEFUN (iscomplex, args, , |
3428
|
1296 "-*- texinfo -*-\n\ |
4028
|
1297 @deftypefn {Built-in Function} {} iscomplex (@var{x})\n\ |
3428
|
1298 Return true if @var{x} is a complex-valued numeric object.\n\ |
|
1299 @end deftypefn") |
3186
|
1300 { |
|
1301 octave_value retval; |
|
1302 |
|
1303 if (args.length () == 1) |
3258
|
1304 retval = args(0).is_complex_type (); |
3186
|
1305 else |
4028
|
1306 print_usage ("iscomplex"); |
3186
|
1307 |
|
1308 return retval; |
|
1309 } |
|
1310 |
3258
|
1311 DEFUN (isreal, args, , |
3428
|
1312 "-*- texinfo -*-\n\ |
|
1313 @deftypefn {Built-in Function} {} isreal (@var{x})\n\ |
|
1314 Return true if @var{x} is a real-valued numeric object.\n\ |
|
1315 @end deftypefn") |
3258
|
1316 { |
|
1317 octave_value retval; |
|
1318 |
|
1319 if (args.length () == 1) |
|
1320 retval = args(0).is_real_type (); |
|
1321 else |
|
1322 print_usage ("isreal"); |
|
1323 |
|
1324 return retval; |
|
1325 } |
|
1326 |
3202
|
1327 DEFUN (isempty, args, , |
3373
|
1328 "-*- texinfo -*-\n\ |
|
1329 @deftypefn {Built-in Function} {} isempty (@var{a})\n\ |
|
1330 Return 1 if @var{a} is an empty matrix (either the number of rows, or\n\ |
|
1331 the number of columns, or both are zero). Otherwise, return 0.\n\ |
|
1332 @end deftypefn") |
3202
|
1333 { |
4233
|
1334 octave_value retval = false; |
3202
|
1335 |
|
1336 if (args.length () == 1) |
4559
|
1337 retval = args(0).is_empty (); |
3202
|
1338 else |
|
1339 print_usage ("isempty"); |
|
1340 |
|
1341 return retval; |
|
1342 } |
|
1343 |
3206
|
1344 DEFUN (isnumeric, args, , |
3428
|
1345 "-*- texinfo -*-\n\ |
|
1346 @deftypefn {Built-in Function} {} isnumeric (@var{x})\n\ |
|
1347 Return nonzero if @var{x} is a numeric object.\n\ |
|
1348 @end deftypefn") |
3206
|
1349 { |
|
1350 octave_value retval; |
|
1351 |
|
1352 if (args.length () == 1) |
3258
|
1353 retval = args(0).is_numeric_type (); |
3206
|
1354 else |
3238
|
1355 print_usage ("isnumeric"); |
3206
|
1356 |
|
1357 return retval; |
|
1358 } |
|
1359 |
4028
|
1360 DEFUN (islist, args, , |
3526
|
1361 "-*- texinfo -*-\n\ |
4028
|
1362 @deftypefn {Built-in Function} {} islist (@var{x})\n\ |
3428
|
1363 Return nonzero if @var{x} is a list.\n\ |
|
1364 @end deftypefn") |
3204
|
1365 { |
|
1366 octave_value retval; |
|
1367 |
|
1368 if (args.length () == 1) |
3258
|
1369 retval = args(0).is_list (); |
3204
|
1370 else |
4028
|
1371 print_usage ("islist"); |
3204
|
1372 |
|
1373 return retval; |
|
1374 } |
|
1375 |
4028
|
1376 DEFUN (ismatrix, args, , |
3321
|
1377 "-*- texinfo -*-\n\ |
4028
|
1378 @deftypefn {Built-in Function} {} ismatrix (@var{a})\n\ |
3321
|
1379 Return 1 if @var{a} is a matrix. Otherwise, return 0.\n\ |
3333
|
1380 @end deftypefn") |
3202
|
1381 { |
4233
|
1382 octave_value retval = false; |
3202
|
1383 |
|
1384 if (args.length () == 1) |
|
1385 { |
|
1386 octave_value arg = args(0); |
|
1387 |
3212
|
1388 if (arg.is_scalar_type () || arg.is_range ()) |
4233
|
1389 retval = true; |
3202
|
1390 else if (arg.is_matrix_type ()) |
4233
|
1391 retval = (arg.rows () >= 1 && arg.columns () >= 1); |
3202
|
1392 } |
|
1393 else |
4028
|
1394 print_usage ("ismatrix"); |
3202
|
1395 |
|
1396 return retval; |
|
1397 } |
|
1398 |
3354
|
1399 static octave_value |
|
1400 fill_matrix (const octave_value_list& args, double val, const char *fcn) |
523
|
1401 { |
3354
|
1402 octave_value retval; |
523
|
1403 |
|
1404 int nargin = args.length (); |
|
1405 |
4481
|
1406 int ndim = 0; |
|
1407 int type = 0; |
|
1408 |
4513
|
1409 dim_vector dims; |
4481
|
1410 |
|
1411 // Check for type information. |
|
1412 |
|
1413 if (nargin > 0 && args(nargin-1).is_string ()) |
|
1414 { |
|
1415 nargin--; |
|
1416 |
|
1417 // XXX FIXME XXX -- allow type of the resulting matrix to be |
|
1418 // specified, e.g. |
|
1419 // |
|
1420 // zeros(n1, n2, ..., 'real') |
|
1421 // zeros(n1, n2, ..., 'complex') |
|
1422 // |
|
1423 // type = get_type (args(nargin).string_value ()); |
|
1424 } |
|
1425 |
|
1426 // determine matrix dimension |
|
1427 |
523
|
1428 switch (nargin) |
|
1429 { |
712
|
1430 case 0: |
4481
|
1431 ndim = 0; |
|
1432 type = 0; |
712
|
1433 break; |
777
|
1434 |
610
|
1435 case 1: |
4481
|
1436 get_dimensions (args(0), fcn, dims); |
610
|
1437 break; |
777
|
1438 |
4563
|
1439 default: |
|
1440 { |
|
1441 dims.resize (nargin); |
4481
|
1442 |
4563
|
1443 for (int i = 0; i < nargin; i++) |
|
1444 { |
4732
|
1445 dims(i) = args(i).is_empty () ? 0 : args(i).int_value (); |
4481
|
1446 |
4563
|
1447 if (error_state) |
|
1448 { |
4732
|
1449 error ("%s: expecting scalar integer arguments", fcn); |
4563
|
1450 break; |
|
1451 } |
|
1452 } |
|
1453 } |
|
1454 break; |
4481
|
1455 } |
|
1456 |
|
1457 if (! error_state) |
|
1458 { |
|
1459 ndim = dims.length (); |
|
1460 |
4565
|
1461 for (int i = ndim-1; i > 1; i--) |
|
1462 { |
|
1463 if (dims(i) == 1) |
|
1464 ndim--; |
|
1465 else |
|
1466 break; |
|
1467 } |
|
1468 |
|
1469 dims.resize (ndim); |
|
1470 |
4481
|
1471 check_dimensions (dims, fcn); |
3354
|
1472 |
4481
|
1473 if (! error_state) |
|
1474 { |
|
1475 // Construct either scalar, matrix or N-d array. |
|
1476 |
|
1477 switch (ndim) |
|
1478 { |
|
1479 case 0: |
|
1480 retval = val; |
|
1481 break; |
777
|
1482 |
4481
|
1483 case 1: |
|
1484 retval = Matrix (dims(0), dims(0), val); |
|
1485 break; |
|
1486 |
|
1487 case 2: |
|
1488 retval = Matrix (dims(0), dims(1), val); |
|
1489 break; |
|
1490 |
|
1491 default: |
4512
|
1492 retval = NDArray (dims, val); |
4481
|
1493 break; |
|
1494 } |
|
1495 } |
523
|
1496 } |
|
1497 |
|
1498 return retval; |
|
1499 } |
|
1500 |
3354
|
1501 DEFUN (ones, args, , |
3369
|
1502 "-*- texinfo -*-\n\ |
|
1503 @deftypefn {Built-in Function} {} ones (@var{x})\n\ |
|
1504 @deftypefnx {Built-in Function} {} ones (@var{n}, @var{m})\n\ |
4481
|
1505 @deftypefnx {Built-in Function} {} ones (@var{n}, @var{m}, @var{k},...)\n\ |
|
1506 Return a matrix or N-dimensional array whose elements are all 1.\n\ |
|
1507 The arguments are handled the same as the arguments for @code{eye}.\n\ |
3369
|
1508 \n\ |
|
1509 If you need to create a matrix whose values are all the same, you should\n\ |
|
1510 use an expression like\n\ |
|
1511 \n\ |
|
1512 @example\n\ |
|
1513 val_matrix = val * ones (n, m)\n\ |
|
1514 @end example\n\ |
|
1515 @end deftypefn") |
523
|
1516 { |
3354
|
1517 return fill_matrix (args, 1.0, "ones"); |
523
|
1518 } |
|
1519 |
3354
|
1520 DEFUN (zeros, args, , |
3369
|
1521 "-*- texinfo -*-\n\ |
|
1522 @deftypefn {Built-in Function} {} zeros (@var{x})\n\ |
|
1523 @deftypefnx {Built-in Function} {} zeros (@var{n}, @var{m})\n\ |
4481
|
1524 @deftypefnx {Built-in Function} {} zeros (@var{n}, @var{m}, @var{k},...)\n\ |
|
1525 Return a matrix or N-dimensional array whose elements are all 0.\n\ |
|
1526 The arguments are handled the same as the arguments for @code{eye}.\n\ |
3369
|
1527 @end deftypefn") |
523
|
1528 { |
3354
|
1529 return fill_matrix (args, 0.0, "zeros"); |
|
1530 } |
523
|
1531 |
1957
|
1532 DEFUN (eye, args, , |
3369
|
1533 "-*- texinfo -*-\n\ |
|
1534 @deftypefn {Built-in Function} {} eye (@var{x})\n\ |
|
1535 @deftypefnx {Built-in Function} {} eye (@var{n}, @var{m})\n\ |
|
1536 Return an identity matrix. If invoked with a single scalar argument,\n\ |
|
1537 @code{eye} returns a square matrix with the dimension specified. If you\n\ |
|
1538 supply two scalar arguments, @code{eye} takes them to be the number of\n\ |
|
1539 rows and columns. If given a vector with two elements, @code{eye} uses\n\ |
|
1540 the values of the elements as the number of rows and columns,\n\ |
|
1541 respectively. For example,\n\ |
|
1542 \n\ |
|
1543 @example\n\ |
|
1544 @group\n\ |
|
1545 eye (3)\n\ |
|
1546 @result{} 1 0 0\n\ |
|
1547 0 1 0\n\ |
|
1548 0 0 1\n\ |
|
1549 @end group\n\ |
|
1550 @end example\n\ |
|
1551 \n\ |
|
1552 The following expressions all produce the same result:\n\ |
|
1553 \n\ |
|
1554 @example\n\ |
|
1555 @group\n\ |
|
1556 eye (2)\n\ |
|
1557 @equiv{}\n\ |
|
1558 eye (2, 2)\n\ |
|
1559 @equiv{}\n\ |
|
1560 eye (size ([1, 2; 3, 4])\n\ |
|
1561 @end group\n\ |
|
1562 @end example\n\ |
|
1563 \n\ |
|
1564 For compatibility with @sc{Matlab}, calling @code{eye} with no arguments\n\ |
|
1565 is equivalent to calling it with an argument of 1.\n\ |
|
1566 @end deftypefn") |
523
|
1567 { |
3354
|
1568 octave_value retval; |
523
|
1569 |
|
1570 int nargin = args.length (); |
|
1571 |
|
1572 switch (nargin) |
|
1573 { |
712
|
1574 case 0: |
|
1575 retval = 1.0; |
|
1576 break; |
777
|
1577 |
610
|
1578 case 1: |
3354
|
1579 { |
|
1580 int nr, nc; |
|
1581 get_dimensions (args(0), "eye", nr, nc); |
|
1582 |
|
1583 if (! error_state) |
|
1584 retval = identity_matrix (nr, nc); |
|
1585 } |
610
|
1586 break; |
777
|
1587 |
523
|
1588 case 2: |
3354
|
1589 { |
|
1590 int nr, nc; |
|
1591 get_dimensions (args(0), args(1), "eye", nr, nc); |
|
1592 |
|
1593 if (! error_state) |
|
1594 retval = identity_matrix (nr, nc); |
|
1595 } |
523
|
1596 break; |
777
|
1597 |
523
|
1598 default: |
|
1599 print_usage ("eye"); |
|
1600 break; |
|
1601 } |
|
1602 |
|
1603 return retval; |
|
1604 } |
|
1605 |
1957
|
1606 DEFUN (linspace, args, , |
3369
|
1607 "-*- texinfo -*-\n\ |
|
1608 @deftypefn {Built-in Function} {} linspace (@var{base}, @var{limit}, @var{n})\n\ |
|
1609 Return a row vector with @var{n} linearly spaced elements between\n\ |
|
1610 @var{base} and @var{limit}. The number of elements, @var{n}, must be\n\ |
|
1611 greater than 1. The @var{base} and @var{limit} are always included in\n\ |
|
1612 the range. If @var{base} is greater than @var{limit}, the elements are\n\ |
|
1613 stored in decreasing order. If the number of points is not specified, a\n\ |
|
1614 value of 100 is used.\n\ |
1100
|
1615 \n\ |
4455
|
1616 The @code{linspace} function always returns a row vector.\n\ |
3369
|
1617 @end deftypefn") |
1100
|
1618 { |
3418
|
1619 octave_value retval; |
1100
|
1620 |
|
1621 int nargin = args.length (); |
|
1622 |
|
1623 int npoints = 100; |
|
1624 |
1940
|
1625 if (nargin != 2 && nargin != 3) |
|
1626 { |
|
1627 print_usage ("linspace"); |
|
1628 return retval; |
|
1629 } |
|
1630 |
1100
|
1631 if (nargin == 3) |
4732
|
1632 npoints = args(2).int_value (); |
1100
|
1633 |
|
1634 if (! error_state) |
|
1635 { |
3322
|
1636 octave_value arg_1 = args(0); |
|
1637 octave_value arg_2 = args(1); |
1100
|
1638 |
3322
|
1639 if (arg_1.is_complex_type () || arg_2.is_complex_type ()) |
|
1640 { |
|
1641 Complex x1 = arg_1.complex_value (); |
|
1642 Complex x2 = arg_2.complex_value (); |
|
1643 |
|
1644 if (! error_state) |
1100
|
1645 { |
3322
|
1646 ComplexRowVector rv = linspace (x1, x2, npoints); |
1100
|
1647 |
|
1648 if (! error_state) |
3418
|
1649 retval = rv; |
1100
|
1650 } |
|
1651 } |
|
1652 else |
3322
|
1653 { |
|
1654 double x1 = arg_1.double_value (); |
|
1655 double x2 = arg_2.double_value (); |
|
1656 |
|
1657 if (! error_state) |
|
1658 { |
|
1659 RowVector rv = linspace (x1, x2, npoints); |
|
1660 |
|
1661 if (! error_state) |
3418
|
1662 retval = rv; |
3322
|
1663 } |
|
1664 } |
1100
|
1665 } |
4732
|
1666 else |
|
1667 error ("linspace: expecting third argument to be an integer"); |
1100
|
1668 |
|
1669 return retval; |
|
1670 } |
|
1671 |
4567
|
1672 DEFUN (reshape, args, , |
|
1673 "-*- texinfo -*-\n\ |
|
1674 @deftypefn {Function File} {} reshape (@var{a}, @var{m}, @var{n}, @dots{})\n\ |
|
1675 @deftypefnx {Function File} {} reshape (@var{a}, @var{siz})\n\ |
|
1676 Return a matrix with the given dimensions whose elements are taken\n\ |
|
1677 from the matrix @var{a}. The elements of the matrix are access in\n\ |
|
1678 column-major order (like Fortran arrays are stored).\n\ |
|
1679 \n\ |
|
1680 For example,\n\ |
|
1681 \n\ |
|
1682 @example\n\ |
|
1683 @group\n\ |
|
1684 reshape ([1, 2, 3, 4], 2, 2)\n\ |
|
1685 @result{} 1 3\n\ |
|
1686 2 4\n\ |
|
1687 @end group\n\ |
|
1688 @end example\n\ |
|
1689 \n\ |
|
1690 @noindent\n\ |
|
1691 Note that the total number of elements in the original\n\ |
|
1692 matrix must match the total number of elements in the new matrix.\n\ |
|
1693 @end deftypefn") |
|
1694 { |
|
1695 octave_value retval; |
|
1696 |
|
1697 int nargin = args.length (); |
|
1698 |
|
1699 Array<int> new_size; |
|
1700 |
|
1701 if (nargin == 2) |
|
1702 new_size = args(1).int_vector_value (); |
|
1703 else if (nargin > 2) |
|
1704 { |
|
1705 new_size.resize (nargin-1); |
|
1706 |
|
1707 for (int i = 1; i < nargin; i++) |
|
1708 { |
|
1709 new_size(i-1) = args(i).int_value (); |
|
1710 |
|
1711 if (error_state) |
|
1712 break; |
|
1713 } |
|
1714 } |
|
1715 else |
|
1716 { |
|
1717 print_usage ("reshape"); |
|
1718 return retval; |
|
1719 } |
|
1720 |
|
1721 if (error_state) |
|
1722 { |
|
1723 error ("reshape: invalid arguments"); |
|
1724 return retval; |
|
1725 } |
|
1726 |
4739
|
1727 // Remove trailing singletons in new_size, but leave at least 2 |
|
1728 // elements. |
|
1729 |
4567
|
1730 int n = new_size.length (); |
|
1731 |
4739
|
1732 while (n > 2) |
|
1733 { |
|
1734 if (new_size(n-1) == 1) |
|
1735 n--; |
|
1736 else |
|
1737 break; |
|
1738 } |
|
1739 |
|
1740 new_size.resize (n); |
|
1741 |
4567
|
1742 if (n < 2) |
|
1743 { |
|
1744 error ("reshape: expecting size to be vector with at least 2 elements"); |
|
1745 return retval; |
|
1746 } |
|
1747 |
|
1748 dim_vector new_dims; |
|
1749 |
|
1750 new_dims.resize (n); |
|
1751 |
|
1752 for (int i = 0; i < n; i++) |
|
1753 new_dims(i) = new_size(i); |
|
1754 |
|
1755 octave_value arg = args(0); |
|
1756 |
|
1757 if (new_dims.numel () == arg.numel ()) |
|
1758 retval = (new_dims == arg.dims ()) ? arg : arg.reshape (new_dims); |
|
1759 else |
|
1760 error ("reshape: size mismatch"); |
|
1761 |
|
1762 return retval; |
|
1763 } |
|
1764 |
4532
|
1765 DEFUN (squeeze, args, , |
|
1766 "-*- texinfo -*-\n\ |
|
1767 @deftypefn {Built-in Function} {} squeeze (@var{x})\n\ |
|
1768 Remove singleton dimensions from @var{x} and return the result.\n\ |
|
1769 @end deftypefn") |
|
1770 { |
|
1771 octave_value retval; |
|
1772 |
|
1773 if (args.length () == 1) |
4545
|
1774 retval = args(0).squeeze (); |
4532
|
1775 else |
|
1776 print_usage ("squeeze"); |
|
1777 |
|
1778 return retval; |
|
1779 } |
|
1780 |
2184
|
1781 void |
|
1782 symbols_of_data (void) |
|
1783 { |
3321
|
1784 |
|
1785 #define IMAGINARY_DOC_STRING "-*- texinfo -*-\n\ |
|
1786 @defvr {Built-in Variable} I\n\ |
|
1787 @defvrx {Built-in Variable} J\n\ |
|
1788 @defvrx {Built-in Variable} i\n\ |
|
1789 @defvrx {Built-in Variable} j\n\ |
|
1790 A pure imaginary number, defined as\n\ |
|
1791 @iftex\n\ |
|
1792 @tex\n\ |
|
1793 $\\sqrt{-1}$.\n\ |
|
1794 @end tex\n\ |
|
1795 @end iftex\n\ |
|
1796 @ifinfo\n\ |
|
1797 @code{sqrt (-1)}.\n\ |
|
1798 @end ifinfo\n\ |
4845
|
1799 These built-in variables behave like functions so you can use the names\n\ |
|
1800 for other purposes. If you use them as variables and assign values to\n\ |
|
1801 them and then clear them, they once again assume their special predefined\n\ |
|
1802 values @xref{Status of Variables}.\n\ |
3321
|
1803 @end defvr" |
|
1804 |
|
1805 #define INFINITY_DOC_STRING "-*- texinfo -*-\n\ |
|
1806 @defvr {Built-in Variable} Inf\n\ |
|
1807 @defvrx {Built-in Variable} inf\n\ |
|
1808 Infinity. This is the result of an operation like 1/0, or an operation\n\ |
|
1809 that results in a floating point overflow.\n\ |
|
1810 @end defvr" |
|
1811 |
|
1812 #define NAN_DOC_STRING "-*- texinfo -*-\n\ |
|
1813 @defvr {Built-in Variable} NaN\n\ |
|
1814 @defvrx {Built-in Variable} nan\n\ |
|
1815 Not a number. This is the result of an operation like\n\ |
|
1816 @iftex\n\ |
|
1817 @tex\n\ |
|
1818 $0/0$, or $\\infty - \\infty$,\n\ |
|
1819 @end tex\n\ |
|
1820 @end iftex\n\ |
|
1821 @ifinfo\n\ |
|
1822 0/0, or @samp{Inf - Inf},\n\ |
|
1823 @end ifinfo\n\ |
|
1824 or any operation with a NaN.\n\ |
|
1825 \n\ |
|
1826 Note that NaN always compares not equal to NaN. This behavior is\n\ |
|
1827 specified by the IEEE standard for floating point arithmetic. To\n\ |
|
1828 find NaN values, you must use the @code{isnan} function.\n\ |
|
1829 @end defvr" |
|
1830 |
3141
|
1831 DEFCONST (I, Complex (0.0, 1.0), |
3321
|
1832 IMAGINARY_DOC_STRING); |
2184
|
1833 |
4102
|
1834 DEFCONST (Inf, lo_ieee_inf_value (), |
3321
|
1835 INFINITY_DOC_STRING); |
2184
|
1836 |
3141
|
1837 DEFCONST (J, Complex (0.0, 1.0), |
3321
|
1838 IMAGINARY_DOC_STRING); |
2184
|
1839 |
4102
|
1840 DEFCONST (NA, lo_ieee_na_value (), |
4025
|
1841 "-*- texinfo -*-\n\ |
|
1842 @defvr {Built-in Variable} NA\n\ |
|
1843 Missing value.\n\ |
|
1844 @end defvr"); |
|
1845 |
4102
|
1846 DEFCONST (NaN, lo_ieee_nan_value (), |
3321
|
1847 NAN_DOC_STRING); |
2184
|
1848 |
|
1849 #if defined (M_E) |
|
1850 double e_val = M_E; |
|
1851 #else |
|
1852 double e_val = exp (1.0); |
|
1853 #endif |
|
1854 |
3141
|
1855 DEFCONST (e, e_val, |
3321
|
1856 "-*- texinfo -*-\n\ |
|
1857 @defvr {Built-in Variable} e\n\ |
|
1858 The base of natural logarithms. The constant\n\ |
|
1859 @iftex\n\ |
|
1860 @tex\n\ |
|
1861 $e$\n\ |
|
1862 @end tex\n\ |
|
1863 @end iftex\n\ |
|
1864 @ifinfo\n\ |
|
1865 @var{e}\n\ |
|
1866 @end ifinfo\n\ |
|
1867 satisfies the equation\n\ |
|
1868 @iftex\n\ |
|
1869 @tex\n\ |
|
1870 $\\log (e) = 1$.\n\ |
|
1871 @end tex\n\ |
|
1872 @end iftex\n\ |
|
1873 @ifinfo\n\ |
|
1874 @code{log} (@var{e}) = 1.\n\ |
|
1875 @end ifinfo\n\ |
|
1876 @end defvr"); |
2184
|
1877 |
3141
|
1878 DEFCONST (eps, DBL_EPSILON, |
3321
|
1879 "-*- texinfo -*-\n\ |
|
1880 @defvr {Built-in Variable} eps\n\ |
|
1881 The machine precision. More precisely, @code{eps} is the largest\n\ |
|
1882 relative spacing between any two adjacent numbers in the machine's\n\ |
|
1883 floating point system. This number is obviously system-dependent. On\n\ |
|
1884 machines that support 64 bit IEEE floating point arithmetic, @code{eps}\n\ |
|
1885 is approximately\n\ |
|
1886 @ifinfo\n\ |
|
1887 2.2204e-16.\n\ |
|
1888 @end ifinfo\n\ |
|
1889 @iftex\n\ |
|
1890 @tex\n\ |
|
1891 $2.2204\\times10^{-16}$.\n\ |
|
1892 @end tex\n\ |
|
1893 @end iftex\n\ |
|
1894 @end defvr"); |
2184
|
1895 |
3258
|
1896 DEFCONST (false, false, |
3443
|
1897 "-*- texinfo -*-\n\ |
|
1898 @defvr {Built-in Variable} false\n\ |
|
1899 Logical false value.\n\ |
|
1900 @end defvr"); |
3258
|
1901 |
3141
|
1902 DEFCONST (i, Complex (0.0, 1.0), |
3321
|
1903 IMAGINARY_DOC_STRING); |
2184
|
1904 |
4102
|
1905 DEFCONST (inf, lo_ieee_inf_value (), |
3321
|
1906 INFINITY_DOC_STRING); |
2184
|
1907 |
3141
|
1908 DEFCONST (j, Complex (0.0, 1.0), |
3321
|
1909 IMAGINARY_DOC_STRING); |
2184
|
1910 |
4102
|
1911 DEFCONST (nan, lo_ieee_nan_value (), |
3321
|
1912 NAN_DOC_STRING); |
2184
|
1913 |
|
1914 #if defined (M_PI) |
|
1915 double pi_val = M_PI; |
|
1916 #else |
|
1917 double pi_val = 4.0 * atan (1.0); |
|
1918 #endif |
|
1919 |
3141
|
1920 DEFCONST (pi, pi_val, |
3321
|
1921 "-*- texinfo -*-\n\ |
|
1922 @defvr {Built-in Variable} pi\n\ |
|
1923 The ratio of the circumference of a circle to its diameter.\n\ |
|
1924 Internally, @code{pi} is computed as @samp{4.0 * atan (1.0)}.\n\ |
|
1925 @end defvr"); |
2184
|
1926 |
3141
|
1927 DEFCONST (realmax, DBL_MAX, |
3321
|
1928 "-*- texinfo -*-\n\ |
|
1929 @defvr {Built-in Variable} realmax\n\ |
|
1930 The largest floating point number that is representable. The actual\n\ |
4303
|
1931 value is system-dependent. On machines that support 64-bit IEEE\n\ |
3321
|
1932 floating point arithmetic, @code{realmax} is approximately\n\ |
|
1933 @ifinfo\n\ |
|
1934 1.7977e+308\n\ |
|
1935 @end ifinfo\n\ |
|
1936 @iftex\n\ |
|
1937 @tex\n\ |
|
1938 $1.7977\\times10^{308}$.\n\ |
|
1939 @end tex\n\ |
|
1940 @end iftex\n\ |
|
1941 @end defvr"); |
2184
|
1942 |
3141
|
1943 DEFCONST (realmin, DBL_MIN, |
3321
|
1944 "-*- texinfo -*-\n\ |
|
1945 @defvr {Built-in Variable} realmin\n\ |
4303
|
1946 The smallest normalized floating point number that is representable.\n\ |
|
1947 The actual value is system-dependent. On machines that support\n\ |
|
1948 64-bit IEEE floating point arithmetic, @code{realmin} is approximately\n\ |
3321
|
1949 @ifinfo\n\ |
|
1950 2.2251e-308\n\ |
|
1951 @end ifinfo\n\ |
|
1952 @iftex\n\ |
|
1953 @tex\n\ |
|
1954 $2.2251\\times10^{-308}$.\n\ |
|
1955 @end tex\n\ |
|
1956 @end iftex\n\ |
|
1957 @end defvr"); |
2188
|
1958 |
3258
|
1959 DEFCONST (true, true, |
3443
|
1960 "-*- texinfo -*-\n\ |
|
1961 @defvr {Built-in Variable} true\n\ |
|
1962 Logical true value.\n\ |
|
1963 @end defvr"); |
3354
|
1964 |
2184
|
1965 } |
|
1966 |
523
|
1967 /* |
|
1968 ;;; Local Variables: *** |
|
1969 ;;; mode: C++ *** |
|
1970 ;;; End: *** |
|
1971 */ |