GNU Octave  4.2.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ov.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-2017 John W. Eaton
4 Copyright (C) 2009-2010 VZLU Prague
5 
6 This file is part of Octave.
7 
8 Octave is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by the
10 Free Software Foundation; either version 3 of the License, or (at your
11 option) any later version.
12 
13 Octave is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
17 
18 You should have received a copy of the GNU General Public License
19 along with Octave; see the file COPYING. If not, see
20 <http://www.gnu.org/licenses/>.
21 
22 */
23 
24 #if defined (HAVE_CONFIG_H)
25 # include "config.h"
26 #endif
27 
28 #include "data-conv.h"
29 #include "quit.h"
30 #include "str-vec.h"
31 
32 #include "ovl.h"
33 #include "oct-stream.h"
34 #include "ov.h"
35 #include "ov-base.h"
36 #include "ov-bool.h"
37 #include "ov-bool-mat.h"
38 #include "ov-cell.h"
39 #include "ov-scalar.h"
40 #include "ov-float.h"
41 #include "ov-re-mat.h"
42 #include "ov-flt-re-mat.h"
43 #include "ov-re-diag.h"
44 #include "ov-flt-re-diag.h"
45 #include "ov-perm.h"
46 #include "ov-bool-sparse.h"
47 #include "ov-cx-sparse.h"
48 #include "ov-re-sparse.h"
49 #include "ov-int8.h"
50 #include "ov-int16.h"
51 #include "ov-int32.h"
52 #include "ov-int64.h"
53 #include "ov-uint8.h"
54 #include "ov-uint16.h"
55 #include "ov-uint32.h"
56 #include "ov-uint64.h"
57 #include "ov-complex.h"
58 #include "ov-flt-complex.h"
59 #include "ov-cx-mat.h"
60 #include "ov-flt-cx-mat.h"
61 #include "ov-cx-diag.h"
62 #include "ov-flt-cx-diag.h"
63 #include "ov-ch-mat.h"
64 #include "ov-str-mat.h"
65 #include "ov-range.h"
66 #include "ov-struct.h"
67 #include "ov-class.h"
68 #include "ov-classdef.h"
69 #include "ov-oncleanup.h"
70 #include "ov-cs-list.h"
71 #include "ov-colon.h"
72 #include "ov-builtin.h"
73 #include "ov-dld-fcn.h"
74 #include "ov-usr-fcn.h"
75 #include "ov-fcn-handle.h"
76 #include "ov-fcn-inline.h"
77 #include "ov-typeinfo.h"
78 #include "ov-null-mat.h"
79 #include "ov-lazy-idx.h"
80 #include "ov-java.h"
81 
82 #include "defun.h"
83 #include "error.h"
84 #include "errwarn.h"
85 #include "pager.h"
86 #include "parse.h"
87 #include "pr-output.h"
88 #include "symtab.h"
89 #include "utils.h"
90 #include "variables.h"
91 
92 // We are likely to have a lot of octave_value objects to allocate, so
93 // make the grow_size large.
94 
95 // If TRUE, don't create special diagonal matrix objects.
96 
97 static bool Vdisable_diagonal_matrix = false;
98 
99 // If TRUE, don't create special permutation matrix objects.
100 
101 static bool Vdisable_permutation_matrix = false;
102 
103 // If TRUE, don't create special range objects.
104 
105 static bool Vdisable_range = false;
106 
107 // FIXME
108 
109 // Octave's value type.
110 
113 {
114  static octave_base_value nr;
115  return &nr;
116 }
117 
120 {
121  switch (op)
122  {
123  case op_not:
124  return "!";
125 
126  case op_uplus:
127  return "+";
128 
129  case op_uminus:
130  return "-";
131 
132  case op_transpose:
133  return ".'";
134 
135  case op_hermitian:
136  return "'";
137 
138  case op_incr:
139  return "++";
140 
141  case op_decr:
142  return "--";
143 
144  default:
145  return "<unknown>";
146  }
147 }
148 
151 {
152  switch (op)
153  {
154  case op_not:
155  return "not";
156 
157  case op_uplus:
158  return "uplus";
159 
160  case op_uminus:
161  return "uminus";
162 
163  case op_transpose:
164  return "transpose";
165 
166  case op_hermitian:
167  return "ctranspose";
168 
169  default:
170  return "<unknown>";
171  }
172 }
173 
176 {
177  switch (op)
178  {
179  case op_add:
180  return "+";
181 
182  case op_sub:
183  return "-";
184 
185  case op_mul:
186  return "*";
187 
188  case op_div:
189  return "/";
190 
191  case op_pow:
192  return "^";
193 
194  case op_ldiv:
195  return "\\";
196 
197  case op_lt:
198  return "<";
199 
200  case op_le:
201  return "<=";
202 
203  case op_eq:
204  return "==";
205 
206  case op_ge:
207  return ">=";
208 
209  case op_gt:
210  return ">";
211 
212  case op_ne:
213  return "!=";
214 
215  case op_el_mul:
216  return ".*";
217 
218  case op_el_div:
219  return "./";
220 
221  case op_el_pow:
222  return ".^";
223 
224  case op_el_ldiv:
225  return ".\\";
226 
227  case op_el_and:
228  return "&";
229 
230  case op_el_or:
231  return "|";
232 
233  case op_struct_ref:
234  return ".";
235 
236  default:
237  return "<unknown>";
238  }
239 }
240 
243 {
244  switch (op)
245  {
246  case op_add:
247  return "plus";
248 
249  case op_sub:
250  return "minus";
251 
252  case op_mul:
253  return "mtimes";
254 
255  case op_div:
256  return "mrdivide";
257 
258  case op_pow:
259  return "mpower";
260 
261  case op_ldiv:
262  return "mldivide";
263 
264  case op_lt:
265  return "lt";
266 
267  case op_le:
268  return "le";
269 
270  case op_eq:
271  return "eq";
272 
273  case op_ge:
274  return "ge";
275 
276  case op_gt:
277  return "gt";
278 
279  case op_ne:
280  return "ne";
281 
282  case op_el_mul:
283  return "times";
284 
285  case op_el_div:
286  return "rdivide";
287 
288  case op_el_pow:
289  return "power";
290 
291  case op_el_ldiv:
292  return "ldivide";
293 
294  case op_el_and:
295  return "and";
296 
297  case op_el_or:
298  return "or";
299 
300  default:
301  return "<unknown>";
302  }
303 }
304 
307 {
308  switch (op)
309  {
310  case op_trans_mul:
311  return "transtimes";
312 
313  case op_mul_trans:
314  return "timestrans";
315 
316  case op_herm_mul:
317  return "hermtimes";
318 
319  case op_mul_herm:
320  return "timesherm";
321 
322  case op_trans_ldiv:
323  return "transldiv";
324 
325  case op_herm_ldiv:
326  return "hermldiv";
327 
328  case op_el_and_not:
329  return "andnot";
330 
331  case op_el_or_not:
332  return "ornot";
333 
334  case op_el_not_and:
335  return "notand";
336 
337  case op_el_not_or:
338  return "notor";
339 
340  default:
341  return "<unknown>";
342  }
343 }
344 
347 {
348  switch (op)
349  {
350  case op_asn_eq:
351  return "=";
352 
353  case op_add_eq:
354  return "+=";
355 
356  case op_sub_eq:
357  return "-=";
358 
359  case op_mul_eq:
360  return "*=";
361 
362  case op_div_eq:
363  return "/=";
364 
365  case op_ldiv_eq:
366  return "\\=";
367 
368  case op_pow_eq:
369  return "^=";
370 
371  case op_el_mul_eq:
372  return ".*=";
373 
374  case op_el_div_eq:
375  return "./=";
376 
377  case op_el_ldiv_eq:
378  return ".\\=";
379 
380  case op_el_pow_eq:
381  return ".^=";
382 
383  case op_el_and_eq:
384  return "&=";
385 
386  case op_el_or_eq:
387  return "|=";
388 
389  default:
390  return "<unknown>";
391  }
392 }
393 
396 {
397  switch (op)
398  {
399  case op_add_eq:
400  return op_add;
401 
402  case op_sub_eq:
403  return op_sub;
404 
405  case op_mul_eq:
406  return op_mul;
407 
408  case op_div_eq:
409  return op_div;
410 
411  case op_ldiv_eq:
412  return op_ldiv;
413 
414  case op_pow_eq:
415  return op_pow;
416 
417  case op_el_mul_eq:
418  return op_el_mul;
419 
420  case op_el_div_eq:
421  return op_el_div;
422 
423  case op_el_ldiv_eq:
424  return op_el_ldiv;
425 
426  case op_el_pow_eq:
427  return op_el_pow;
428 
429  case op_el_and_eq:
430  return op_el_and;
431 
432  case op_el_or_eq:
433  return op_el_or;
434 
435  default:
436  return unknown_binary_op;
437  }
438 }
439 
442 {
443  switch (op)
444  {
445  case op_add:
446  return op_add_eq;
447 
448  case op_sub:
449  return op_sub_eq;
450 
451  case op_mul:
452  return op_mul_eq;
453 
454  case op_div:
455  return op_div_eq;
456 
457  case op_el_mul:
458  return op_el_mul_eq;
459 
460  case op_el_div:
461  return op_el_div_eq;
462 
463  case op_el_and:
464  return op_el_and_eq;
465 
466  case op_el_or:
467  return op_el_or_eq;
468 
469  default:
470  return unknown_assign_op;
471  }
472 }
473 
475  : rep (new octave_scalar (i))
476 { }
477 
478 octave_value::octave_value (unsigned short int i)
479  : rep (new octave_scalar (i))
480 { }
481 
483  : rep (new octave_scalar (i))
484 { }
485 
487  : rep (new octave_scalar (i))
488 { }
489 
491  : rep (new octave_scalar (i))
492 { }
493 
494 octave_value::octave_value (unsigned long int i)
495  : rep (new octave_scalar (i))
496 { }
497 
498 #if defined (OCTAVE_HAVE_LONG_LONG_INT)
499 octave_value::octave_value (long long int i)
500  : rep (new octave_scalar (i))
501 { }
502 #endif
503 
504 #if defined (OCTAVE_HAVE_UNSIGNED_LONG_LONG_INT)
505 octave_value::octave_value (unsigned long long int i)
506  : rep (new octave_scalar (i))
507 { }
508 #endif
509 
511  : rep (new octave_scalar (t.double_value ()))
512 { }
513 
515  : rep (new octave_scalar (d))
516 { }
517 
519  : rep (new octave_float_scalar (d))
520 { }
521 
522 octave_value::octave_value (const Cell& c, bool is_csl)
523  : rep (is_csl
524  ? dynamic_cast<octave_base_value *> (new octave_cs_list (c))
525  : dynamic_cast<octave_base_value *> (new octave_cell (c)))
526 { }
527 
529  : rep (is_csl
530  ? dynamic_cast<octave_base_value *> (new octave_cs_list (Cell (a)))
531  : dynamic_cast<octave_base_value *> (new octave_cell (Cell (a))))
532 { }
533 
535  : rep (new octave_matrix (m, t))
536 {
537  maybe_mutate ();
538 }
539 
541  : rep (new octave_float_matrix (m, t))
542 {
543  maybe_mutate ();
544 }
545 
547  : rep (new octave_matrix (a))
548 {
549  maybe_mutate ();
550 }
551 
553  : rep (new octave_float_matrix (a))
554 {
555  maybe_mutate ();
556 }
557 
559  : rep (new octave_matrix (a))
560 {
561  maybe_mutate ();
562 }
563 
565  : rep (new octave_float_matrix (a))
566 {
567  maybe_mutate ();
568 }
569 
571  : rep (Vdisable_diagonal_matrix
572  ? dynamic_cast<octave_base_value *> (new octave_matrix (Matrix (d)))
573  : dynamic_cast<octave_base_value *> (new octave_diag_matrix (d)))
574 {
575  maybe_mutate ();
576 }
577 
579  : rep (Vdisable_diagonal_matrix
580  ? dynamic_cast<octave_base_value *> (new octave_float_matrix (FloatMatrix (d)))
581  : dynamic_cast<octave_base_value *> (new octave_float_diag_matrix (d)))
582 {
583  maybe_mutate ();
584 }
585 
587  : rep (Vdisable_diagonal_matrix
588  ? dynamic_cast<octave_base_value *> (new octave_complex_matrix (ComplexMatrix (d)))
589  : dynamic_cast<octave_base_value *> (new octave_complex_diag_matrix (d)))
590 {
591  maybe_mutate ();
592 }
593 
595  : rep (Vdisable_diagonal_matrix
597  : dynamic_cast<octave_base_value *> (new octave_float_complex_diag_matrix (d)))
598 {
599  maybe_mutate ();
600 }
601 
603  : rep (Vdisable_diagonal_matrix
604  ? dynamic_cast<octave_base_value *> (new octave_matrix (Matrix (d)))
605  : dynamic_cast<octave_base_value *> (new octave_diag_matrix (d)))
606 {
607  maybe_mutate ();
608 }
609 
611  : rep (Vdisable_diagonal_matrix
612  ? dynamic_cast<octave_base_value *> (new octave_float_matrix (FloatMatrix (d)))
613  : dynamic_cast<octave_base_value *> (new octave_float_diag_matrix (d)))
614 {
615  maybe_mutate ();
616 }
617 
619  : rep (new octave_matrix (v))
620 {
621  maybe_mutate ();
622 }
623 
625  : rep (new octave_float_matrix (v))
626 {
627  maybe_mutate ();
628 }
629 
631  : rep (new octave_matrix (v))
632 {
633  maybe_mutate ();
634 }
635 
637  : rep (new octave_float_matrix (v))
638 {
639  maybe_mutate ();
640 }
641 
643  : rep (new octave_complex (C))
644 {
645  maybe_mutate ();
646 }
647 
649  : rep (new octave_float_complex (C))
650 {
651  maybe_mutate ();
652 }
653 
655  : rep (new octave_complex_matrix (m, t))
656 {
657  maybe_mutate ();
658 }
659 
661  : rep (new octave_float_complex_matrix (m, t))
662 {
663  maybe_mutate ();
664 }
665 
667  : rep (new octave_complex_matrix (a))
668 {
669  maybe_mutate ();
670 }
671 
673  : rep (new octave_float_complex_matrix (a))
674 {
675  maybe_mutate ();
676 }
677 
679  : rep (new octave_complex_matrix (a))
680 {
681  maybe_mutate ();
682 }
683 
685  : rep (new octave_float_complex_matrix (a))
686 {
687  maybe_mutate ();
688 }
689 
691  : rep (Vdisable_diagonal_matrix
692  ? dynamic_cast<octave_base_value *> (new octave_complex_matrix (ComplexMatrix (d)))
693  : dynamic_cast<octave_base_value *> (new octave_complex_diag_matrix (d)))
694 {
695  maybe_mutate ();
696 }
697 
699  : rep (Vdisable_diagonal_matrix
701  : dynamic_cast<octave_base_value *> (new octave_float_complex_diag_matrix (d)))
702 {
703  maybe_mutate ();
704 }
705 
707  : rep (new octave_complex_matrix (v))
708 {
709  maybe_mutate ();
710 }
711 
713  : rep (new octave_float_complex_matrix (v))
714 {
715  maybe_mutate ();
716 }
717 
719  : rep (new octave_complex_matrix (v))
720 {
721  maybe_mutate ();
722 }
723 
725  : rep (new octave_float_complex_matrix (v))
726 {
727  maybe_mutate ();
728 }
729 
731  : rep (Vdisable_permutation_matrix
732  ? dynamic_cast<octave_base_value *> (new octave_matrix (Matrix (p)))
733  : dynamic_cast<octave_base_value *> (new octave_perm_matrix (p)))
734 {
735  maybe_mutate ();
736 }
737 
739  : rep (new octave_bool (b))
740 { }
741 
743  : rep (new octave_bool_matrix (bm, t))
744 {
745  maybe_mutate ();
746 }
747 
749  : rep (new octave_bool_matrix (bnda))
750 {
751  maybe_mutate ();
752 }
753 
755  : rep (new octave_bool_matrix (bnda))
756 {
757  maybe_mutate ();
758 }
759 
761  : rep (type == '"'
762  ? new octave_char_matrix_dq_str (c)
763  : new octave_char_matrix_sq_str (c))
764 {
765  maybe_mutate ();
766 }
767 
768 octave_value::octave_value (const char *s, char type)
769  : rep (type == '"'
770  ? new octave_char_matrix_dq_str (s)
771  : new octave_char_matrix_sq_str (s))
772 {
773  maybe_mutate ();
774 }
775 
777  : rep (type == '"'
778  ? new octave_char_matrix_dq_str (s)
779  : new octave_char_matrix_sq_str (s))
780 {
781  maybe_mutate ();
782 }
783 
785  : rep (type == '"'
786  ? new octave_char_matrix_dq_str (s)
787  : new octave_char_matrix_sq_str (s))
788 {
789  maybe_mutate ();
790 }
791 
793  : rep (type == '"'
794  ? new octave_char_matrix_dq_str (chm)
795  : new octave_char_matrix_sq_str (chm))
796 {
797  maybe_mutate ();
798 }
799 
801  : rep (type == '"'
802  ? new octave_char_matrix_dq_str (chm)
803  : new octave_char_matrix_sq_str (chm))
804 {
805  maybe_mutate ();
806 }
807 
809  : rep (type == '"'
810  ? new octave_char_matrix_dq_str (chm)
811  : new octave_char_matrix_sq_str (chm))
812 {
813  maybe_mutate ();
814 }
815 
816 octave_value::octave_value (const charMatrix& chm, bool, char type)
817  : rep (type == '"'
818  ? new octave_char_matrix_dq_str (chm)
819  : new octave_char_matrix_sq_str (chm))
820 {
821  maybe_mutate ();
822 }
823 
825  : rep (type == '"'
826  ? new octave_char_matrix_dq_str (chm)
827  : new octave_char_matrix_sq_str (chm))
828 {
829  maybe_mutate ();
830 }
831 
832 octave_value::octave_value (const Array<char>& chm, bool, char type)
833  : rep (type == '"'
834  ? new octave_char_matrix_dq_str (chm)
835  : new octave_char_matrix_sq_str (chm))
836 {
837  maybe_mutate ();
838 }
839 
841  : rep (new octave_sparse_matrix (m, t))
842 {
843  maybe_mutate ();
844 }
845 
847  : rep (new octave_sparse_matrix (m, t))
848 {
849  maybe_mutate ();
850 }
851 
853  : rep (new octave_sparse_complex_matrix (m, t))
854 {
855  maybe_mutate ();
856 }
857 
859  : rep (new octave_sparse_complex_matrix (m, t))
860 {
861  maybe_mutate ();
862 }
863 
865  : rep (new octave_sparse_bool_matrix (bm, t))
866 {
867  maybe_mutate ();
868 }
869 
871  : rep (new octave_sparse_bool_matrix (bm, t))
872 {
873  maybe_mutate ();
874 }
875 
877  : rep (new octave_int8_scalar (i))
878 {
879  maybe_mutate ();
880 }
881 
883  : rep (new octave_uint8_scalar (i))
884 {
885  maybe_mutate ();
886 }
887 
889  : rep (new octave_int16_scalar (i))
890 {
891  maybe_mutate ();
892 }
893 
895  : rep (new octave_uint16_scalar (i))
896 {
897  maybe_mutate ();
898 }
899 
901  : rep (new octave_int32_scalar (i))
902 {
903  maybe_mutate ();
904 }
905 
907  : rep (new octave_uint32_scalar (i))
908 {
909  maybe_mutate ();
910 }
911 
913  : rep (new octave_int64_scalar (i))
914 {
915  maybe_mutate ();
916 }
917 
919  : rep (new octave_uint64_scalar (i))
920 {
921  maybe_mutate ();
922 }
923 
925  : rep (new octave_int8_matrix (inda))
926 {
927  maybe_mutate ();
928 }
929 
931  : rep (new octave_int8_matrix (inda))
932 {
933  maybe_mutate ();
934 }
935 
937  : rep (new octave_uint8_matrix (inda))
938 {
939  maybe_mutate ();
940 }
941 
943  : rep (new octave_uint8_matrix (inda))
944 {
945  maybe_mutate ();
946 }
947 
949  : rep (new octave_int16_matrix (inda))
950 {
951  maybe_mutate ();
952 }
953 
955  : rep (new octave_int16_matrix (inda))
956 {
957  maybe_mutate ();
958 }
959 
961  : rep (new octave_uint16_matrix (inda))
962 {
963  maybe_mutate ();
964 }
965 
967  : rep (new octave_uint16_matrix (inda))
968 {
969  maybe_mutate ();
970 }
971 
973  : rep (new octave_int32_matrix (inda))
974 {
975  maybe_mutate ();
976 }
977 
979  : rep (new octave_int32_matrix (inda))
980 {
981  maybe_mutate ();
982 }
983 
985  : rep (new octave_uint32_matrix (inda))
986 {
987  maybe_mutate ();
988 }
989 
991  : rep (new octave_uint32_matrix (inda))
992 {
993  maybe_mutate ();
994 }
995 
997  : rep (new octave_int64_matrix (inda))
998 {
999  maybe_mutate ();
1000 }
1001 
1003  : rep (new octave_int64_matrix (inda))
1004 {
1005  maybe_mutate ();
1006 }
1007 
1009  : rep (new octave_uint64_matrix (inda))
1010 {
1011  maybe_mutate ();
1012 }
1013 
1015  : rep (new octave_uint64_matrix (inda))
1016 {
1017  maybe_mutate ();
1018 }
1019 
1021  bool cache_index)
1022  : rep (new octave_matrix (inda, zero_based, cache_index))
1023 {
1024  maybe_mutate ();
1025 }
1026 
1028  : rep ()
1029 {
1030  double scalar;
1031  Range range;
1032  NDArray array;
1033  boolNDArray mask;
1034  idx_vector::idx_class_type idx_class;
1035 
1036  if (lazy)
1037  {
1038  // Only make lazy indices out of ranges and index vectors.
1039  switch (idx.idx_class ())
1040  {
1043  rep = new octave_lazy_index (idx);
1044  maybe_mutate ();
1045  return;
1046 
1047  default:
1048  break;
1049  }
1050  }
1051 
1052  idx.unconvert (idx_class, scalar, range, array, mask);
1053 
1054  switch (idx_class)
1055  {
1057  rep = new octave_magic_colon ();
1058  break;
1059 
1061  rep = new octave_range (range, idx);
1062  break;
1063 
1065  rep = new octave_scalar (scalar);
1066  break;
1067 
1069  rep = new octave_matrix (array, idx);
1070  break;
1071 
1073  rep = new octave_bool_matrix (mask, idx);
1074  break;
1075 
1076  default:
1077  panic_impossible ();
1078  break;
1079  }
1080 
1081  // FIXME: needed?
1082  maybe_mutate ();
1083 }
1084 
1086  : rep (new octave_cell (cellstr))
1087 {
1088  maybe_mutate ();
1089 }
1090 
1091 octave_value::octave_value (double base, double limit, double inc)
1092  : rep (new octave_range (base, limit, inc))
1093 {
1094  maybe_mutate ();
1095 }
1096 
1097 octave_value::octave_value (const Range& r, bool force_range)
1098  : rep (force_range || ! Vdisable_range
1099  ? dynamic_cast<octave_base_value *> (new octave_range (r))
1100  : dynamic_cast<octave_base_value *> (new octave_matrix (r.matrix_value ())))
1101 {
1102  maybe_mutate ();
1103 }
1104 
1106  : rep (new octave_struct (m))
1107 {
1108  maybe_mutate ();
1109 }
1110 
1112  : rep (new octave_scalar_struct (m))
1113 { }
1114 
1116  const std::list<std::string>& plist)
1117  : rep (new octave_class (m, id, plist))
1118 {
1119  maybe_mutate ();
1120 }
1121 
1123  const std::list<std::string>& plist)
1124  : rep (new octave_class (m, id, plist))
1125 { }
1126 
1128  : rep (new octave_cs_list (l))
1129 { }
1130 
1132  : rep (new octave_magic_colon ())
1133 { }
1134 
1136  : rep (new_rep)
1137 {
1138  if (borrow)
1139  rep->count++;
1140 }
1141 
1143  : rep (new_rep)
1144 {
1145  rep->count = xcount;
1146 }
1147 
1150 {
1151  return rep->clone ();
1152 }
1153 
1154 void
1156 {
1158 
1159  if (tmp && tmp != rep)
1160  {
1161  if (--rep->count == 0)
1162  delete rep;
1163 
1164  rep = tmp;
1165  }
1166 }
1167 
1168 DEFUN (double, args, ,
1169  doc: /* -*- texinfo -*-
1170 @deftypefn {} {} double (@var{x})
1171 Convert @var{x} to double precision type.
1172 @seealso{single}
1173 @end deftypefn */)
1174 {
1175  if (args.length () != 1)
1176  print_usage ();
1177 
1178  return ovl (args(0).as_double ());
1179 }
1180 
1181 /*
1182 %!assert (class (double (single (1))), "double")
1183 %!assert (class (double (single (1 + i))), "double")
1184 %!assert (class (double (int8 (1))), "double")
1185 %!assert (class (double (uint8 (1))), "double")
1186 %!assert (class (double (int16 (1))), "double")
1187 %!assert (class (double (uint16 (1))), "double")
1188 %!assert (class (double (int32 (1))), "double")
1189 %!assert (class (double (uint32 (1))), "double")
1190 %!assert (class (double (int64 (1))), "double")
1191 %!assert (class (double (uint64 (1))), "double")
1192 %!assert (class (double (true)), "double")
1193 %!assert (class (double ("A")), "double")
1194 %!test
1195 %! x = sparse (logical ([1 0; 0 1]));
1196 %! y = double (x);
1197 %! assert (class (x), "logical");
1198 %! assert (class (y), "double");
1199 %! assert (issparse (y));
1200 %!test
1201 %! x = diag (single ([1 3 2]));
1202 %! y = double (x);
1203 %! assert (class (x), "single");
1204 %! assert (class (y), "double");
1205 %!test
1206 %! x = diag (single ([i 3 2]));
1207 %! y = double (x);
1208 %! assert (class (x), "single");
1209 %! assert (class (y), "double");
1210 */
1211 
1212 DEFUN (single, args, ,
1213  doc: /* -*- texinfo -*-
1214 @deftypefn {} {} single (@var{x})
1215 Convert @var{x} to single precision type.
1216 @seealso{double}
1217 @end deftypefn */)
1218 {
1219  if (args.length () != 1)
1220  print_usage ();
1221 
1222  return args(0).as_single ();
1223 
1224  return ovl ();
1225 }
1226 
1227 /*
1228 %!assert (class (single (1)), "single")
1229 %!assert (class (single (1 + i)), "single")
1230 %!assert (class (single (int8 (1))), "single")
1231 %!assert (class (single (uint8 (1))), "single")
1232 %!assert (class (single (int16 (1))), "single")
1233 %!assert (class (single (uint16 (1))), "single")
1234 %!assert (class (single (int32 (1))), "single")
1235 %!assert (class (single (uint32 (1))), "single")
1236 %!assert (class (single (int64 (1))), "single")
1237 %!assert (class (single (uint64 (1))), "single")
1238 %!assert (class (single (true)), "single")
1239 %!assert (class (single ("A")), "single")
1240 %!error (single (sparse (1)))
1241 %!test
1242 %! x = diag ([1 3 2]);
1243 %! y = single (x);
1244 %! assert (class (x), "double");
1245 %! assert (class (y), "single");
1246 %!test
1247 %! x = diag ([i 3 2]);
1248 %! y = single (x);
1249 %! assert (class (x), "double");
1250 %! assert (class (y), "single");
1251 */
1252 
1253 DEFUN (int8, args, ,
1254  doc: /* -*- texinfo -*-
1255 @deftypefn {} {} int8 (@var{x})
1256 Convert @var{x} to 8-bit integer type.
1257 @seealso{uint8, int16, uint16, int32, uint32, int64, uint64}
1258 @end deftypefn */)
1259 {
1260  if (args.length () != 1)
1261  print_usage ();
1262 
1263  return args(0).as_int8 ();
1264 }
1265 
1266 /*
1267 %!assert (class (int8 (1)), "int8")
1268 %!assert (int8 (1.25), int8 (1))
1269 %!assert (int8 (1.5), int8 (2))
1270 %!assert (int8 (-1.5), int8 (-2))
1271 %!assert (int8 (2^9), int8 (2^8-1))
1272 %!assert (int8 (-2^9), int8 (-2^8))
1273 */
1274 
1275 DEFUN (int16, args, ,
1276  doc: /* -*- texinfo -*-
1277 @deftypefn {} {} int16 (@var{x})
1278 Convert @var{x} to 16-bit integer type.
1279 @seealso{int8, uint8, uint16, int32, uint32, int64, uint64}
1280 @end deftypefn */)
1281 {
1282  if (args.length () != 1)
1283  print_usage ();
1284 
1285  return args(0).as_int16 ();
1286 }
1287 
1288 /*
1289 %!assert (class (int16 (1)), "int16")
1290 %!assert (int16 (1.25), int16 (1))
1291 %!assert (int16 (1.5), int16 (2))
1292 %!assert (int16 (-1.5), int16 (-2))
1293 %!assert (int16 (2^17), int16 (2^16-1))
1294 %!assert (int16 (-2^17), int16 (-2^16))
1295 */
1296 
1297 DEFUN (int32, args, ,
1298  doc: /* -*- texinfo -*-
1299 @deftypefn {} {} int32 (@var{x})
1300 Convert @var{x} to 32-bit integer type.
1301 @seealso{int8, uint8, int16, uint16, uint32, int64, uint64}
1302 @end deftypefn */)
1303 {
1304  if (args.length () != 1)
1305  print_usage ();
1306 
1307  return args(0).as_int32 ();
1308 }
1309 
1310 /*
1311 %!assert (class (int32 (1)), "int32")
1312 %!assert (int32 (1.25), int32 (1))
1313 %!assert (int32 (1.5), int32 (2))
1314 %!assert (int32 (-1.5), int32 (-2))
1315 %!assert (int32 (2^33), int32 (2^32-1))
1316 %!assert (int32 (-2^33), int32 (-2^32))
1317 */
1318 
1319 DEFUN (int64, args, ,
1320  doc: /* -*- texinfo -*-
1321 @deftypefn {} {} int64 (@var{x})
1322 Convert @var{x} to 64-bit integer type.
1323 @seealso{int8, uint8, int16, uint16, int32, uint32, uint64}
1324 @end deftypefn */)
1325 {
1326  if (args.length () != 1)
1327  print_usage ();
1328 
1329  return args(0).as_int64 ();
1330 }
1331 
1332 /*
1333 %!assert (class (int64 (1)), "int64")
1334 %!assert (int64 (1.25), int64 (1))
1335 %!assert (int64 (1.5), int64 (2))
1336 %!assert (int64 (-1.5), int64 (-2))
1337 %!assert (int64 (2^65), int64 (2^64-1))
1338 %!assert (int64 (-2^65), int64 (-2^64))
1339 */
1340 
1341 DEFUN (uint8, args, ,
1342  doc: /* -*- texinfo -*-
1343 @deftypefn {} {} uint8 (@var{x})
1344 Convert @var{x} to unsigned 8-bit integer type.
1345 @seealso{int8, int16, uint16, int32, uint32, int64, uint64}
1346 @end deftypefn */)
1347 {
1348  if (args.length () != 1)
1349  print_usage ();
1350 
1351  return args(0).as_uint8 ();
1352 }
1353 
1354 /*
1355 %!assert (class (uint8 (1)), "uint8")
1356 %!assert (uint8 (1.25), uint8 (1))
1357 %!assert (uint8 (1.5), uint8 (2))
1358 %!assert (uint8 (-1.5), uint8 (0))
1359 %!assert (uint8 (2^9), uint8 (2^8-1))
1360 %!assert (uint8 (-2^9), uint8 (0))
1361 */
1362 
1363 DEFUN (uint16, args, ,
1364  doc: /* -*- texinfo -*-
1365 @deftypefn {} {} uint16 (@var{x})
1366 Convert @var{x} to unsigned 16-bit integer type.
1367 @seealso{int8, uint8, int16, int32, uint32, int64, uint64}
1368 @end deftypefn */)
1369 {
1370  if (args.length () != 1)
1371  print_usage ();
1372 
1373  return args(0).as_uint16 ();
1374 }
1375 
1376 /*
1377 %!assert (class (uint16 (1)), "uint16")
1378 %!assert (uint16 (1.25), uint16 (1))
1379 %!assert (uint16 (1.5), uint16 (2))
1380 %!assert (uint16 (-1.5), uint16 (0))
1381 %!assert (uint16 (2^17), uint16 (2^16-1))
1382 %!assert (uint16 (-2^17), uint16 (0))
1383 */
1384 
1385 DEFUN (uint32, args, ,
1386  doc: /* -*- texinfo -*-
1387 @deftypefn {} {} uint32 (@var{x})
1388 Convert @var{x} to unsigned 32-bit integer type.
1389 @seealso{int8, uint8, int16, uint16, int32, int64, uint64}
1390 @end deftypefn */)
1391 {
1392  if (args.length () != 1)
1393  print_usage ();
1394 
1395  return args(0).as_uint32 ();
1396 }
1397 
1398 /*
1399 %!assert (class (uint32 (1)), "uint32")
1400 %!assert (uint32 (1.25), uint32 (1))
1401 %!assert (uint32 (1.5), uint32 (2))
1402 %!assert (uint32 (-1.5), uint32 (0))
1403 %!assert (uint32 (2^33), uint32 (2^32-1))
1404 %!assert (uint32 (-2^33), uint32 (0))
1405 */
1406 
1407 DEFUN (uint64, args, ,
1408  doc: /* -*- texinfo -*-
1409 @deftypefn {} {} uint64 (@var{x})
1410 Convert @var{x} to unsigned 64-bit integer type.
1411 @seealso{int8, uint8, int16, uint16, int32, uint32, int64}
1412 @end deftypefn */)
1413 {
1414  if (args.length () != 1)
1415  print_usage ();
1416 
1417  return args(0).as_uint64 ();
1418 }
1419 
1420 /*
1421 %!assert (class (uint64 (1)), "uint64")
1422 %!assert (uint64 (1.25), uint64 (1))
1423 %!assert (uint64 (1.5), uint64 (2))
1424 %!assert (uint64 (-1.5), uint64 (0))
1425 %!assert (uint64 (2^65), uint64 (2^64-1))
1426 %!assert (uint64 (-2^65), uint64 (0))
1427 */
1428 
1431  const octave_value_list& idx)
1432 {
1433  std::list<octave_value_list> i;
1434 
1435  i.push_back (idx);
1436 
1437  return rep->subsref (type, i);
1438 }
1439 
1442  const std::list<octave_value_list>& idx, int nargout)
1443 {
1444  if (nargout == 1)
1445  return rep->subsref (type, idx);
1446  else
1447  return rep->subsref (type, idx, nargout);
1448 }
1449 
1452  const std::list<octave_value_list>& idx, int nargout,
1453  const std::list<octave_lvalue> *lvalue_list)
1454 {
1455  if (lvalue_list)
1456  return rep->subsref (type, idx, nargout, lvalue_list);
1457  else
1458  return subsref (type, idx, nargout);
1459 }
1460 
1463  const std::list<octave_value_list>& idx,
1464  size_t skip)
1465 {
1466  if (idx.size () > skip)
1467  {
1468  std::list<octave_value_list> new_idx (idx);
1469  for (size_t i = 0; i < skip; i++)
1470  new_idx.erase (new_idx.begin ());
1471  return subsref (type.substr (skip), new_idx);
1472  }
1473  else
1474  return *this;
1475 }
1476 
1479  const std::list<octave_value_list>& idx,
1480  size_t skip)
1481 {
1482  if (idx.size () > skip)
1483  {
1484  std::list<octave_value_list> new_idx (idx);
1485  for (size_t i = 0; i < skip; i++)
1486  new_idx.erase (new_idx.begin ());
1487  return subsref (type.substr (skip), new_idx, nargout);
1488  }
1489  else
1490  return *this;
1491 }
1492 
1495  const std::list<octave_value_list>& idx,
1496  const std::list<octave_lvalue> *lvalue_list,
1497  size_t skip)
1498 {
1499  if (idx.size () > skip)
1500  {
1501  std::list<octave_value_list> new_idx (idx);
1502  for (size_t i = 0; i < skip; i++)
1503  new_idx.erase (new_idx.begin ());
1504  return subsref (type.substr (skip), new_idx, nargout, lvalue_list);
1505  }
1506  else
1507  return *this;
1508 }
1509 
1512  const std::list<octave_value_list>& idx,
1513  size_t skip)
1514 {
1515  if (idx.size () > skip)
1516  {
1517  std::list<octave_value_list> new_idx (idx);
1518  for (size_t i = 0; i < skip; i++)
1519  new_idx.erase (new_idx.begin ());
1520  return subsref (type.substr (skip), new_idx, auto_add);
1521  }
1522  else
1523  return *this;
1524 }
1525 
1528 {
1529  return rep->do_multi_index_op (nargout, idx);
1530 }
1531 
1534  const std::list<octave_lvalue> *lvalue_list)
1535 {
1536  return rep->do_multi_index_op (nargout, idx, lvalue_list);
1537 }
1538 
1541  const std::list<octave_value_list>& idx,
1542  const octave_value& rhs)
1543 {
1544  return rep->subsasgn (type, idx, rhs);
1545 }
1546 
1549  const std::list<octave_value_list>& idx,
1550  const octave_value& rhs)
1551 {
1552  return rep->undef_subsasgn (type, idx, rhs);
1553 }
1554 
1555 octave_value&
1557  const std::list<octave_value_list>& idx,
1558  const octave_value& rhs)
1559 {
1560  make_unique ();
1561 
1562  octave_value t_rhs = rhs;
1563 
1564  if (op != op_asn_eq)
1565  {
1566  if (! is_defined ())
1567  error ("in computed assignment A(index) OP= X, A must be defined first");
1568 
1569  octave_value t = subsref (type, idx);
1570 
1571  binary_op binop = op_eq_to_binary_op (op);
1572 
1573  t_rhs = do_binary_op (binop, t, rhs);
1574  }
1575 
1576  *this = subsasgn (type, idx, t_rhs);
1577 
1578  return *this;
1579 }
1580 
1581 octave_value&
1583 {
1584  if (op == op_asn_eq)
1585  // Regularize a null matrix if stored into a variable.
1586  operator = (rhs.storable_value ());
1587  else if (is_defined ())
1588  {
1590 
1591  // Only attempt to operate in-place if this variable is unshared.
1592  if (rep->count == 1)
1593  {
1594  int tthis = this->type_id ();
1595  int trhs = rhs.type_id ();
1596 
1597  f = octave_value_typeinfo::lookup_assign_op (op, tthis, trhs);
1598  }
1599 
1600  if (f)
1601  {
1602  f (*rep, octave_value_list (), *rhs.rep);
1603  // Usually unnecessary, but may be needed (complex arrays).
1604  maybe_mutate ();
1605  }
1606  else
1607  {
1608 
1609  binary_op binop = op_eq_to_binary_op (op);
1610 
1611  octave_value t = do_binary_op (binop, *this, rhs);
1612 
1613  operator = (t);
1614  }
1615  }
1616  else
1617  error ("in computed assignment A OP= X, A must be defined first");
1618 
1619  return *this;
1620 }
1621 
1624 {
1625  octave_idx_type retval = 0;
1626 
1627  const dim_vector dv = dims ();
1628 
1629  for (int i = 0; i < dv.ndims (); i++)
1630  {
1631  if (dv(i) == 0)
1632  {
1633  retval = 0;
1634  break;
1635  }
1636 
1637  if (dv(i) > retval)
1638  retval = dv(i);
1639  }
1640 
1641  return retval;
1642 }
1643 
1644 bool
1646 {
1647  bool retval = false;
1648 
1649  // If there is no op_eq for these types, we can't compare values.
1650 
1651  if (rows () == test.rows () && columns () == test.columns ())
1652  {
1654 
1655  // Empty array also means a match.
1656  if (tmp.is_defined ())
1657  {
1658  if (tmp.is_empty ())
1659  retval = true;
1660  else
1661  {
1662  // Reshape into a vector and call all() explicitly,
1663  // to avoid Octave:array-as-logical warning.
1664  tmp = tmp.reshape (dim_vector (tmp.numel (), 1));
1665  retval = tmp.all ().is_true ();
1666  }
1667  }
1668  }
1669 
1670  return retval;
1671 }
1672 
1673 // Define the idx_type_value function here instead of in ov.h to avoid
1674 // needing definitions for the SIZEOF_X macros in ov.h.
1675 
1677 octave_value::idx_type_value (bool req_int, bool frc_str_conv) const
1678 {
1679 #if defined (OCTAVE_ENABLE_64)
1680  return int64_value (req_int, frc_str_conv);
1681 #else
1682  return int_value (req_int, frc_str_conv);
1683 #endif
1684 }
1685 
1686 Cell
1688 {
1689  return rep->cell_value ();
1690 }
1691 
1692 octave_map
1694 {
1695  return rep->map_value ();
1696 }
1697 
1700 {
1701  return rep->scalar_map_value ();
1702 }
1703 
1705 octave_value::function_value (bool silent) const
1706 {
1707  return rep->function_value (silent);
1708 }
1709 
1712 {
1713  return rep->user_function_value (silent);
1714 }
1715 
1718 {
1719  return rep->user_script_value (silent);
1720 }
1721 
1724 {
1725  return rep->user_code_value (silent);
1726 }
1727 
1730 {
1731  return rep->fcn_handle_value (silent);
1732 }
1733 
1736 {
1737  return rep->fcn_inline_value (silent);
1738 }
1739 
1742 {
1743  return rep->list_value ();
1744 }
1745 
1746 static dim_vector
1747 make_vector_dims (const dim_vector& dv, bool force_vector_conversion,
1748  const std::string& my_type, const std::string& wanted_type)
1749 {
1750  dim_vector retval (dv);
1751  retval.chop_trailing_singletons ();
1752  octave_idx_type nel = dv.numel ();
1753 
1754  if (retval.ndims () > 2 || (retval(0) != 1 && retval(1) != 1))
1755  {
1756  if (! force_vector_conversion)
1757  warn_implicit_conversion ("Octave:array-to-vector",
1758  my_type.c_str (), wanted_type.c_str ());
1759  retval = dim_vector (nel, 1);
1760  }
1761 
1762  return retval;
1763 }
1764 
1766 octave_value::column_vector_value (bool force_string_conv,
1767  bool frc_vec_conv) const
1768 {
1769  return ColumnVector (vector_value (force_string_conv,
1770  frc_vec_conv));
1771 }
1772 
1775  bool frc_vec_conv) const
1776 {
1777  return ComplexColumnVector (complex_vector_value (force_string_conv,
1778  frc_vec_conv));
1779 }
1780 
1781 RowVector
1782 octave_value::row_vector_value (bool force_string_conv,
1783  bool frc_vec_conv) const
1784 {
1785  return RowVector (vector_value (force_string_conv,
1786  frc_vec_conv));
1787 }
1788 
1791  bool frc_vec_conv) const
1792 {
1793  return ComplexRowVector (complex_vector_value (force_string_conv,
1794  frc_vec_conv));
1795 }
1796 
1798 octave_value::vector_value (bool force_string_conv,
1799  bool force_vector_conversion) const
1800 {
1801  Array<double> retval = array_value (force_string_conv);
1802 
1803  return retval.reshape (make_vector_dims (retval.dims (),
1804  force_vector_conversion,
1805  type_name (), "real vector"));
1806 }
1807 
1808 template <typename T>
1809 static Array<int>
1811 {
1812  Array<int> retval (A.dims ());
1813  octave_idx_type n = A.numel ();
1814 
1815  for (octave_idx_type i = 0; i < n; i++)
1816  retval.xelem (i) = octave_int<int> (A.xelem (i));
1817 
1818  return retval;
1819 }
1820 
1821 Array<int>
1822 octave_value::int_vector_value (bool require_int, bool force_string_conv,
1823  bool force_vector_conversion) const
1824 {
1826 
1827  if (is_integer_type ())
1828  {
1829  if (is_int32_type ())
1831  else if (is_int64_type ())
1833  else if (is_int16_type ())
1835  else if (is_int8_type ())
1836  retval = convert_to_int_array (int8_array_value ());
1837  else if (is_uint32_type ())
1839  else if (is_uint64_type ())
1841  else if (is_uint16_type ())
1843  else if (is_uint8_type ())
1845  else
1846  retval = array_value (force_string_conv);
1847  }
1848  else
1849  {
1850  const NDArray a = array_value (force_string_conv);
1851 
1852  if (require_int)
1853  {
1854  retval.resize (a.dims ());
1855  for (octave_idx_type i = 0; i < a.numel (); i++)
1856  {
1857  double ai = a.elem (i);
1858  int v = static_cast<int> (ai);
1859  if (ai == v)
1860  retval.xelem (i) = v;
1861  else
1862  {
1863  error_with_cfn ("conversion to integer value failed");
1864  break;
1865  }
1866  }
1867  }
1868  else
1869  retval = Array<int> (a);
1870  }
1871 
1872  return retval.reshape (make_vector_dims (retval.dims (),
1873  force_vector_conversion,
1874  type_name (), "integer vector"));
1875 }
1876 
1877 template <typename T>
1880 {
1881  Array<octave_idx_type> retval (A.dims ());
1882  octave_idx_type n = A.numel ();
1883 
1884  for (octave_idx_type i = 0; i < n; i++)
1885  retval.xelem (i) = octave_int<octave_idx_type> (A.xelem (i));
1886 
1887  return retval;
1888 }
1889 
1892  bool force_string_conv,
1893  bool force_vector_conversion) const
1894 {
1896 
1897  if (is_integer_type ())
1898  {
1899  if (is_int32_type ())
1901  else if (is_int64_type ())
1903  else if (is_int16_type ())
1905  else if (is_int8_type ())
1907  else if (is_uint32_type ())
1909  else if (is_uint64_type ())
1911  else if (is_uint16_type ())
1913  else if (is_uint8_type ())
1915  else
1916  retval = array_value (force_string_conv);
1917  }
1918  else
1919  {
1920  const NDArray a = array_value (force_string_conv);
1921 
1922  if (require_int)
1923  {
1924  retval.resize (a.dims ());
1925  for (octave_idx_type i = 0; i < a.numel (); i++)
1926  {
1927  double ai = a.elem (i);
1928  octave_idx_type v = static_cast<octave_idx_type> (ai);
1929  if (ai == v)
1930  retval.xelem (i) = v;
1931  else
1932  {
1933  error_with_cfn ("conversion to integer value failed");
1934  break;
1935  }
1936  }
1937  }
1938  else
1939  retval = Array<octave_idx_type> (a);
1940  }
1941 
1942  return retval.reshape (make_vector_dims (retval.dims (),
1943  force_vector_conversion,
1944  type_name (), "integer vector"));
1945 }
1946 
1948 octave_value::complex_vector_value (bool force_string_conv,
1949  bool force_vector_conversion) const
1950 {
1951  Array<Complex> retval = complex_array_value (force_string_conv);
1952 
1953  return retval.reshape (make_vector_dims (retval.dims (),
1954  force_vector_conversion,
1955  type_name (), "complex vector"));
1956 }
1957 
1960  bool frc_vec_conv) const
1961 {
1962  return FloatColumnVector (float_vector_value (force_string_conv,
1963  frc_vec_conv));
1964 }
1965 
1968  bool frc_vec_conv) const
1969 {
1970  return
1972  frc_vec_conv));
1973 }
1974 
1977  bool frc_vec_conv) const
1978 {
1979  return FloatRowVector (float_vector_value (force_string_conv,
1980  frc_vec_conv));
1981 }
1982 
1985  bool frc_vec_conv) const
1986 {
1987  return FloatComplexRowVector (float_complex_vector_value (force_string_conv,
1988  frc_vec_conv));
1989 }
1990 
1992 octave_value::float_vector_value (bool force_string_conv,
1993  bool force_vector_conversion) const
1994 {
1995  Array<float> retval = float_array_value (force_string_conv);
1996 
1997  return retval.reshape (make_vector_dims (retval.dims (),
1998  force_vector_conversion,
1999  type_name (), "real vector"));
2000 }
2001 
2004  bool force_vector_conversion) const
2005 {
2007 
2008  return retval.reshape (make_vector_dims (retval.dims (),
2009  force_vector_conversion,
2010  type_name (), "complex vector"));
2011 }
2012 
2013 // NAME can't always be "x ## FCN" because some of the original
2014 // value extraction functions perform implicit type conversions that we
2015 // wish to avoid for these functions.
2016 
2017 #define XVALUE_EXTRACTOR(TYPE, NAME, FCN) \
2018  TYPE \
2019  octave_value::NAME (const char *fmt, ...) const \
2020  { \
2021  TYPE retval; \
2022  \
2023  try \
2024  { \
2025  retval = FCN (); \
2026  } \
2027  catch (octave::execution_exception& e) \
2028  { \
2029  if (fmt) \
2030  { \
2031  va_list args; \
2032  va_start (args, fmt); \
2033  verror (e, fmt, args); \
2034  va_end (args); \
2035  } \
2036  \
2037  throw e; \
2038  } \
2039  \
2040  return retval; \
2041  }
2042 
2043 XVALUE_EXTRACTOR (short int, xshort_value, short_value)
2044 
2045 XVALUE_EXTRACTOR (unsigned short int, xushort_value, ushort_value)
2046 
2047 XVALUE_EXTRACTOR (int, xint_value, int_value)
2048 
2049 XVALUE_EXTRACTOR (unsigned int, xuint_value, uint_value)
2050 
2051 XVALUE_EXTRACTOR (int, xnint_value, nint_value)
2052 
2053 XVALUE_EXTRACTOR (long int, xlong_value, long_value)
2054 
2055 XVALUE_EXTRACTOR (unsigned long int, xulong_value, ulong_value)
2056 
2057 XVALUE_EXTRACTOR (int64_t, xint64_value, int64_value)
2058 
2059 XVALUE_EXTRACTOR (uint64_t, xuint64_value, uint64_value)
2060 
2061 XVALUE_EXTRACTOR (octave_idx_type, xidx_type_value, idx_type_value)
2062 
2063 XVALUE_EXTRACTOR (double, xdouble_value, double_value)
2064 XVALUE_EXTRACTOR (float, xfloat_value, float_value)
2065 
2066 XVALUE_EXTRACTOR (double, xscalar_value, scalar_value)
2067 XVALUE_EXTRACTOR (float, xfloat_scalar_value, float_scalar_value)
2068 
2069 XVALUE_EXTRACTOR (Matrix, xmatrix_value, matrix_value)
2070 XVALUE_EXTRACTOR (FloatMatrix, xfloat_matrix_value, float_matrix_value)
2071 
2072 XVALUE_EXTRACTOR (NDArray, xarray_value, array_value)
2073 XVALUE_EXTRACTOR (FloatNDArray, xfloat_array_value, float_array_value)
2074 
2075 XVALUE_EXTRACTOR (Complex, xcomplex_value, complex_value)
2076 XVALUE_EXTRACTOR (FloatComplex, xfloat_complex_value, float_complex_value)
2077 
2078 XVALUE_EXTRACTOR (ComplexMatrix, xcomplex_matrix_value, complex_matrix_value)
2079 XVALUE_EXTRACTOR (FloatComplexMatrix, xfloat_complex_matrix_value, float_complex_matrix_value)
2080 
2081 XVALUE_EXTRACTOR (ComplexNDArray, xcomplex_array_value, complex_array_value)
2082 XVALUE_EXTRACTOR (FloatComplexNDArray, xfloat_complex_array_value, float_complex_array_value)
2083 
2084 XVALUE_EXTRACTOR (bool, xbool_value, bool_value)
2085 XVALUE_EXTRACTOR (boolMatrix, xbool_matrix_value, bool_matrix_value)
2086 XVALUE_EXTRACTOR (boolNDArray, xbool_array_value, bool_array_value)
2087 
2088 XVALUE_EXTRACTOR (charMatrix, xchar_matrix_value, char_matrix_value)
2089 XVALUE_EXTRACTOR (charNDArray, xchar_array_value, char_array_value)
2090 
2091 XVALUE_EXTRACTOR (SparseMatrix, xsparse_matrix_value, sparse_matrix_value)
2092 XVALUE_EXTRACTOR (SparseComplexMatrix, xsparse_complex_matrix_value, sparse_complex_matrix_value)
2093 XVALUE_EXTRACTOR (SparseBoolMatrix, xsparse_bool_matrix_value, sparse_bool_matrix_value)
2094 
2095 XVALUE_EXTRACTOR (DiagMatrix, xdiag_matrix_value, diag_matrix_value)
2096 XVALUE_EXTRACTOR (FloatDiagMatrix, xfloat_diag_matrix_value, float_diag_matrix_value)
2097 XVALUE_EXTRACTOR (ComplexDiagMatrix, xcomplex_diag_matrix_value, complex_diag_matrix_value)
2098 XVALUE_EXTRACTOR (FloatComplexDiagMatrix, xfloat_complex_diag_matrix_value, float_complex_diag_matrix_value)
2099 
2100 XVALUE_EXTRACTOR (PermMatrix, xperm_matrix_value, perm_matrix_value)
2101 
2102 XVALUE_EXTRACTOR (octave_int8, xint8_scalar_value, int8_scalar_value)
2103 XVALUE_EXTRACTOR (octave_int16, xint16_scalar_value, int16_scalar_value)
2104 XVALUE_EXTRACTOR (octave_int32, xint32_scalar_value, int32_scalar_value)
2105 XVALUE_EXTRACTOR (octave_int64, xint64_scalar_value, int64_scalar_value)
2106 
2107 XVALUE_EXTRACTOR (octave_uint8, xuint8_scalar_value, uint8_scalar_value)
2108 XVALUE_EXTRACTOR (octave_uint16, xuint16_scalar_value, uint16_scalar_value)
2109 XVALUE_EXTRACTOR (octave_uint32, xuint32_scalar_value, uint32_scalar_value)
2110 XVALUE_EXTRACTOR (octave_uint64, xuint64_scalar_value, uint64_scalar_value)
2111 
2112 XVALUE_EXTRACTOR (int8NDArray, xint8_array_value, int8_array_value)
2113 XVALUE_EXTRACTOR (int16NDArray, xint16_array_value, int16_array_value)
2114 XVALUE_EXTRACTOR (int32NDArray, xint32_array_value, int32_array_value)
2115 XVALUE_EXTRACTOR (int64NDArray, xint64_array_value, int64_array_value)
2116 
2117 XVALUE_EXTRACTOR (uint8NDArray, xuint8_array_value, uint8_array_value)
2118 XVALUE_EXTRACTOR (uint16NDArray, xuint16_array_value, uint16_array_value)
2119 XVALUE_EXTRACTOR (uint32NDArray, xuint32_array_value, uint32_array_value)
2120 XVALUE_EXTRACTOR (uint64NDArray, xuint64_array_value, uint64_array_value)
2121 
2122 XVALUE_EXTRACTOR (std::string, xstring_value, rep->xstring_value)
2123 XVALUE_EXTRACTOR (string_vector, xstring_vector_value, string_vector_value)
2124 
2125 XVALUE_EXTRACTOR (Cell, xcell_value, cell_value)
2126 XVALUE_EXTRACTOR (Array<std::string>, xcellstr_value, cellstr_value)
2127 
2128 XVALUE_EXTRACTOR (Range, xrange_value, range_value)
2129 
2130 XVALUE_EXTRACTOR (octave_map, xmap_value, map_value)
2131 XVALUE_EXTRACTOR (octave_scalar_map, xscalar_map_value, scalar_map_value)
2132 
2133 XVALUE_EXTRACTOR (ColumnVector, xcolumn_vector_value, column_vector_value)
2134 XVALUE_EXTRACTOR (ComplexColumnVector, xcomplex_column_vector_value, complex_column_vector_value)
2135 
2136 XVALUE_EXTRACTOR (RowVector, xrow_vector_value, row_vector_value)
2137 XVALUE_EXTRACTOR (ComplexRowVector, xcomplex_row_vector_value, complex_row_vector_value)
2138 
2139 XVALUE_EXTRACTOR (FloatColumnVector, xfloat_column_vector_value, float_column_vector_value)
2140 XVALUE_EXTRACTOR (FloatComplexColumnVector, xfloat_complex_column_vector_value, float_complex_column_vector_value)
2141 
2142 XVALUE_EXTRACTOR (FloatRowVector, xfloat_row_vector_value, float_row_vector_value)
2143 XVALUE_EXTRACTOR (FloatComplexRowVector, xfloat_complex_row_vector_value, float_complex_row_vector_value)
2144 
2145 XVALUE_EXTRACTOR (Array<int>, xint_vector_value, int_vector_value)
2146 XVALUE_EXTRACTOR (Array<octave_idx_type>, xoctave_idx_type_vector_value, octave_idx_type_vector_value)
2147 
2148 XVALUE_EXTRACTOR (Array<double>, xvector_value, vector_value)
2149 XVALUE_EXTRACTOR (Array<Complex>, xcomplex_vector_value, complex_vector_value)
2150 
2151 XVALUE_EXTRACTOR (Array<float>, xfloat_vector_value, float_vector_value)
2152 XVALUE_EXTRACTOR (Array<FloatComplex>, xfloat_complex_vector_value, float_complex_vector_value)
2153 
2154 XVALUE_EXTRACTOR (octave_function *, xfunction_value, function_value)
2155 XVALUE_EXTRACTOR (octave_user_function *, xuser_function_value, user_function_value)
2156 XVALUE_EXTRACTOR (octave_user_script *, xuser_script_value, user_script_value)
2157 XVALUE_EXTRACTOR (octave_user_code *, xuser_code_value, user_code_value)
2158 XVALUE_EXTRACTOR (octave_fcn_handle *, xfcn_handle_value, fcn_handle_value)
2159 XVALUE_EXTRACTOR (octave_fcn_inline *, xfcn_inline_value, fcn_inline_value)
2160 
2161 XVALUE_EXTRACTOR (octave_value_list, xlist_value, list_value)
2162 
2163 #undef XVALUE_EXTRACTOR
2164 
2167 {
2168  octave_value retval = *this;
2169  if (is_null_value ())
2170  retval = octave_value (rep->empty_clone ());
2171  else
2172  retval.maybe_economize ();
2173 
2174  return retval;
2175 }
2176 
2177 void
2179 {
2180  if (is_null_value ())
2181  {
2182  octave_base_value *rc = rep->empty_clone ();
2183  if (--rep->count == 0)
2184  delete rep;
2185  rep = rc;
2186  }
2187  else
2188  maybe_economize ();
2189 }
2190 
2191 int
2192 octave_value::write (octave_stream& os, int block_size,
2193  oct_data_conv::data_type output_type, int skip,
2195 {
2196  return rep->write (os, block_size, output_type, skip, flt_fmt);
2197 }
2198 
2199 OCTAVE_NORETURN static void
2200 err_binary_op (const std::string& on, const std::string& tn1,
2201  const std::string& tn2)
2202 {
2203  error ("binary operator '%s' not implemented for '%s' by '%s' operations",
2204  on.c_str (), tn1.c_str (), tn2.c_str ());
2205 }
2206 
2207 OCTAVE_NORETURN static void
2209 {
2210  error ("type conversion failed for binary operator '%s'", on.c_str ());
2211 }
2212 
2215  const octave_value& v1, const octave_value& v2)
2216 {
2218 
2219  int t1 = v1.type_id ();
2220  int t2 = v2.type_id ();
2221 
2222  if (t1 == octave_class::static_type_id ()
2223  || t2 == octave_class::static_type_id ()
2225  || t2 == octave_classdef::static_type_id ())
2226  {
2229 
2230  if (! f)
2232  v1.class_name (), v2.class_name ());
2233 
2234  retval = f (v1, v2);
2235  }
2236  else
2237  {
2238  // FIXME: we need to handle overloading operators for built-in
2239  // classes (double, char, int8, etc.)
2240 
2243 
2244  if (f)
2245  retval = f (*v1.rep, *v2.rep);
2246  else
2247  {
2248  octave_value tv1;
2251 
2252  octave_value tv2;
2255 
2256  // Try biased (one-sided) conversions first.
2257  if (cf2.type_id () >= 0
2259  cf2.type_id ()))
2260  cf1 = 0;
2261  else if (cf1.type_id () >= 0
2263  cf1.type_id (),
2264  t2))
2265  cf2 = 0;
2266 
2267  if (cf1)
2268  {
2269  octave_base_value *tmp = cf1 (*v1.rep);
2270 
2271  if (! tmp)
2273 
2274  tv1 = octave_value (tmp);
2275  t1 = tv1.type_id ();
2276  }
2277  else
2278  tv1 = v1;
2279 
2280  if (cf2)
2281  {
2282  octave_base_value *tmp = cf2 (*v2.rep);
2283 
2284  if (! tmp)
2286 
2287  tv2 = octave_value (tmp);
2288  t2 = tv2.type_id ();
2289  }
2290  else
2291  tv2 = v2;
2292 
2293  if (cf1 || cf2)
2294  {
2295  retval = do_binary_op (op, tv1, tv2);
2296  }
2297  else
2298  {
2299  //demote double -> single and try again
2300  cf1 = tv1.numeric_demotion_function ();
2301 
2302  cf2 = tv2.numeric_demotion_function ();
2303 
2304  // Try biased (one-sided) conversions first.
2305  if (cf2.type_id () >= 0
2307  cf2.type_id ()))
2308  cf1 = 0;
2309  else if (cf1.type_id () >= 0
2311  cf1.type_id (),
2312  t2))
2313  cf2 = 0;
2314 
2315  if (cf1)
2316  {
2317  octave_base_value *tmp = cf1 (*tv1.rep);
2318 
2319  if (! tmp)
2321 
2322  tv1 = octave_value (tmp);
2323  t1 = tv1.type_id ();
2324  }
2325 
2326  if (cf2)
2327  {
2328  octave_base_value *tmp = cf2 (*tv2.rep);
2329 
2330  if (! tmp)
2332 
2333  tv2 = octave_value (tmp);
2334  t2 = tv2.type_id ();
2335  }
2336 
2337  if (! cf1 && ! cf2)
2339  v1.type_name (), v2.type_name ());
2340 
2341  f = octave_value_typeinfo::lookup_binary_op (op, t1, t2);
2342 
2343  if (! f)
2345  v1.type_name (), v2.type_name ());
2346 
2347  retval = f (*tv1.rep, *tv2.rep);
2348  }
2349  }
2350  }
2351 
2352  return retval;
2353 }
2354 
2355 static octave_value
2357  const octave_value& v1, const octave_value& v2)
2358 {
2359  switch (op)
2360  {
2364 
2368 
2372 
2376 
2380 
2384 
2387  do_unary_op (octave_value::op_not, v1), v2);
2388 
2391  do_unary_op (octave_value::op_not, v1), v2);
2392 
2395  v1, do_unary_op (octave_value::op_not, v2));
2396 
2399  v1, do_unary_op (octave_value::op_not, v2));
2400 
2401  default:
2402  error ("invalid compound operator");
2403  }
2404 }
2405 
2408  const octave_value& v1, const octave_value& v2)
2409 {
2411 
2412  int t1 = v1.type_id ();
2413  int t2 = v2.type_id ();
2414 
2415  if (t1 == octave_class::static_type_id ()
2416  || t2 == octave_class::static_type_id ()
2418  || t2 == octave_classdef::static_type_id ())
2419  {
2422 
2423  if (f)
2424  retval = f (v1, v2);
2425  else
2426  retval = decompose_binary_op (op, v1, v2);
2427  }
2428  else
2429  {
2432 
2433  if (f)
2434  retval = f (*v1.rep, *v2.rep);
2435  else
2436  retval = decompose_binary_op (op, v1, v2);
2437  }
2438 
2439  return retval;
2440 }
2441 
2442 OCTAVE_NORETURN static void
2443 err_cat_op (const std::string& tn1, const std::string& tn2)
2444 {
2445  error ("concatenation operator not implemented for '%s' by '%s' operations",
2446  tn1.c_str (), tn2.c_str ());
2447 }
2448 
2449 OCTAVE_NORETURN static void
2451 {
2452  error ("type conversion failed for concatenation operator");
2453 }
2454 
2458 {
2460 
2461  // Can't rapid return for concatenation with an empty object here as
2462  // something like cat(1,[],single([]) must return the correct type.
2463 
2464  int t1 = v1.type_id ();
2465  int t2 = v2.type_id ();
2466 
2469 
2470  if (f)
2471  retval = f (*v1.rep, *v2.rep, ra_idx);
2472  else
2473  {
2474  octave_value tv1;
2476 
2477  octave_value tv2;
2479 
2480  // Try biased (one-sided) conversions first.
2481  if (cf2.type_id () >= 0
2483  cf1 = 0;
2484  else if (cf1.type_id () >= 0
2486  cf2 = 0;
2487 
2488  if (cf1)
2489  {
2490  octave_base_value *tmp = cf1 (*v1.rep);
2491 
2492  if (! tmp)
2493  err_cat_op_conv ();
2494 
2495  tv1 = octave_value (tmp);
2496  t1 = tv1.type_id ();
2497  }
2498  else
2499  tv1 = v1;
2500 
2501  if (cf2)
2502  {
2503  octave_base_value *tmp = cf2 (*v2.rep);
2504 
2505  if (! tmp)
2506  err_cat_op_conv ();
2507 
2508  tv2 = octave_value (tmp);
2509  t2 = tv2.type_id ();
2510  }
2511  else
2512  tv2 = v2;
2513 
2514  if (! cf1 && ! cf2)
2515  err_cat_op (v1.type_name (), v2.type_name ());
2516 
2517  retval = do_cat_op (tv1, tv2, ra_idx);
2518  }
2519 
2520  return retval;
2521 }
2522 
2524 do_colon_op (const octave_value& base, const octave_value& increment,
2525  const octave_value& limit, bool is_for_cmd_expr)
2526 {
2528 
2529  if (base.is_object () || increment.is_object () || limit.is_object ())
2530  {
2531  std::string dispatch_type;
2532 
2533  if (base.is_object ())
2534  dispatch_type = base.class_name ();
2535  else if (increment.is_defined () && increment.is_object ())
2536  dispatch_type = increment.class_name ();
2537  else
2538  dispatch_type = limit.class_name ();
2539 
2540  octave_value meth = symbol_table::find_method ("colon", dispatch_type);
2541 
2542  if (! meth.is_defined ())
2543  error ("colon method not defined for %s class", dispatch_type.c_str ());
2544 
2545  octave_value_list args;
2546 
2547  if (increment.is_defined ())
2548  {
2549  args(2) = limit;
2550  args(1) = increment;
2551  }
2552  else
2553  args(1) = limit;
2554 
2555  args(0) = base;
2556 
2557  octave_value_list tmp = feval (meth.function_value (), args, 1);
2558 
2559  if (tmp.length () > 0)
2560  retval = tmp(0);
2561  }
2562  else
2563  {
2564  bool result_is_str = (base.is_string () && limit.is_string ());
2565  bool dq_str = (base.is_dq_string () || limit.is_dq_string ());
2566 
2567  Matrix m_base, m_limit, m_increment;
2568 
2569  try
2570  {
2571  m_base = base.matrix_value (true);
2572  }
2573  catch (octave::execution_exception& e)
2574  {
2575  error (e, "invalid base value in colon expression");
2576  }
2577 
2578  try
2579  {
2580  m_limit = limit.matrix_value (true);
2581  }
2582  catch (octave::execution_exception& e)
2583  {
2584  error (e, "invalid limit value in colon expression");
2585  }
2586 
2587  try
2588  {
2589  m_increment = (increment.is_defined ()
2590  ? increment.matrix_value (true)
2591  : Matrix (1, 1, 1.0));
2592  }
2593  catch (octave::execution_exception& e)
2594  {
2595  error (e, "invalid increment value in colon expression");
2596  }
2597 
2598  bool base_empty = m_base.is_empty ();
2599  bool limit_empty = m_limit.is_empty ();
2600  bool increment_empty = m_increment.is_empty ();
2601 
2602  if (base_empty || limit_empty || increment_empty)
2603  retval = Range ();
2604  else
2605  {
2606  Range r (m_base(0), m_limit(0), m_increment(0));
2607 
2608  // For compatibility with Matlab, don't allow the range used in
2609  // a FOR loop expression to be converted to a Matrix.
2610 
2611  retval = octave_value (r, is_for_cmd_expr);
2612 
2613  if (result_is_str)
2614  retval = retval.convert_to_str (false, true, dq_str ? '"' : '\'');
2615  }
2616  }
2617 
2618  return retval;
2619 }
2620 
2621 void
2622 octave_value::print_info (std::ostream& os, const std::string& prefix) const
2623 {
2624  os << prefix << "type_name: " << type_name () << "\n"
2625  << prefix << "count: " << get_count () << "\n"
2626  << prefix << "rep info: ";
2627 
2628  rep->print_info (os, prefix + " ");
2629 }
2630 
2631 OCTAVE_NORETURN static void
2632 err_unary_op (const std::string& on, const std::string& tn)
2633 {
2634  error ("unary operator '%s' not implemented for '%s' operands",
2635  on.c_str (), tn.c_str ());
2636 }
2637 
2638 OCTAVE_NORETURN static void
2640 {
2641  error ("type conversion failed for unary operator '%s'", on.c_str ());
2642 }
2643 
2646 {
2648 
2649  int t = v.type_id ();
2650 
2651  if (t == octave_class::static_type_id ()
2653  {
2656 
2657  if (! f)
2659 
2660  retval = f (v);
2661  }
2662  else
2663  {
2664  // FIXME: we need to handle overloading operators for built-in
2665  // classes (double, char, int8, etc.)
2666 
2669 
2670  if (f)
2671  retval = f (*v.rep);
2672  else
2673  {
2674  octave_value tv;
2677 
2678  if (! cf)
2680  v.type_name ());
2681 
2682  octave_base_value *tmp = cf (*v.rep);
2683 
2684  if (! tmp)
2686 
2687  tv = octave_value (tmp);
2688  retval = do_unary_op (op, tv);
2689  }
2690  }
2691 
2692  return retval;
2693 }
2694 
2695 OCTAVE_NORETURN static void
2697  const std::string& tn)
2698 {
2699  error ("operator %s: type conversion for '%s' failed",
2700  op.c_str (), tn.c_str ());
2701 }
2702 
2703 octave_value&
2705 {
2706  if (op == op_incr || op == op_decr)
2707  {
2708  // We want the error just here, because in the other branch this should
2709  // not happen, and if it did anyway (internal error), the message would
2710  // be confusing.
2711  if (is_undefined ())
2712  {
2713  std::string op_str = unary_op_as_string (op);
2714  error ("in x%s or %sx, x must be defined first",
2715  op_str.c_str (), op_str.c_str ());
2716  return *this;
2717  }
2718 
2719  // Genuine.
2720  int t = type_id ();
2721 
2724 
2725  if (f)
2726  {
2727  make_unique ();
2728 
2729  f (*rep);
2730  }
2731  else
2732  {
2734 
2735  if (! cf)
2737 
2738  octave_base_value *tmp = cf (*rep);
2739 
2740  if (! tmp)
2743 
2744  octave_base_value *old_rep = rep;
2745  rep = tmp;
2746 
2747  t = type_id ();
2748 
2750 
2751  if (f)
2752  {
2753  f (*rep);
2754 
2755  if (old_rep && --old_rep->count == 0)
2756  delete old_rep;
2757  }
2758  else
2759  {
2760  if (old_rep)
2761  {
2762  if (--rep->count == 0)
2763  delete rep;
2764 
2765  rep = old_rep;
2766  }
2767 
2769  type_name ());
2770  }
2771  }
2772  }
2773  else
2774  {
2775  // Non-genuine.
2776  int t = type_id ();
2777 
2779 
2780  // Only attempt to operate in-place if this variable is unshared.
2781  if (rep->count == 1)
2783 
2784  if (f)
2785  f (*rep);
2786  else
2787  *this = do_unary_op (op, *this);
2788  }
2789 
2790  return *this;
2791 }
2792 
2793 octave_value&
2795  const std::list<octave_value_list>& idx)
2796 {
2797  if (idx.empty ())
2798  do_non_const_unary_op (op);
2799  else
2800  {
2801  // FIXME: only do the following stuff if we can't find a
2802  // specific function to call to handle the op= operation for the
2803  // types we have.
2804 
2805  assign_op assop = unary_op_to_assign_op (op);
2806 
2807  assign (assop, type, idx, 1.0);
2808  }
2809 
2810  return *this;
2811 }
2812 
2815 {
2816  switch (op)
2817  {
2818  case op_incr:
2819  return op_add_eq;
2820 
2821  case op_decr:
2822  return op_sub_eq;
2823 
2824  default:
2825  {
2826  std::string on = unary_op_as_string (op);
2827  error ("operator %s: no assign operator found", on.c_str ());
2828  }
2829  }
2830 }
2831 
2834 {
2835  switch (op)
2836  {
2837  case op_add_eq:
2838  return op_add;
2839 
2840  case op_sub_eq:
2841  return op_sub;
2842 
2843  case op_mul_eq:
2844  return op_mul;
2845 
2846  case op_div_eq:
2847  return op_div;
2848 
2849  case op_ldiv_eq:
2850  return op_ldiv;
2851 
2852  case op_pow_eq:
2853  return op_pow;
2854 
2855  case op_el_mul_eq:
2856  return op_el_mul;
2857 
2858  case op_el_div_eq:
2859  return op_el_div;
2860 
2861  case op_el_ldiv_eq:
2862  return op_el_ldiv;
2863 
2864  case op_el_pow_eq:
2865  return op_el_pow;
2866 
2867  case op_el_and_eq:
2868  return op_el_and;
2869 
2870  case op_el_or_eq:
2871  return op_el_or;
2872 
2873  default:
2874  {
2875  std::string on = assign_op_as_string (op);
2876  error ("operator %s: no binary operator found", on.c_str ());
2877  }
2878  }
2879 }
2880 
2883 {
2884  if (type.length () > 0)
2885  {
2886  switch (type[0])
2887  {
2888  case '(':
2889  if (type.length () > 1 && type[1] == '.')
2890  return octave_map ();
2891  else
2892  return octave_value (rhs.empty_clone ());
2893 
2894  case '{':
2895  return Cell ();
2896 
2897  case '.':
2898  return octave_scalar_map ();
2899 
2900  default:
2901  panic_impossible ();
2902  }
2903  }
2904  else
2905  return octave_value (rhs.empty_clone ());
2906 }
2907 
2908 void
2910 {
2924  octave_int8_scalar::register_type ();
2925  octave_int16_scalar::register_type ();
2926  octave_int32_scalar::register_type ();
2927  octave_int64_scalar::register_type ();
2928  octave_uint8_scalar::register_type ();
2929  octave_uint16_scalar::register_type ();
2930  octave_uint32_scalar::register_type ();
2931  octave_uint64_scalar::register_type ();
2932  octave_int8_matrix::register_type ();
2933  octave_int16_matrix::register_type ();
2934  octave_int32_matrix::register_type ();
2935  octave_int64_matrix::register_type ();
2936  octave_uint8_matrix::register_type ();
2937  octave_uint16_matrix::register_type ();
2938  octave_uint32_matrix::register_type ();
2939  octave_uint64_matrix::register_type ();
2966 }
2967 
2968 DEFUN (sizeof, args, ,
2969  doc: /* -*- texinfo -*-
2970 @deftypefn {} {} sizeof (@var{val})
2971 Return the size of @var{val} in bytes.
2972 @seealso{whos}
2973 @end deftypefn */)
2974 {
2975  if (args.length () != 1)
2976  print_usage ();
2977 
2978  return ovl (args(0).byte_size ());
2979 }
2980 
2981 /*
2982 %!assert (sizeof (uint64 (ones (3))), 72)
2983 %!assert (sizeof (double (zeros (2,4))), 64)
2984 %!assert (sizeof ({"foo", "bar", "baaz"}), 10)
2985 */
2986 
2987 static void
2989  std::string& type_string,
2990  std::list<octave_value_list>& idx)
2991 {
2992  const octave_map m = arg.xmap_value ("%s: second argument must be a structure with fields 'type' and 'subs'", name);
2993 
2994  if (m.nfields () != 2 || ! m.contains ("type") || ! m.contains ("subs"))
2995  error ("%s: second argument must be a structure with fields 'type' and 'subs'",
2996  name);
2997 
2998  octave_idx_type nel = m.numel ();
2999 
3000  type_string = std::string (nel, '\0');
3001  idx = std::list<octave_value_list> ();
3002 
3003  if (nel == 0)
3004  return;
3005 
3006  const Cell type = m.contents ("type");
3007  const Cell subs = m.contents ("subs");
3008 
3009  for (int k = 0; k < nel; k++)
3010  {
3011  std::string item = type(k).xstring_value ("%s: type(%d) must be a string", name, k+1);
3012 
3013  if (item == "{}")
3014  type_string[k] = '{';
3015  else if (item == "()")
3016  type_string[k] = '(';
3017  else if (item == ".")
3018  type_string[k] = '.';
3019  else
3020  error ("%s: invalid indexing type '%s'", name, item.c_str ());
3021 
3022  octave_value_list idx_item;
3023 
3024  if (subs(k).is_string ())
3025  idx_item(0) = subs(k);
3026  else if (subs(k).is_cell ())
3027  {
3028  Cell subs_cell = subs(k).cell_value ();
3029 
3030  for (int n = 0; n < subs_cell.numel (); n++)
3031  {
3032  if (subs_cell(n).is_string ()
3033  && subs_cell(n).string_value () == ":")
3035  else
3036  idx_item(n) = subs_cell(n);
3037  }
3038  }
3039  else
3040  error ("%s: subs(%d) must be a string or cell array", name, k+1);
3041 
3042  idx.push_back (idx_item);
3043  }
3044 }
3045 
3047  doc: /* -*- texinfo -*-
3048 @deftypefn {} {} subsref (@var{val}, @var{idx})
3049 Perform the subscripted element selection operation on @var{val} according
3050 to the subscript specified by @var{idx}.
3051 
3052 The subscript @var{idx} must be a structure array with fields @samp{type}
3053 and @samp{subs}. Valid values for @samp{type} are @qcode{"()"},
3054 @qcode{"@{@}"}, and @qcode{"."}. The @samp{subs} field may be either
3055 @qcode{":"} or a cell array of index values.
3056 
3057 The following example shows how to extract the first two columns of a matrix
3058 
3059 @example
3060 @group
3061 val = magic (3)
3062  @result{} val = [ 8 1 6
3063  3 5 7
3064  4 9 2 ]
3065 idx.type = "()";
3066 idx.subs = @{":", 1:2@};
3067 subsref (val, idx)
3068  @result{} [ 8 1
3069  3 5
3070  4 9 ]
3071 @end group
3072 @end example
3073 
3074 @noindent
3075 Note that this is the same as writing @code{val(:, 1:2)}.
3076 
3077 If @var{idx} is an empty structure array with fields @samp{type} and
3078 @samp{subs}, return @var{val}.
3079 @seealso{subsasgn, substruct}
3080 @end deftypefn */)
3081 {
3082  if (args.length () != 2)
3083  print_usage ();
3084 
3085  std::string type;
3086  std::list<octave_value_list> idx;
3087 
3088  decode_subscripts ("subsref", args(1), type, idx);
3089 
3090  octave_value arg0 = args(0);
3091 
3092  if (type.empty ())
3093  return ovl (arg0);
3094  else
3095  return arg0.subsref (type, idx, nargout);
3096 }
3097 
3098 DEFUN (subsasgn, args, ,
3099  doc: /* -*- texinfo -*-
3100 @deftypefn {} {} subsasgn (@var{val}, @var{idx}, @var{rhs})
3101 Perform the subscripted assignment operation according to the subscript
3102 specified by @var{idx}.
3103 
3104 The subscript @var{idx} must be a structure array with fields @samp{type}
3105 and @samp{subs}. Valid values for @samp{type} are @qcode{"()"},
3106 @qcode{"@{@}"}, and @qcode{"."}. The @samp{subs} field may be either
3107 @qcode{":"} or a cell array of index values.
3108 
3109 The following example shows how to set the two first columns of a 3-by-3
3110 matrix to zero.
3111 
3112 @example
3113 @group
3114 val = magic (3);
3115 idx.type = "()";
3116 idx.subs = @{":", 1:2@};
3117 subsasgn (val, idx, 0)
3118  @result{} [ 0 0 6
3119  0 0 7
3120  0 0 2 ]
3121 @end group
3122 @end example
3123 
3124 Note that this is the same as writing @code{val(:, 1:2) = 0}.
3125 
3126 If @var{idx} is an empty structure array with fields @samp{type} and
3127 @samp{subs}, return @var{rhs}.
3128 @seealso{subsref, substruct, optimize_subsasgn_calls}
3129 @end deftypefn */)
3130 {
3131  if (args.length () != 3)
3132  print_usage ();
3133 
3134  std::string type;
3135  std::list<octave_value_list> idx;
3136 
3137  decode_subscripts ("subsasgn", args(1), type, idx);
3138 
3139  if (type.empty ())
3140  {
3141  // Regularize a null matrix if stored into a variable.
3142  return ovl (args(2).storable_value ());
3143  }
3144  else
3145  {
3146  octave_value arg0 = args(0);
3147  octave_value arg2 = args(2);
3148 
3149  arg0.make_unique ();
3150 
3151  bool arg2_null = arg2.is_zero_by_zero () && arg2.is_double_type ();
3152 
3153  return ovl (arg0.subsasgn (type, idx, (arg2_null
3155  : arg2)));
3156  }
3157 }
3158 
3159 /*
3160 %!test
3161 %! a = reshape ([1:25], 5,5);
3162 %! idx1 = substruct ("()", {3, 3});
3163 %! idx2 = substruct ("()", {2:2:5, 2:2:5});
3164 %! idx3 = substruct ("()", {":", [1,5]});
3165 %! idx4 = struct ("type", {}, "subs", {});
3166 %! assert (subsref (a, idx1), 13);
3167 %! assert (subsref (a, idx2), [7 17; 9 19]);
3168 %! assert (subsref (a, idx3), [1:5; 21:25]');
3169 %! assert (subsref (a, idx4), a);
3170 %! a = subsasgn (a, idx1, 0);
3171 %! a = subsasgn (a, idx2, 0);
3172 %! a = subsasgn (a, idx3, 0);
3173 %!# a = subsasgn (a, idx4, 0);
3174 %! b = [0 6 11 16 0
3175 %! 0 0 12 0 0
3176 %! 0 8 0 18 0
3177 %! 0 0 14 0 0
3178 %! 0 10 15 20 0];
3179 %! assert (a, b);
3180 
3181 %!test
3182 %! x = 1:10;
3183 %! assert (subsasgn (x, substruct ("()", {1}), zeros (0, 0)), 2:10);
3184 
3185 %!test
3186 %! c = num2cell (reshape ([1:25],5,5));
3187 %! idx1 = substruct ("{}", {3, 3});
3188 %! idx2 = substruct ("()", {2:2:5, 2:2:5});
3189 %! idx3 = substruct ("()", {":", [1,5]});
3190 %! idx2p = substruct ("{}", {2:2:5, 2:2:5});
3191 %! idx3p = substruct ("{}", {":", [1,5]});
3192 %! idx4 = struct ("type", {}, "subs", {});
3193 %! assert ({ subsref(c, idx1) }, {13});
3194 %! assert ({ subsref(c, idx2p) }, {7 9 17 19});
3195 %! assert ({ subsref(c, idx3p) }, num2cell ([1:5, 21:25]));
3196 %! assert (subsref (c, idx4), c);
3197 %! c = subsasgn (c, idx1, 0);
3198 %! c = subsasgn (c, idx2, 0);
3199 %! c = subsasgn (c, idx3, 0);
3200 %!# c = subsasgn (c, idx4, 0);
3201 %! d = {0 6 11 16 0
3202 %! 0 0 12 0 0
3203 %! 0 8 0 18 0
3204 %! 0 0 14 0 0
3205 %! 0 10 15 20 0};
3206 %! assert (c, d);
3207 
3208 %!test
3209 %! s.a = "ohai";
3210 %! s.b = "dere";
3211 %! s.c = 42;
3212 %! idx1 = substruct (".", "a");
3213 %! idx2 = substruct (".", "b");
3214 %! idx3 = substruct (".", "c");
3215 %! idx4 = struct ("type", {}, "subs", {});
3216 %! assert (subsref (s, idx1), "ohai");
3217 %! assert (subsref (s, idx2), "dere");
3218 %! assert (subsref (s, idx3), 42);
3219 %! assert (subsref (s, idx4), s);
3220 %! s = subsasgn (s, idx1, "Hello");
3221 %! s = subsasgn (s, idx2, "There");
3222 %! s = subsasgn (s, idx3, 163);
3223 %!# s = subsasgn (s, idx4, 163);
3224 %! t.a = "Hello";
3225 %! t.b = "There";
3226 %! t.c = 163;
3227 %! assert (s, t);
3228 */
3229 
3230 DEFUN (is_sq_string, args, ,
3231  doc: /* -*- texinfo -*-
3232 @deftypefn {} {} is_sq_string (@var{x})
3233 Return true if @var{x} is a single-quoted character string.
3234 @seealso{is_dq_string, ischar}
3235 @end deftypefn */)
3236 {
3237  if (args.length () != 1)
3238  print_usage ();
3239 
3240  return ovl (args(0).is_sq_string ());
3241 }
3242 
3243 /*
3244 %!assert (is_sq_string ('foo'), true)
3245 %!assert (is_sq_string ("foo"), false)
3246 %!assert (is_sq_string (1.0), false)
3247 %!assert (is_sq_string ({2.0}), false)
3248 
3249 %!error is_sq_string ()
3250 %!error is_sq_string ('foo', 2)
3251 */
3252 
3253 DEFUN (is_dq_string, args, ,
3254  doc: /* -*- texinfo -*-
3255 @deftypefn {} {} is_dq_string (@var{x})
3256 Return true if @var{x} is a double-quoted character string.
3257 @seealso{is_sq_string, ischar}
3258 @end deftypefn */)
3259 {
3260  if (args.length () != 1)
3261  print_usage ();
3262 
3263  return ovl (args(0).is_dq_string ());
3264 }
3265 
3266 /*
3267 %!assert (is_dq_string ("foo"), true)
3268 %!assert (is_dq_string ('foo'), false)
3269 %!assert (is_dq_string (1.0), false)
3270 %!assert (is_dq_string ({2.0}), false)
3271 
3272 %!error is_dq_string ()
3273 %!error is_dq_string ("foo", 2)
3274 */
3275 
3276 DEFUN (disable_permutation_matrix, args, nargout,
3277  doc: /* -*- texinfo -*-
3278 @deftypefn {} {@var{val} =} disable_permutation_matrix ()
3279 @deftypefnx {} {@var{old_val} =} disable_permutation_matrix (@var{new_val})
3280 @deftypefnx {} {} disable_permutation_matrix (@var{new_val}, "local")
3281 Query or set the internal variable that controls whether permutation
3282 matrices are stored in a special space-efficient format.
3283 
3284 The default value is true. If this option is disabled Octave will store
3285 permutation matrices as full matrices.
3286 
3287 When called from inside a function with the @qcode{"local"} option, the
3288 variable is changed locally for the function and any subroutines it calls.
3289 The original variable value is restored when exiting the function.
3290 @seealso{disable_range, disable_diagonal_matrix}
3291 @end deftypefn */)
3292 {
3293  return SET_INTERNAL_VARIABLE (disable_permutation_matrix);
3294 }
3295 
3296 /*
3297 %!function p = __test_dpm__ (dpm)
3298 %! disable_permutation_matrix (dpm, "local");
3299 %! [~, ~, p] = lu ([1,2;3,4]);
3300 %!endfunction
3301 
3302 %!assert (typeinfo (__test_dpm__ (false)), "permutation matrix")
3303 %!assert (typeinfo (__test_dpm__ (true)), "matrix")
3304 */
3305 
3306 DEFUN (disable_diagonal_matrix, args, nargout,
3307  doc: /* -*- texinfo -*-
3308 @deftypefn {} {@var{val} =} disable_diagonal_matrix ()
3309 @deftypefnx {} {@var{old_val} =} disable_diagonal_matrix (@var{new_val})
3310 @deftypefnx {} {} disable_diagonal_matrix (@var{new_val}, "local")
3311 Query or set the internal variable that controls whether diagonal
3312 matrices are stored in a special space-efficient format.
3313 
3314 The default value is true. If this option is disabled Octave will store
3315 diagonal matrices as full matrices.
3316 
3317 When called from inside a function with the @qcode{"local"} option, the
3318 variable is changed locally for the function and any subroutines it calls.
3319 The original variable value is restored when exiting the function.
3320 @seealso{disable_range, disable_permutation_matrix}
3321 @end deftypefn */)
3322 {
3323  return SET_INTERNAL_VARIABLE (disable_diagonal_matrix);
3324 }
3325 
3326 /*
3327 %!function [x, xi, fx, fxi] = __test_ddm__ (ddm)
3328 %! disable_diagonal_matrix (ddm, "local");
3329 %! x = eye (2);
3330 %! xi = x*i;
3331 %! fx = single (x);
3332 %! fxi = single (xi);
3333 %!endfunction
3334 
3335 %!shared x, xi, fx, fxi
3336 %! [x, xi, fx, fxi] = __test_ddm__ (false);
3337 %!assert (typeinfo (x), "diagonal matrix")
3338 %!assert (typeinfo (xi), "complex diagonal matrix")
3339 %!assert (typeinfo (fx), "float diagonal matrix")
3340 %!assert (typeinfo (fxi), "float complex diagonal matrix")
3341 
3342 %!shared x, xi, fx, fxi
3343 %! [x, xi, fx, fxi] = __test_ddm__ (true);
3344 %!assert (typeinfo (x), "matrix")
3345 %!assert (typeinfo (xi), "complex matrix")
3346 %!assert (typeinfo (fx), "float matrix")
3347 %!assert (typeinfo (fxi), "float complex matrix")
3348 */
3349 
3350 DEFUN (disable_range, args, nargout,
3351  doc: /* -*- texinfo -*-
3352 @deftypefn {} {@var{val} =} disable_range ()
3353 @deftypefnx {} {@var{old_val} =} disable_range (@var{new_val})
3354 @deftypefnx {} {} disable_range (@var{new_val}, "local")
3355 Query or set the internal variable that controls whether ranges are stored
3356 in a special space-efficient format.
3357 
3358 The default value is true. If this option is disabled Octave will store
3359 ranges as full matrices.
3360 
3361 When called from inside a function with the @qcode{"local"} option, the
3362 variable is changed locally for the function and any subroutines it calls.
3363 The original variable value is restored when exiting the function.
3364 @seealso{disable_diagonal_matrix, disable_permutation_matrix}
3365 @end deftypefn */)
3366 {
3367  return SET_INTERNAL_VARIABLE (disable_range);
3368 }
3369 
3370 /*
3371 %!function r = __test_dr__ (dr)
3372 %! disable_range (dr, "local");
3373 %! ## Constant folding will produce range for 1:13.
3374 %! base = 1;
3375 %! limit = 13;
3376 %! r = base:limit;
3377 %!endfunction
3378 
3379 %!assert (typeinfo (__test_dr__ (false)), "range")
3380 %!assert (typeinfo (__test_dr__ (true)), "matrix")
3381 */
uint8NDArray uint8_array_value(void) const
Definition: ov.h:896
static void register_type(void)
Definition: ov-null-mat.cc:75
bool is_object(void) const
Definition: ov.h:593
ColumnVector column_vector_value(bool frc_str_conv=false, bool frc_vec_conv=false) const
Definition: ov.cc:1766
ComplexNDArray complex_array_value(bool frc_str_conv=false) const
Definition: ov.h:812
const Cell & contents(const_iterator p) const
Definition: oct-map.h:313
bool is_empty(void) const
Definition: Array.h:575
octave_value(void)
Definition: ov.h:169
void(* non_const_unary_op_fcn)(octave_base_value &)
Definition: ov-typeinfo.h:47
Definition: Cell.h:37
virtual octave_fcn_handle * fcn_handle_value(bool silent=false)
Definition: ov-base.cc:956
octave_refcount< octave_idx_type > count
Definition: ov-base.h:843
static OCTAVE_NORETURN void err_unary_op_conv(const std::string &on)
Definition: ov.cc:2639
assign_op
Definition: ov.h:131
static OCTAVE_NORETURN void err_cat_op_conv(void)
Definition: ov.cc:2450
octave_map xmap_value(const char *fmt,...) const
Definition: ov.cc:2130
#define XVALUE_EXTRACTOR(TYPE, NAME, FCN)
Definition: ov.cc:2017
octave_value(* binary_op_fcn)(const octave_base_value &, const octave_base_value &)
Definition: ov-typeinfo.h:53
octave_value subsref(const std::string &type, const std::list< octave_value_list > &idx)
Definition: ov.h:417
#define C(a, b)
Definition: Faddeeva.cc:246
virtual octave_value_list do_multi_index_op(int nargout, const octave_value_list &idx)
Definition: ov-base.cc:259
octave_value & operator=(const octave_value &a)
Definition: ov.h:358
const octave_base_value const Array< octave_idx_type > & ra_idx
octave_value reshape(const dim_vector &dv) const
Definition: ov.h:515
octave_idx_type rows(void) const
Definition: ov.h:489
virtual int write(octave_stream &os, int block_size, oct_data_conv::data_type output_type, int skip, octave::mach_info::float_format flt_fmt) const
Definition: ov-base.cc:1021
octave_value do_cat_op(const octave_value &v1, const octave_value &v2, const Array< octave_idx_type > &ra_idx)
Definition: ov.cc:2456
int8NDArray int8_array_value(void) const
Definition: ov.h:884
nd group nd example oindent but is performed more efficiently If only and it is a scalar
Definition: data.cc:5342
virtual octave_map map_value(void) const
Definition: ov-base.cc:870
octave_base_value * empty_clone(void) const
Definition: ov.h:316
static octave_value find_method(const std::string &name, const std::string &dispatch_type)
Definition: symtab.h:1495
OCTAVE_EXPORT octave_value_list isa nd deftypefn *return ovl(args(0).is_integer_type())
FloatColumnVector float_column_vector_value(bool frc_str_conv=false, bool frc_vec_conv=false) const
Definition: ov.cc:1959
bool is_uint16_type(void) const
Definition: ov.h:650
static void register_type(void)
Definition: ov-builtin.cc:40
static void register_type(void)
OCTINTERP_API void print_usage(void)
Definition: defun.cc:52
static std::string binary_op_as_string(binary_op)
Definition: ov.cc:175
octave_idx_type numel(void) const
Number of elements in the array.
Definition: Array.h:363
OCTAVE_EXPORT octave_value_list uint16
Definition: ov.cc:1258
static bool Vdisable_range
Definition: ov.cc:105
F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T F77_REAL F77_REAL &F77_RET_T F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE const F77_DBLE * f
int16NDArray int16_array_value(void) const
Definition: ov.h:887
octave_idx_type length(void) const
Definition: ovl.h:96
octave_map map_value(void) const
Definition: ov.cc:1693
octave_value do_unary_op(octave_value::unary_op op, const octave_value &v)
Definition: ov.cc:2645
idx subsref(val, idx) esult
Definition: ov.cc:3080
octave_user_code * user_code_value(bool silent=false) const
Definition: ov.cc:1723
static void register_type(void)
Definition: ov-float.cc:61
static assign_op binary_op_to_assign_op(binary_op)
Definition: ov.cc:441
bool contains(const std::string &name) const
Definition: oct-map.h:332
bool is_defined(void) const
Definition: ov.h:536
static non_const_unary_op_fcn lookup_non_const_unary_op(octave_value::unary_op op, int t)
Definition: ov-typeinfo.h:122
static void register_type(void)
Definition: ov-lazy-idx.cc:33
static void register_type(void)
Definition: ov-re-diag.cc:40
for large enough k
Definition: lu.cc:606
int int_value(bool req_int=false, bool frc_str_conv=false) const
Definition: ov.h:746
Definition: Range.h:33
uint64NDArray uint64_array_value(void) const
Definition: ov.h:905
binary_op
Definition: ov.h:89
int64_t int64_value(bool req_int=false, bool frc_str_conv=false) const
Definition: ov.h:765
#define DEFUN(name, args_name, nargout_name, doc)
Definition: defun.h:46
void error(const char *fmt,...)
Definition: error.cc:570
int32NDArray int32_array_value(void) const
Definition: ov.h:890
#define SET_INTERNAL_VARIABLE(NM)
Definition: variables.h:126
static std::string unary_op_fcn_name(unary_op)
Definition: ov.cc:150
bool is_int8_type(void) const
Definition: ov.h:635
STL namespace.
void install_types(void)
Definition: ov.cc:2909
int type_id(void) const
Definition: ov.h:1230
static void register_type(void)
Definition: ov-usr-fcn.cc:177
static void register_type(void)
Definition: ov-cell.cc:128
void make_unique(void)
Definition: ov.h:327
static void register_type(void)
Definition: ov-struct.cc:1038
static binary_op assign_op_to_binary_op(assign_op)
Definition: ov.cc:395
octave_value(* binary_class_op_fcn)(const octave_value &, const octave_value &)
Definition: ov-typeinfo.h:50
octave::mach_info::float_format flt_fmt
Definition: load-save.cc:723
static void register_type(void)
static std::string assign_op_as_string(assign_op)
Definition: ov.cc:346
static OCTAVE_NORETURN void err_unary_op_conversion_failed(const std::string &op, const std::string &tn)
Definition: ov.cc:2696
T & elem(octave_idx_type n)
Definition: Array.h:482
static binary_op_fcn lookup_binary_op(octave_value::binary_op op, int t1, int t2)
Definition: ov-typeinfo.h:134
octave_idx_type numel(void) const
Definition: oct-map.h:371
static void register_type(void)
Definition: ov-str-mat.cc:60
OCTAVE_EXPORT octave_value_list return the number of command line arguments passed to Octave If called with the optional argument the function t
Definition: ov-usr-fcn.cc:935
static void register_type(void)
bool is_int32_type(void) const
Definition: ov.h:641
octave_fcn_handle * fcn_handle_value(bool silent=false) const
Definition: ov.cc:1729
s
Definition: file-io.cc:2682
virtual octave_value subsref(const std::string &type, const std::list< octave_value_list > &idx)
Definition: ov-base.cc:217
octave_idx_type idx_type_value(bool req_int=false, bool frc_str_conv=false) const
Definition: ov.cc:1677
i e
Definition: data.cc:2724
static void register_type(void)
binary_op op_eq_to_binary_op(assign_op op)
Definition: ov.cc:2833
octave_value arg
Definition: pr-output.cc:3440
Array< Complex > complex_vector_value(bool frc_str_conv=false, bool frc_vec_conv=false) const
Definition: ov.cc:1948
octave_value & do_non_const_unary_op(unary_op op)
Definition: ov.cc:2704
octave_base_value * clone(void) const
Definition: ov.cc:1149
octave_idx_type numel(int n=0) const
Number of elements that a matrix with this dimensions would have.
Definition: dim-vector.h:389
virtual octave_value subsasgn(const std::string &type, const std::list< octave_value_list > &idx, const octave_value &rhs)
Definition: ov-base.cc:281
F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T F77_REAL F77_REAL &F77_RET_T F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE * d
octave_base_value * rep
Definition: ov.h:1437
virtual void print_info(std::ostream &os, const std::string &prefix) const
Definition: ov-base.cc:492
issues an error eealso single
Definition: ov-bool-mat.cc:594
octave_value subsasgn(const std::string &type, const std::list< octave_value_list > &idx, const octave_value &rhs)
Definition: ov.cc:1540
calling an anonymous function involves an overhead quite comparable to the overhead of an m file function Passing a handle to a built in function is because the interpreter is not involved in the internal loop For a
Definition: cellfun.cc:398
int64NDArray int64_array_value(void) const
Definition: ov.h:893
Cell cell_value(void) const
Definition: ov.cc:1687
static unary_class_op_fcn lookup_unary_class_op(octave_value::unary_op op)
Definition: ov-typeinfo.h:110
JNIEnv void * args
Definition: ov-java.cc:67
octave_base_value::type_conv_info numeric_demotion_function(void) const
Definition: ov.h:377
static bool Vdisable_permutation_matrix
Definition: ov.cc:101
virtual octave_value undef_subsasgn(const std::string &type, const std::list< octave_value_list > &idx, const octave_value &rhs)
Definition: ov-base.cc:347
virtual octave_value_list list_value(void) const
Definition: ov-base.cc:978
const dim_vector & dims(void) const
Return a const-reference so that dims ()(i) works efficiently.
Definition: Array.h:439
static void register_type(void)
Definition: ov-bool.cc:57
octave_value single_subsref(const std::string &type, const octave_value_list &idx)
Definition: ov.cc:1430
static void register_type(void)
Definition: ov-cx-sparse.cc:56
octave_value_list do_multi_index_op(int nargout, const octave_value_list &idx)
Definition: ov.cc:1527
virtual octave_fcn_inline * fcn_inline_value(bool silent=false)
Definition: ov-base.cc:967
static void register_type(void)
Definition: ov-perm.cc:463
virtual octave_base_value * clone(void) const
Definition: ov-base.h:221
octave_value(* cat_op_fcn)(octave_base_value &, const octave_base_value &, const Array< octave_idx_type > &ra_idx)
Definition: ov-typeinfo.h:56
void print_info(std::ostream &os, const std::string &prefix="") const
Definition: ov.cc:2622
octave_idx_type columns(void) const
Definition: ov.h:491
virtual octave_base_value * try_narrowing_conversion(void)
Definition: ov-base.h:258
static void register_type(void)
Definition: ov-str-mat.cc:58
FloatNDArray float_array_value(bool frc_str_conv=false) const
Definition: ov.h:796
OCTAVE_EXPORT octave_value_list any number nd example oindent prints the prompt xample Pick a any number!nd example oindent and waits for the user to enter a value The string entered by the user is evaluated as an so it may be a literal a variable name
Definition: input.cc:871
static void register_type(void)
Definition: ov-oncleanup.cc:35
virtual octave_user_function * user_function_value(bool silent=false)
Definition: ov-base.cc:923
bool is_null_value(void) const
Definition: ov.h:608
OCTAVE_EXPORT octave_value_list return the number of command line arguments passed to Octave If called with the optional argument the function xample nargout(@histc)
Definition: ov-usr-fcn.cc:935
int write(octave_stream &os, int block_size, oct_data_conv::data_type output_type, int skip, octave::mach_info::float_format flt_fmt) const
Definition: ov.cc:2192
static void register_type(void)
Definition: ov-cx-mat.cc:67
octave_value convert_to_str(bool pad=false, bool force=false, char type= '\'') const
Definition: ov.h:1202
static OCTAVE_NORETURN void err_cat_op(const std::string &tn1, const std::string &tn2)
Definition: ov.cc:2443
static const octave_value instance
Definition: ov-null-mat.h:49
virtual octave_scalar_map scalar_map_value(void) const
Definition: ov-base.cc:876
octave_idx_type nfields(void) const
Definition: oct-map.h:326
octave_idx_type numel(const octave_value_list &idx)
Definition: ov.h:411
static void register_type(void)
Definition: ov-struct.cc:52
octave_value(* unary_op_fcn)(const octave_base_value &)
Definition: ov-typeinfo.h:45
OCTAVE_EXPORT octave_value_list uint32
Definition: ov.cc:1258
static void register_type(void)
Definition: ov-scalar.cc:64
void error_with_cfn(const char *fmt,...)
Definition: error.cc:600
nd deftypefn *octave_map m
Definition: ov-struct.cc:2058
static void register_type(void)
Definition: ov-class.cc:65
then the function must return scalars which will be concatenated into the return array(s).If code
Definition: cellfun.cc:398
static void register_type(void)
Definition: ov-re-mat.cc:85
octave_base_value::type_conv_info numeric_conversion_function(void) const
Definition: ov.h:374
FloatComplexNDArray float_complex_array_value(bool frc_str_conv=false) const
Definition: ov.h:816
bool is_string(void) const
Definition: ov.h:578
OCTAVE_EXPORT octave_value_list int16
Definition: ov.cc:1302
octave_user_function * user_function_value(bool silent=false) const
Definition: ov.cc:1711
bool is_double_type(void) const
Definition: ov.h:624
void maybe_economize(void)
Definition: ov.h:1184
static std::string binary_op_fcn_name(binary_op)
Definition: ov.cc:242
static void register_type(void)
Definition: ov-re-sparse.cc:55
static void register_type(void)
Definition: ov-null-mat.cc:32
static void register_type(void)
Array< octave_idx_type > octave_idx_type_vector_value(bool req_int=false, bool frc_str_conv=false, bool frc_vec_conv=false) const
Definition: ov.cc:1891
friend OCTINTERP_API octave_value do_binary_op(binary_op op, const octave_value &a, const octave_value &b)
Definition: ov.cc:2214
void resize(const dim_vector &dv, const T &rfv)
Definition: Array.cc:1028
octave_value & assign(assign_op op, const std::string &type, const std::list< octave_value_list > &idx, const octave_value &rhs)
Definition: ov.cc:1556
double tmp
Definition: data.cc:6300
idx subs
Definition: ov.cc:3080
bool is_int64_type(void) const
Definition: ov.h:644
virtual octave_base_value * empty_clone(void) const
Definition: ov-base.cc:122
octave_value retval
Definition: data.cc:6294
#define panic_impossible()
Definition: error.h:40
FloatComplexRowVector float_complex_row_vector_value(bool frc_str_conv=false, bool frc_vec_conv=false) const
Definition: ov.cc:1984
OCTAVE_EXPORT octave_value_list int32
Definition: ov.cc:1258
static void register_type(void)
static int static_type_id(void)
Definition: ov-classdef.h:1478
assign_op unary_op_to_assign_op(unary_op op)
Definition: ov.cc:2814
octave_idx_type length(void) const
Definition: ov.cc:1623
idx type
Definition: ov.cc:3129
static void register_type(void)
Definition: ov-base.cc:115
static binary_class_op_fcn lookup_binary_class_op(octave_value::binary_op op)
Definition: ov-typeinfo.h:128
Definition: dMatrix.h:37
octave_value all(int dim=0) const
Definition: ov.h:613
the sparsity preserving column transformation such that that defines the pivoting threshold can be given in which case it defines the c
Definition: lu.cc:138
dim_vector dims(void) const
Definition: ov.h:486
virtual octave_user_code * user_code_value(bool silent=false)
Definition: ov-base.cc:945
Matrix matrix_value(bool frc_str_conv=false) const
Definition: ov.h:787
static void register_type(void)
Definition: ov-complex.cc:62
void make_storable_value(void)
Definition: ov.cc:2178
feval(ar{f}, 1) esult
Definition: oct-parse.cc:8829
static void register_type(void)
octave_function * function_value(bool silent=false) const
Definition: ov.cc:1705
T & xelem(octave_idx_type n)
Definition: Array.h:455
bool is_int16_type(void) const
Definition: ov.h:638
OCTAVE_EXPORT octave_value_list int64
Definition: ov.cc:1258
static octave_base_value * nil_rep(void)
Definition: ov.cc:112
bool is_true(void) const
Definition: ov.h:687
magic_colon
Definition: ov.h:167
std::string type_name(void) const
Definition: ov.h:1232
idx_class_type idx_class(void) const
Definition: idx-vector.h:539
static Array< octave_idx_type > convert_to_octave_idx_type_array(const Array< octave_int< T > > &A)
Definition: ov.cc:1879
octave_value(* assign_op_fcn)(octave_base_value &, const octave_value_list &, const octave_base_value &)
Definition: ov-typeinfo.h:60
bool is_empty(void) const
Definition: ov.h:542
static OCTAVE_NORETURN void err_unary_op(const std::string &on, const std::string &tn)
Definition: ov.cc:2632
octave_value undef_subsasgn(const std::string &type, const std::list< octave_value_list > &idx, const octave_value &rhs)
Definition: ov.cc:1548
const octave_char_matrix & v2
NDArray array_value(bool frc_str_conv=false) const
Definition: ov.h:793
static cat_op_fcn lookup_cat_op(int t1, int t2)
Definition: ov-typeinfo.h:152
octave_base_value *(* type_conv_fcn)(const octave_base_value &)
Definition: ov-base.h:190
FloatRowVector float_row_vector_value(bool frc_str_conv=false, bool frc_vec_conv=false) const
Definition: ov.cc:1976
OCTAVE_EXPORT octave_value_list uint64 nd deftypefn *return args(0).as_int8()
octave_scalar_map scalar_map_value(void) const
Definition: ov.cc:1699
ComplexRowVector complex_row_vector_value(bool frc_str_conv=false, bool frc_vec_conv=false) const
Definition: ov.cc:1790
bool is_dq_string(void) const
Definition: ov.h:584
static void register_type(void)
Definition: ov-java.cc:1930
=val(i)}if ode{val(i)}occurs in table i
Definition: lookup.cc:239
void maybe_mutate(void)
Definition: ov.cc:1155
bool is_uint8_type(void) const
Definition: ov.h:647
RowVector row_vector_value(bool frc_str_conv=false, bool frc_vec_conv=false) const
Definition: ov.cc:1782
p
Definition: lu.cc:138
static bool Vdisable_diagonal_matrix
Definition: ov.cc:97
FloatComplexColumnVector float_complex_column_vector_value(bool frc_str_conv=false, bool frc_vec_conv=false) const
Definition: ov.cc:1967
void warn_implicit_conversion(const char *id, const char *from, const char *to)
Definition: errwarn.cc:332
octave_value(* unary_class_op_fcn)(const octave_value &)
Definition: ov-typeinfo.h:43
Array< double > vector_value(bool frc_str_conv=false, bool frc_vec_conv=false) const
Definition: ov.cc:1798
idx subsasgn(val, idx, 0) esult
Definition: ov.cc:3129
compound_binary_op
Definition: ov.h:114
octave_idx_type ndims(void) const
Number of dimensions.
Definition: dim-vector.h:301
std::string class_name(void) const
Definition: ov.h:1234
b
Definition: cellfun.cc:398
octave_idx_type get_count(void) const
Definition: ov.h:372
static void register_type(void)
Definition: ov-cs-list.cc:39
bool is_undefined(void) const
Definition: ov.h:539
bool is_uint64_type(void) const
Definition: ov.h:656
Array< T > reshape(octave_idx_type nr, octave_idx_type nc) const
Definition: Array.h:563
void unconvert(idx_class_type &iclass, double &scalar, Range &range, Array< double > &array, Array< bool > &mask) const
Definition: idx-vector.cc:1222
static void decode_subscripts(const char *name, const octave_value &arg, std::string &type_string, std::list< octave_value_list > &idx)
Definition: ov.cc:2988
octave_value_list list_value(void) const
Definition: ov.cc:1741
std::complex< float > FloatComplex
Definition: oct-cmplx.h:32
ComplexColumnVector complex_column_vector_value(bool frc_str_conv=false, bool frc_vec_conv=false) const
Definition: ov.cc:1774
Array< int > int_vector_value(bool req_int=false, bool frc_str_conv=false, bool frc_vec_conv=false) const
Definition: ov.cc:1822
friend OCTINTERP_API octave_value do_unary_op(unary_op op, const octave_value &a)
Definition: ov.cc:2645
static OCTAVE_NORETURN void err_binary_op(const std::string &on, const std::string &tn1, const std::string &tn2)
Definition: ov.cc:2200
Array< FloatComplex > float_complex_vector_value(bool frc_str_conv=false, bool frc_vec_conv=false) const
Definition: ov.cc:2003
static assign_op_fcn lookup_assign_op(octave_value::assign_op op, int t_lhs, int t_rhs)
Definition: ov-typeinfo.h:158
std::complex< double > Complex
Definition: oct-cmplx.h:31
virtual octave_function * function_value(bool silent=false)
Definition: ov-base.cc:912
octave_fcn_inline * fcn_inline_value(bool silent=false) const
Definition: ov.cc:1735
static std::string unary_op_as_string(unary_op)
Definition: ov.cc:119
static OCTAVE_NORETURN void err_binary_op_conv(const std::string &on)
Definition: ov.cc:2208
static Array< int > convert_to_int_array(const Array< octave_int< T > > &A)
Definition: ov.cc:1810
bool is_uint32_type(void) const
Definition: ov.h:653
Vector representing the dimensions (size) of an Array.
Definition: dim-vector.h:87
static void register_type(void)
Definition: ov-colon.cc:35
octave_user_script * user_script_value(bool silent=false) const
Definition: ov.cc:1717
virtual Cell cell_value(void) const
Definition: ov-base.cc:572
octave_value storable_value(void) const
Definition: ov.cc:2166
unary_op
Definition: ov.h:76
bool is_equal(const octave_value &) const
Definition: ov.cc:1645
static void register_type(void)
Definition: ov-dld-fcn.cc:39
void chop_trailing_singletons(void)
Definition: dim-vector.h:232
octave_value do_colon_op(const octave_value &base, const octave_value &increment, const octave_value &limit, bool is_for_cmd_expr)
Definition: ov.cc:2524
uint32NDArray uint32_array_value(void) const
Definition: ov.h:902
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Definition: utils.cc:854
static dim_vector make_vector_dims(const dim_vector &dv, bool force_vector_conversion, const std::string &my_type, const std::string &wanted_type)
Definition: ov.cc:1747
virtual octave_user_script * user_script_value(bool silent=false)
Definition: ov-base.cc:934
static int static_type_id(void)
Definition: ov-class.h:215
dim_vector dv
Definition: sub2ind.cc:263
uint16NDArray uint16_array_value(void) const
Definition: ov.h:899
static void register_type(void)
Definition: ov-null-mat.cc:53
bool is_zero_by_zero(void) const
Definition: ov.h:696
octave_value next_subsref(const std::string &type, const std::list< octave_value_list > &idx, size_t skip=1)
Definition: ov.cc:1462
OCTAVE_EXPORT octave_value_list or cell arrays Arguments are concatenated vertically The returned values are padded with blanks as needed to make each row of the string array have the same length Empty input strings are significant and will concatenated in the output For numerical each element is converted to the corresponding ASCII character A range error results if an input is outside the ASCII range(0-255).For cell arrays
return octave_value(v1.char_array_value().concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string())? '\'': '"'))
static octave_value empty_conv(const std::string &type, const octave_value &rhs=octave_value())
Definition: ov.cc:2882
Array< float > float_vector_value(bool frc_str_conv=false, bool frc_vec_conv=false) const
Definition: ov.cc:1992
octave_value do_binary_op(octave_value::binary_op op, const octave_value &v1, const octave_value &v2)
Definition: ov.cc:2214
static void register_type(void)
Definition: ov-range.cc:63
F77_RET_T const F77_INT F77_CMPLX * A
static void register_type(void)
Definition: ov-cx-diag.cc:41
static octave_value decompose_binary_op(octave_value::compound_binary_op op, const octave_value &v1, const octave_value &v2)
Definition: ov.cc:2356
static unary_op_fcn lookup_unary_op(octave_value::unary_op op, int t)
Definition: ov-typeinfo.h:116
bool is_integer_type(void) const
Definition: ov.h:664
static void register_type(void)
Definition: ov-bool-mat.cc:68