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