Mercurial > octave-nkf
annotate src/ov.cc @ 7997:2b8952e133c9
implement checked conversions between integers
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Wed, 30 Jul 2008 15:20:13 +0200 |
parents | 7ca2735d74c2 |
children | f7f2d867c523 |
rev | line source |
---|---|
2376 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2002, 2003, 2004, 2005, |
4 2006, 2007 John W. Eaton | |
2376 | 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 | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
2376 | 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 | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
2376 | 21 |
22 */ | |
23 | |
24 #ifdef HAVE_CONFIG_H | |
25 #include <config.h> | |
26 #endif | |
27 | |
4970 | 28 #include "data-conv.h" |
29 #include "quit.h" | |
2942 | 30 #include "str-vec.h" |
2376 | 31 |
2974 | 32 #include "oct-obj.h" |
4944 | 33 #include "oct-stream.h" |
2376 | 34 #include "ov.h" |
35 #include "ov-base.h" | |
2825 | 36 #include "ov-bool.h" |
37 #include "ov-bool-mat.h" | |
3351 | 38 #include "ov-cell.h" |
2376 | 39 #include "ov-scalar.h" |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
40 #include "ov-float.h" |
2376 | 41 #include "ov-re-mat.h" |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
42 #include "ov-flt-re-mat.h" |
5164 | 43 #include "ov-bool-sparse.h" |
44 #include "ov-cx-sparse.h" | |
45 #include "ov-re-sparse.h" | |
4901 | 46 #include "ov-int8.h" |
47 #include "ov-int16.h" | |
48 #include "ov-int32.h" | |
49 #include "ov-int64.h" | |
50 #include "ov-uint8.h" | |
51 #include "ov-uint16.h" | |
52 #include "ov-uint32.h" | |
53 #include "ov-uint64.h" | |
2376 | 54 #include "ov-complex.h" |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
55 #include "ov-flt-complex.h" |
2376 | 56 #include "ov-cx-mat.h" |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
57 #include "ov-flt-cx-mat.h" |
2376 | 58 #include "ov-ch-mat.h" |
59 #include "ov-str-mat.h" | |
60 #include "ov-range.h" | |
61 #include "ov-struct.h" | |
7336 | 62 #include "ov-class.h" |
2880 | 63 #include "ov-list.h" |
3977 | 64 #include "ov-cs-list.h" |
2376 | 65 #include "ov-colon.h" |
2974 | 66 #include "ov-builtin.h" |
4649 | 67 #include "ov-dld-fcn.h" |
2974 | 68 #include "ov-usr-fcn.h" |
4342 | 69 #include "ov-fcn-handle.h" |
4966 | 70 #include "ov-fcn-inline.h" |
2376 | 71 #include "ov-typeinfo.h" |
72 | |
73 #include "defun.h" | |
2880 | 74 #include "error.h" |
2376 | 75 #include "gripes.h" |
76 #include "pager.h" | |
4005 | 77 #include "parse.h" |
2376 | 78 #include "pr-output.h" |
7336 | 79 #include "symtab.h" |
2376 | 80 #include "utils.h" |
81 #include "variables.h" | |
82 | |
2477 | 83 // We are likely to have a lot of octave_value objects to allocate, so |
84 // make the grow_size large. | |
3219 | 85 DEFINE_OCTAVE_ALLOCATOR2(octave_value, 1024); |
2477 | 86 |
5775 | 87 // FIXME |
2880 | 88 |
2376 | 89 // Octave's value type. |
90 | |
3536 | 91 std::string |
3203 | 92 octave_value::unary_op_as_string (unary_op op) |
93 { | |
3523 | 94 std::string retval; |
3203 | 95 |
96 switch (op) | |
97 { | |
3533 | 98 case op_not: |
3203 | 99 retval = "!"; |
100 break; | |
101 | |
4965 | 102 case op_uplus: |
103 retval = "+"; | |
104 break; | |
105 | |
3533 | 106 case op_uminus: |
3203 | 107 retval = "-"; |
108 break; | |
109 | |
3533 | 110 case op_transpose: |
3203 | 111 retval = ".'"; |
112 break; | |
113 | |
3533 | 114 case op_hermitian: |
3203 | 115 retval = "'"; |
116 break; | |
117 | |
3533 | 118 case op_incr: |
3203 | 119 retval = "++"; |
120 break; | |
121 | |
3533 | 122 case op_decr: |
3203 | 123 retval = "--"; |
124 break; | |
125 | |
126 default: | |
127 retval = "<unknown>"; | |
128 } | |
129 | |
130 return retval; | |
131 } | |
132 | |
3536 | 133 std::string |
7336 | 134 octave_value::unary_op_fcn_name (unary_op op) |
135 { | |
136 std::string retval; | |
137 | |
138 switch (op) | |
139 { | |
140 case op_not: | |
141 retval = "not"; | |
142 break; | |
143 | |
144 case op_uplus: | |
145 retval = "uplus"; | |
146 break; | |
147 | |
148 case op_uminus: | |
149 retval = "uminus"; | |
150 break; | |
151 | |
152 case op_transpose: | |
153 retval = "transpose"; | |
154 break; | |
155 | |
156 case op_hermitian: | |
157 retval = "ctranspose"; | |
158 break; | |
159 | |
160 default: | |
161 break; | |
162 } | |
163 | |
164 return retval; | |
165 } | |
166 | |
167 std::string | |
2376 | 168 octave_value::binary_op_as_string (binary_op op) |
169 { | |
3523 | 170 std::string retval; |
2376 | 171 |
172 switch (op) | |
173 { | |
3533 | 174 case op_add: |
2376 | 175 retval = "+"; |
176 break; | |
177 | |
3533 | 178 case op_sub: |
2376 | 179 retval = "-"; |
180 break; | |
181 | |
3533 | 182 case op_mul: |
2376 | 183 retval = "*"; |
184 break; | |
185 | |
3533 | 186 case op_div: |
2376 | 187 retval = "/"; |
188 break; | |
189 | |
3533 | 190 case op_pow: |
2376 | 191 retval = "^"; |
192 break; | |
193 | |
3533 | 194 case op_ldiv: |
2376 | 195 retval = "\\"; |
196 break; | |
197 | |
3533 | 198 case op_lshift: |
2903 | 199 retval = "<<"; |
200 break; | |
201 | |
3533 | 202 case op_rshift: |
2903 | 203 retval = ">>"; |
204 break; | |
205 | |
3533 | 206 case op_lt: |
2376 | 207 retval = "<"; |
208 break; | |
209 | |
3533 | 210 case op_le: |
2376 | 211 retval = "<="; |
212 break; | |
213 | |
3533 | 214 case op_eq: |
2376 | 215 retval = "=="; |
216 break; | |
217 | |
3533 | 218 case op_ge: |
2376 | 219 retval = ">="; |
220 break; | |
221 | |
3533 | 222 case op_gt: |
2376 | 223 retval = ">"; |
224 break; | |
225 | |
3533 | 226 case op_ne: |
2376 | 227 retval = "!="; |
228 break; | |
229 | |
3533 | 230 case op_el_mul: |
2376 | 231 retval = ".*"; |
232 break; | |
233 | |
3533 | 234 case op_el_div: |
2376 | 235 retval = "./"; |
236 break; | |
237 | |
3533 | 238 case op_el_pow: |
2376 | 239 retval = ".^"; |
240 break; | |
241 | |
3533 | 242 case op_el_ldiv: |
2376 | 243 retval = ".\\"; |
244 break; | |
245 | |
3533 | 246 case op_el_and: |
2376 | 247 retval = "&"; |
248 break; | |
249 | |
3533 | 250 case op_el_or: |
2376 | 251 retval = "|"; |
252 break; | |
253 | |
3533 | 254 case op_struct_ref: |
2376 | 255 retval = "."; |
256 break; | |
257 | |
258 default: | |
259 retval = "<unknown>"; | |
260 } | |
261 | |
262 return retval; | |
263 } | |
264 | |
3536 | 265 std::string |
7336 | 266 octave_value::binary_op_fcn_name (binary_op op) |
267 { | |
268 std::string retval; | |
269 | |
270 switch (op) | |
271 { | |
272 case op_add: | |
273 retval = "plus"; | |
274 break; | |
275 | |
276 case op_sub: | |
277 retval = "minus"; | |
278 break; | |
279 | |
280 case op_mul: | |
281 retval = "mtimes"; | |
282 break; | |
283 | |
284 case op_div: | |
285 retval = "mrdivide"; | |
286 break; | |
287 | |
288 case op_pow: | |
289 retval = "mpower"; | |
290 break; | |
291 | |
292 case op_ldiv: | |
293 retval = "mldivide"; | |
294 break; | |
295 | |
296 case op_lt: | |
297 retval = "lt"; | |
298 break; | |
299 | |
300 case op_le: | |
301 retval = "le"; | |
302 break; | |
303 | |
304 case op_eq: | |
305 retval = "eq"; | |
306 break; | |
307 | |
308 case op_ge: | |
309 retval = "ge"; | |
310 break; | |
311 | |
312 case op_gt: | |
313 retval = "gt"; | |
314 break; | |
315 | |
316 case op_ne: | |
317 retval = "ne"; | |
318 break; | |
319 | |
320 case op_el_mul: | |
321 retval = "times"; | |
322 break; | |
323 | |
324 case op_el_div: | |
325 retval = "rdivide"; | |
326 break; | |
327 | |
328 case op_el_pow: | |
329 retval = "power"; | |
330 break; | |
331 | |
332 case op_el_ldiv: | |
333 retval = "ldivide"; | |
334 break; | |
335 | |
336 case op_el_and: | |
337 retval = "and"; | |
338 break; | |
339 | |
340 case op_el_or: | |
341 retval = "or"; | |
342 break; | |
343 | |
344 default: | |
345 break; | |
346 } | |
347 | |
348 return retval; | |
349 } | |
350 | |
351 std::string | |
7800
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
352 octave_value::binary_op_fcn_name (compound_binary_op op) |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
353 { |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
354 std::string retval; |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
355 |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
356 switch (op) |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
357 { |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
358 case op_trans_mul: |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
359 retval = "transtimes"; |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
360 break; |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
361 |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
362 case op_mul_trans: |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
363 retval = "timestrans"; |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
364 break; |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
365 |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
366 case op_herm_mul: |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
367 retval = "hermtimes"; |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
368 break; |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
369 |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
370 case op_mul_herm: |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
371 retval = "timesherm"; |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
372 break; |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
373 |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
374 default: |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
375 break; |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
376 } |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
377 |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
378 return retval; |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
379 } |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
380 |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
381 std::string |
2880 | 382 octave_value::assign_op_as_string (assign_op op) |
383 { | |
3523 | 384 std::string retval; |
2880 | 385 |
386 switch (op) | |
387 { | |
3533 | 388 case op_asn_eq: |
2880 | 389 retval = "="; |
390 break; | |
391 | |
3533 | 392 case op_add_eq: |
2880 | 393 retval = "+="; |
394 break; | |
395 | |
3533 | 396 case op_sub_eq: |
2880 | 397 retval = "-="; |
398 break; | |
399 | |
3533 | 400 case op_mul_eq: |
2880 | 401 retval = "*="; |
402 break; | |
403 | |
3533 | 404 case op_div_eq: |
2880 | 405 retval = "/="; |
406 break; | |
407 | |
3533 | 408 case op_ldiv_eq: |
3204 | 409 retval = "\\="; |
410 break; | |
411 | |
4018 | 412 case op_pow_eq: |
413 retval = "^="; | |
414 break; | |
415 | |
3533 | 416 case op_lshift_eq: |
2903 | 417 retval = "<<="; |
418 break; | |
419 | |
3533 | 420 case op_rshift_eq: |
2903 | 421 retval = ">>="; |
422 break; | |
423 | |
3533 | 424 case op_el_mul_eq: |
2880 | 425 retval = ".*="; |
426 break; | |
427 | |
3533 | 428 case op_el_div_eq: |
2880 | 429 retval = "./="; |
430 break; | |
431 | |
3533 | 432 case op_el_ldiv_eq: |
3204 | 433 retval = ".\\="; |
434 break; | |
435 | |
4018 | 436 case op_el_pow_eq: |
437 retval = ".^="; | |
438 break; | |
439 | |
3533 | 440 case op_el_and_eq: |
2880 | 441 retval = "&="; |
442 break; | |
443 | |
3533 | 444 case op_el_or_eq: |
2880 | 445 retval = "|="; |
446 break; | |
447 | |
448 default: | |
449 retval = "<unknown>"; | |
450 } | |
451 | |
452 return retval; | |
453 } | |
454 | |
5759 | 455 octave_value::octave_value (void) |
456 : rep (new octave_base_value ()) | |
4513 | 457 { |
2825 | 458 } |
2376 | 459 |
4254 | 460 octave_value::octave_value (short int i) |
461 : rep (new octave_scalar (i)) | |
462 { | |
463 } | |
464 | |
465 octave_value::octave_value (unsigned short int i) | |
466 : rep (new octave_scalar (i)) | |
467 { | |
468 } | |
469 | |
4233 | 470 octave_value::octave_value (int i) |
471 : rep (new octave_scalar (i)) | |
472 { | |
473 } | |
474 | |
4254 | 475 octave_value::octave_value (unsigned int i) |
476 : rep (new octave_scalar (i)) | |
477 { | |
478 } | |
479 | |
480 octave_value::octave_value (long int i) | |
481 : rep (new octave_scalar (i)) | |
482 { | |
483 } | |
484 | |
485 octave_value::octave_value (unsigned long int i) | |
486 : rep (new octave_scalar (i)) | |
487 { | |
488 } | |
489 | |
4353 | 490 #if defined (HAVE_LONG_LONG_INT) |
491 octave_value::octave_value (long long int i) | |
492 : rep (new octave_scalar (i)) | |
493 { | |
494 } | |
495 #endif | |
496 | |
4355 | 497 #if defined (HAVE_UNSIGNED_LONG_LONG_INT) |
4353 | 498 octave_value::octave_value (unsigned long long int i) |
499 : rep (new octave_scalar (i)) | |
500 { | |
501 } | |
502 #endif | |
503 | |
4254 | 504 octave_value::octave_value (octave_time t) |
7065 | 505 : rep (new octave_scalar (t.double_value ())) |
4254 | 506 { |
507 } | |
508 | |
2376 | 509 octave_value::octave_value (double d) |
2825 | 510 : rep (new octave_scalar (d)) |
511 { | |
512 } | |
2376 | 513 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
514 octave_value::octave_value (float d) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
515 : rep (new octave_float_scalar (d)) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
516 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
517 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
518 |
4587 | 519 octave_value::octave_value (const Cell& c, bool is_csl) |
5477 | 520 : rep (is_csl |
5759 | 521 ? dynamic_cast<octave_base_value *> (new octave_cs_list (c)) |
522 : dynamic_cast<octave_base_value *> (new octave_cell (c))) | |
3351 | 523 { |
524 } | |
525 | |
5147 | 526 octave_value::octave_value (const ArrayN<octave_value>& a, bool is_csl) |
5477 | 527 : rep (is_csl |
5759 | 528 ? dynamic_cast<octave_base_value *> (new octave_cs_list (Cell (a))) |
529 : dynamic_cast<octave_base_value *> (new octave_cell (Cell (a)))) | |
5147 | 530 { |
531 } | |
532 | |
5785 | 533 octave_value::octave_value (const Matrix& m, const MatrixType& t) |
534 : rep (new octave_matrix (m, t)) | |
2423 | 535 { |
536 maybe_mutate (); | |
537 } | |
2376 | 538 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
539 octave_value::octave_value (const FloatMatrix& m, const MatrixType& t) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
540 : rep (new octave_float_matrix (m, t)) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
541 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
542 maybe_mutate (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
543 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
544 |
4507 | 545 octave_value::octave_value (const NDArray& a) |
4513 | 546 : rep (new octave_matrix (a)) |
4478 | 547 { |
548 maybe_mutate (); | |
549 } | |
550 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
551 octave_value::octave_value (const FloatNDArray& a) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
552 : rep (new octave_float_matrix (a)) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
553 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
554 maybe_mutate (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
555 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
556 |
4911 | 557 octave_value::octave_value (const ArrayN<double>& a) |
558 : rep (new octave_matrix (a)) | |
559 { | |
560 maybe_mutate (); | |
561 } | |
562 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
563 octave_value::octave_value (const ArrayN<float>& a) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
564 : rep (new octave_float_matrix (a)) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
565 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
566 maybe_mutate (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
567 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
568 |
2376 | 569 octave_value::octave_value (const DiagMatrix& d) |
2423 | 570 : rep (new octave_matrix (d)) |
571 { | |
572 maybe_mutate (); | |
573 } | |
2376 | 574 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
575 octave_value::octave_value (const FloatDiagMatrix& d) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
576 : rep (new octave_float_matrix (d)) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
577 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
578 maybe_mutate (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
579 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
580 |
3418 | 581 octave_value::octave_value (const RowVector& v) |
582 : rep (new octave_matrix (v)) | |
2423 | 583 { |
584 maybe_mutate (); | |
585 } | |
2376 | 586 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
587 octave_value::octave_value (const FloatRowVector& v) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
588 : rep (new octave_float_matrix (v)) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
589 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
590 maybe_mutate (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
591 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
592 |
3418 | 593 octave_value::octave_value (const ColumnVector& v) |
594 : rep (new octave_matrix (v)) | |
2423 | 595 { |
596 maybe_mutate (); | |
597 } | |
2376 | 598 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
599 octave_value::octave_value (const FloatColumnVector& v) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
600 : rep (new octave_float_matrix (v)) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
601 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
602 maybe_mutate (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
603 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
604 |
2376 | 605 octave_value::octave_value (const Complex& C) |
2423 | 606 : rep (new octave_complex (C)) |
607 { | |
608 maybe_mutate (); | |
609 } | |
2376 | 610 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
611 octave_value::octave_value (const FloatComplex& C) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
612 : rep (new octave_float_complex (C)) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
613 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
614 maybe_mutate (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
615 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
616 |
5785 | 617 octave_value::octave_value (const ComplexMatrix& m, const MatrixType& t) |
618 : rep (new octave_complex_matrix (m, t)) | |
2423 | 619 { |
620 maybe_mutate (); | |
621 } | |
2376 | 622 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
623 octave_value::octave_value (const FloatComplexMatrix& m, const MatrixType& t) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
624 : rep (new octave_float_complex_matrix (m, t)) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
625 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
626 maybe_mutate (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
627 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
628 |
4513 | 629 octave_value::octave_value (const ComplexNDArray& a) |
630 : rep (new octave_complex_matrix (a)) | |
4478 | 631 { |
632 maybe_mutate (); | |
633 } | |
634 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
635 octave_value::octave_value (const FloatComplexNDArray& a) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
636 : rep (new octave_float_complex_matrix (a)) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
637 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
638 maybe_mutate (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
639 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
640 |
4911 | 641 octave_value::octave_value (const ArrayN<Complex>& a) |
642 : rep (new octave_complex_matrix (a)) | |
643 { | |
644 maybe_mutate (); | |
645 } | |
646 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
647 octave_value::octave_value (const ArrayN<FloatComplex>& a) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
648 : rep (new octave_float_complex_matrix (a)) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
649 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
650 maybe_mutate (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
651 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
652 |
2376 | 653 octave_value::octave_value (const ComplexDiagMatrix& d) |
2423 | 654 : rep (new octave_complex_matrix (d)) |
655 { | |
656 maybe_mutate (); | |
657 } | |
2376 | 658 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
659 octave_value::octave_value (const FloatComplexDiagMatrix& d) |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7800
diff
changeset
|
660 : rep (new octave_float_complex_matrix (d)) |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
661 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
662 maybe_mutate (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
663 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
664 |
3418 | 665 octave_value::octave_value (const ComplexRowVector& v) |
666 : rep (new octave_complex_matrix (v)) | |
2423 | 667 { |
668 maybe_mutate (); | |
669 } | |
2376 | 670 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
671 octave_value::octave_value (const FloatComplexRowVector& v) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
672 : rep (new octave_float_complex_matrix (v)) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
673 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
674 maybe_mutate (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
675 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
676 |
3418 | 677 octave_value::octave_value (const ComplexColumnVector& v) |
678 : rep (new octave_complex_matrix (v)) | |
2423 | 679 { |
680 maybe_mutate (); | |
681 } | |
2376 | 682 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
683 octave_value::octave_value (const FloatComplexColumnVector& v) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
684 : rep (new octave_float_complex_matrix (v)) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
685 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
686 maybe_mutate (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
687 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
688 |
2825 | 689 octave_value::octave_value (bool b) |
690 : rep (new octave_bool (b)) | |
691 { | |
692 } | |
693 | |
5785 | 694 octave_value::octave_value (const boolMatrix& bm, const MatrixType& t) |
695 : rep (new octave_bool_matrix (bm, t)) | |
2825 | 696 { |
697 maybe_mutate (); | |
698 } | |
699 | |
4513 | 700 octave_value::octave_value (const boolNDArray& bnda) |
701 : rep (new octave_bool_matrix (bnda)) | |
702 { | |
703 maybe_mutate (); | |
704 } | |
705 | |
7433 | 706 octave_value::octave_value (const ArrayN<bool>& bnda) |
707 : rep (new octave_bool_matrix (bnda)) | |
708 { | |
709 maybe_mutate (); | |
710 } | |
711 | |
5279 | 712 octave_value::octave_value (char c, char type) |
713 : rep (type == '"' | |
714 ? new octave_char_matrix_dq_str (c) | |
715 : new octave_char_matrix_sq_str (c)) | |
3189 | 716 { |
717 maybe_mutate (); | |
718 } | |
719 | |
5279 | 720 octave_value::octave_value (const char *s, char type) |
721 : rep (type == '"' | |
722 ? new octave_char_matrix_dq_str (s) | |
723 : new octave_char_matrix_sq_str (s)) | |
2423 | 724 { |
725 maybe_mutate (); | |
726 } | |
2376 | 727 |
5279 | 728 octave_value::octave_value (const std::string& s, char type) |
729 : rep (type == '"' | |
730 ? new octave_char_matrix_dq_str (s) | |
731 : new octave_char_matrix_sq_str (s)) | |
2423 | 732 { |
733 maybe_mutate (); | |
734 } | |
2376 | 735 |
5279 | 736 octave_value::octave_value (const string_vector& s, char type) |
737 : rep (type == '"' | |
738 ? new octave_char_matrix_dq_str (s) | |
739 : new octave_char_matrix_sq_str (s)) | |
2423 | 740 { |
741 maybe_mutate (); | |
742 } | |
2376 | 743 |
5279 | 744 octave_value::octave_value (const charMatrix& chm, bool is_str, char type) |
4587 | 745 : rep (is_str |
5279 | 746 ? (type == '"' |
747 ? new octave_char_matrix_dq_str (chm) | |
748 : new octave_char_matrix_sq_str (chm)) | |
4513 | 749 : new octave_char_matrix (chm)) |
2409 | 750 { |
4513 | 751 maybe_mutate (); |
752 } | |
2376 | 753 |
5279 | 754 octave_value::octave_value (const charNDArray& chm, bool is_str, char type) |
4587 | 755 : rep (is_str |
5279 | 756 ? (type == '"' |
757 ? new octave_char_matrix_dq_str (chm) | |
758 : new octave_char_matrix_sq_str (chm)) | |
4513 | 759 : new octave_char_matrix (chm)) |
760 { | |
2423 | 761 maybe_mutate (); |
2409 | 762 } |
2376 | 763 |
5279 | 764 octave_value::octave_value (const ArrayN<char>& chm, bool is_str, char type) |
4997 | 765 : rep (is_str |
5279 | 766 ? (type == '"' |
767 ? new octave_char_matrix_dq_str (chm) | |
768 : new octave_char_matrix_sq_str (chm)) | |
4997 | 769 : new octave_char_matrix (chm)) |
770 { | |
771 maybe_mutate (); | |
772 } | |
773 | |
5785 | 774 octave_value::octave_value (const SparseMatrix& m, const MatrixType &t) |
5164 | 775 : rep (new octave_sparse_matrix (m, t)) |
776 { | |
777 maybe_mutate (); | |
778 } | |
779 | |
6863 | 780 octave_value::octave_value (const Sparse<double>& m, const MatrixType &t) |
781 : rep (new octave_sparse_matrix (m, t)) | |
782 { | |
783 maybe_mutate (); | |
784 } | |
785 | |
5785 | 786 octave_value::octave_value (const SparseComplexMatrix& m, const MatrixType &t) |
5164 | 787 : rep (new octave_sparse_complex_matrix (m, t)) |
788 { | |
789 maybe_mutate (); | |
790 } | |
791 | |
6863 | 792 octave_value::octave_value (const Sparse<Complex>& m, const MatrixType &t) |
793 : rep (new octave_sparse_complex_matrix (m, t)) | |
794 { | |
795 maybe_mutate (); | |
796 } | |
797 | |
5785 | 798 octave_value::octave_value (const SparseBoolMatrix& bm, const MatrixType &t) |
5164 | 799 : rep (new octave_sparse_bool_matrix (bm, t)) |
800 { | |
801 maybe_mutate (); | |
802 } | |
803 | |
7433 | 804 octave_value::octave_value (const Sparse<bool>& bm, const MatrixType &t) |
805 : rep (new octave_sparse_bool_matrix (bm, t)) | |
806 { | |
807 maybe_mutate (); | |
808 } | |
809 | |
4901 | 810 octave_value::octave_value (const octave_int8& i) |
811 : rep (new octave_int8_scalar (i)) | |
812 { | |
813 maybe_mutate (); | |
814 } | |
815 | |
816 octave_value::octave_value (const octave_uint8& i) | |
817 : rep (new octave_uint8_scalar (i)) | |
818 { | |
819 maybe_mutate (); | |
820 } | |
821 | |
822 octave_value::octave_value (const octave_int16& i) | |
823 : rep (new octave_int16_scalar (i)) | |
824 { | |
825 maybe_mutate (); | |
826 } | |
827 | |
828 octave_value::octave_value (const octave_uint16& i) | |
829 : rep (new octave_uint16_scalar (i)) | |
830 { | |
831 maybe_mutate (); | |
832 } | |
833 | |
834 octave_value::octave_value (const octave_int32& i) | |
835 : rep (new octave_int32_scalar (i)) | |
836 { | |
837 maybe_mutate (); | |
838 } | |
839 | |
840 octave_value::octave_value (const octave_uint32& i) | |
841 : rep (new octave_uint32_scalar (i)) | |
842 { | |
843 maybe_mutate (); | |
844 } | |
845 | |
846 octave_value::octave_value (const octave_int64& i) | |
847 : rep (new octave_int64_scalar (i)) | |
848 { | |
849 maybe_mutate (); | |
850 } | |
851 | |
852 octave_value::octave_value (const octave_uint64& i) | |
853 : rep (new octave_uint64_scalar (i)) | |
854 { | |
855 maybe_mutate (); | |
856 } | |
857 | |
858 octave_value::octave_value (const int8NDArray& inda) | |
859 : rep (new octave_int8_matrix (inda)) | |
860 { | |
861 maybe_mutate (); | |
862 } | |
863 | |
7064 | 864 octave_value::octave_value (const ArrayN<octave_int8>& inda) |
865 : rep (new octave_int8_matrix (inda)) | |
866 { | |
867 maybe_mutate (); | |
868 } | |
869 | |
4901 | 870 octave_value::octave_value (const uint8NDArray& inda) |
871 : rep (new octave_uint8_matrix (inda)) | |
872 { | |
873 maybe_mutate (); | |
874 } | |
875 | |
7064 | 876 octave_value::octave_value (const ArrayN<octave_uint8>& inda) |
877 : rep (new octave_uint8_matrix (inda)) | |
878 { | |
879 maybe_mutate (); | |
880 } | |
881 | |
4901 | 882 octave_value::octave_value (const int16NDArray& inda) |
883 : rep (new octave_int16_matrix (inda)) | |
884 { | |
885 maybe_mutate (); | |
886 } | |
887 | |
7064 | 888 octave_value::octave_value (const ArrayN<octave_int16>& inda) |
889 : rep (new octave_int16_matrix (inda)) | |
890 { | |
891 maybe_mutate (); | |
892 } | |
893 | |
4901 | 894 octave_value::octave_value (const uint16NDArray& inda) |
895 : rep (new octave_uint16_matrix (inda)) | |
896 { | |
897 maybe_mutate (); | |
898 } | |
899 | |
7064 | 900 octave_value::octave_value (const ArrayN<octave_uint16>& inda) |
901 : rep (new octave_uint16_matrix (inda)) | |
902 { | |
903 maybe_mutate (); | |
904 } | |
905 | |
4901 | 906 octave_value::octave_value (const int32NDArray& inda) |
907 : rep (new octave_int32_matrix (inda)) | |
908 { | |
909 maybe_mutate (); | |
910 } | |
911 | |
7064 | 912 octave_value::octave_value (const ArrayN<octave_int32>& inda) |
913 : rep (new octave_int32_matrix (inda)) | |
914 { | |
915 maybe_mutate (); | |
916 } | |
917 | |
4901 | 918 octave_value::octave_value (const uint32NDArray& inda) |
919 : rep (new octave_uint32_matrix (inda)) | |
920 { | |
921 maybe_mutate (); | |
922 } | |
923 | |
7064 | 924 octave_value::octave_value (const ArrayN<octave_uint32>& inda) |
925 : rep (new octave_uint32_matrix (inda)) | |
926 { | |
927 maybe_mutate (); | |
928 } | |
929 | |
4901 | 930 octave_value::octave_value (const int64NDArray& inda) |
931 : rep (new octave_int64_matrix (inda)) | |
932 { | |
933 maybe_mutate (); | |
934 } | |
935 | |
7064 | 936 octave_value::octave_value (const ArrayN<octave_int64>& inda) |
937 : rep (new octave_int64_matrix (inda)) | |
938 { | |
939 maybe_mutate (); | |
940 } | |
941 | |
4901 | 942 octave_value::octave_value (const uint64NDArray& inda) |
943 : rep (new octave_uint64_matrix (inda)) | |
944 { | |
945 maybe_mutate (); | |
946 } | |
947 | |
7064 | 948 octave_value::octave_value (const ArrayN<octave_uint64>& inda) |
949 : rep (new octave_uint64_matrix (inda)) | |
950 { | |
951 maybe_mutate (); | |
952 } | |
953 | |
2376 | 954 octave_value::octave_value (double base, double limit, double inc) |
2423 | 955 : rep (new octave_range (base, limit, inc)) |
956 { | |
957 maybe_mutate (); | |
958 } | |
2376 | 959 |
960 octave_value::octave_value (const Range& r) | |
2423 | 961 : rep (new octave_range (r)) |
962 { | |
963 maybe_mutate (); | |
964 } | |
2376 | 965 |
966 octave_value::octave_value (const Octave_map& m) | |
2825 | 967 : rep (new octave_struct (m)) |
968 { | |
2880 | 969 } |
970 | |
7336 | 971 octave_value::octave_value (const Octave_map& m, const std::string& id) |
972 : rep (new octave_class (m, id)) | |
973 { | |
974 } | |
975 | |
4587 | 976 octave_value::octave_value (const octave_value_list& l, bool is_csl) |
5477 | 977 : rep (is_csl |
5759 | 978 ? dynamic_cast<octave_base_value *> (new octave_cs_list (l)) |
979 : dynamic_cast<octave_base_value *> (new octave_list (l))) | |
2880 | 980 { |
981 } | |
2376 | 982 |
983 octave_value::octave_value (octave_value::magic_colon) | |
2825 | 984 : rep (new octave_magic_colon ()) |
985 { | |
986 } | |
2376 | 987 |
5759 | 988 octave_value::octave_value (octave_base_value *new_rep) |
2825 | 989 : rep (new_rep) |
990 { | |
991 } | |
2376 | 992 |
7336 | 993 octave_value::octave_value (octave_base_value *new_rep, int xcount) |
994 : rep (new_rep) | |
995 { | |
996 rep->count = xcount; | |
997 } | |
998 | |
5759 | 999 octave_base_value * |
3933 | 1000 octave_value::clone (void) const |
2880 | 1001 { |
1002 panic_impossible (); | |
3546 | 1003 return 0; |
2880 | 1004 } |
1005 | |
2409 | 1006 void |
1007 octave_value::maybe_mutate (void) | |
1008 { | |
5759 | 1009 octave_base_value *tmp = rep->try_narrowing_conversion (); |
2409 | 1010 |
1011 if (tmp && tmp != rep) | |
1012 { | |
1013 if (--rep->count == 0) | |
1014 delete rep; | |
1015 | |
1016 rep = tmp; | |
1017 } | |
1018 } | |
1019 | |
4247 | 1020 octave_value |
4271 | 1021 octave_value::single_subsref (const std::string& type, |
1022 const octave_value_list& idx) | |
4247 | 1023 { |
1024 std::list<octave_value_list> i; | |
1025 | |
1026 i.push_back (idx); | |
1027 | |
1028 return rep->subsref (type, i); | |
1029 } | |
1030 | |
2974 | 1031 octave_value_list |
4247 | 1032 octave_value::subsref (const std::string& type, |
4219 | 1033 const std::list<octave_value_list>& idx, int nargout) |
3933 | 1034 { |
7651
443a8f5a50fd
require both subsref variants to be defined in octave_value subclasses
John W. Eaton <jwe@octave.org>
parents:
7503
diff
changeset
|
1035 if (nargout == 1) |
3933 | 1036 return rep->subsref (type, idx); |
1037 else | |
1038 return rep->subsref (type, idx, nargout); | |
1039 } | |
1040 | |
1041 octave_value | |
4247 | 1042 octave_value::next_subsref (const std::string& type, |
4219 | 1043 const std::list<octave_value_list>& idx, |
4233 | 1044 size_t skip) |
3933 | 1045 { |
4582 | 1046 if (! error_state && idx.size () > skip) |
3933 | 1047 { |
4219 | 1048 std::list<octave_value_list> new_idx (idx); |
4233 | 1049 for (size_t i = 0; i < skip; i++) |
4219 | 1050 new_idx.erase (new_idx.begin ()); |
3933 | 1051 return subsref (type.substr (skip), new_idx); |
1052 } | |
1053 else | |
1054 return *this; | |
1055 } | |
1056 | |
1057 octave_value_list | |
4994 | 1058 octave_value::next_subsref (int nargout, const std::string& type, |
1059 const std::list<octave_value_list>& idx, | |
1060 size_t skip) | |
1061 { | |
1062 if (! error_state && idx.size () > skip) | |
1063 { | |
1064 std::list<octave_value_list> new_idx (idx); | |
1065 for (size_t i = 0; i < skip; i++) | |
1066 new_idx.erase (new_idx.begin ()); | |
1067 return subsref (type.substr (skip), new_idx, nargout); | |
1068 } | |
1069 else | |
1070 return *this; | |
1071 } | |
1072 | |
1073 octave_value_list | |
3544 | 1074 octave_value::do_multi_index_op (int nargout, const octave_value_list& idx) |
2974 | 1075 { |
3544 | 1076 return rep->do_multi_index_op (nargout, idx); |
2974 | 1077 } |
1078 | |
3933 | 1079 #if 0 |
3204 | 1080 static void |
3933 | 1081 gripe_assign_failed (const std::string& on, const std::string& tn1, |
1082 const std::string& tn2) | |
3204 | 1083 { |
1084 error ("assignment failed for `%s %s %s'", | |
1085 tn1.c_str (), on.c_str (), tn2.c_str ()); | |
1086 } | |
3933 | 1087 #endif |
3204 | 1088 |
1089 static void | |
3933 | 1090 gripe_assign_failed_or_no_method (const std::string& on, |
1091 const std::string& tn1, | |
3523 | 1092 const std::string& tn2) |
3204 | 1093 { |
1094 error ("assignment failed, or no method for `%s %s %s'", | |
1095 tn1.c_str (), on.c_str (), tn2.c_str ()); | |
1096 } | |
1097 | |
3933 | 1098 octave_value |
4247 | 1099 octave_value::subsasgn (const std::string& type, |
4219 | 1100 const std::list<octave_value_list>& idx, |
3933 | 1101 const octave_value& rhs) |
1102 { | |
1103 return rep->subsasgn (type, idx, rhs); | |
1104 } | |
1105 | |
1106 octave_value | |
4247 | 1107 octave_value::assign (assign_op op, const std::string& type, |
4219 | 1108 const std::list<octave_value_list>& idx, |
3933 | 1109 const octave_value& rhs) |
1110 { | |
1111 octave_value retval; | |
1112 | |
1113 make_unique (); | |
1114 | |
1115 octave_value t_rhs = rhs; | |
1116 | |
1117 if (op != op_asn_eq) | |
1118 { | |
5775 | 1119 // FIXME -- only do the following stuff if we can't find |
3933 | 1120 // a specific function to call to handle the op= operation for |
1121 // the types we have. | |
1122 | |
7651
443a8f5a50fd
require both subsref variants to be defined in octave_value subclasses
John W. Eaton <jwe@octave.org>
parents:
7503
diff
changeset
|
1123 octave_value t = subsref (type, idx); |
3933 | 1124 |
1125 if (! error_state) | |
1126 { | |
1127 binary_op binop = op_eq_to_binary_op (op); | |
1128 | |
1129 if (! error_state) | |
1130 t_rhs = do_binary_op (binop, t, rhs); | |
1131 } | |
1132 } | |
1133 | |
1134 if (! error_state) | |
1135 { | |
7336 | 1136 if (type[0] == '.' && ! (is_map () || is_object ())) |
3933 | 1137 { |
1138 octave_value tmp = Octave_map (); | |
1139 retval = tmp.subsasgn (type, idx, t_rhs); | |
1140 } | |
1141 else | |
1142 retval = subsasgn (type, idx, t_rhs); | |
1143 } | |
1144 | |
1145 if (error_state) | |
1146 gripe_assign_failed_or_no_method (assign_op_as_string (op), | |
1147 type_name (), rhs.type_name ()); | |
1148 | |
1149 return retval; | |
1150 } | |
1151 | |
1152 const octave_value& | |
3203 | 1153 octave_value::assign (assign_op op, const octave_value& rhs) |
2880 | 1154 { |
3533 | 1155 if (op == op_asn_eq) |
3203 | 1156 operator = (rhs); |
1157 else | |
1158 { | |
5775 | 1159 // FIXME -- only do the following stuff if we can't find |
3204 | 1160 // a specific function to call to handle the op= operation for |
1161 // the types we have. | |
1162 | |
1163 binary_op binop = op_eq_to_binary_op (op); | |
1164 | |
1165 if (! error_state) | |
1166 { | |
1167 octave_value t = do_binary_op (binop, *this, rhs); | |
1168 | |
1169 if (! error_state) | |
1170 operator = (t); | |
1171 } | |
1172 | |
1173 if (error_state) | |
1174 gripe_assign_failed_or_no_method (assign_op_as_string (op), | |
1175 type_name (), rhs.type_name ()); | |
1176 } | |
1177 | |
3933 | 1178 return *this; |
2376 | 1179 } |
1180 | |
5275 | 1181 octave_idx_type |
4563 | 1182 octave_value::length (void) const |
1183 { | |
1184 int retval = 0; | |
1185 | |
1186 dim_vector dv = dims (); | |
4584 | 1187 |
4563 | 1188 for (int i = 0; i < dv.length (); i++) |
1189 { | |
1190 if (dv(i) < 0) | |
1191 { | |
1192 retval = -1; | |
1193 break; | |
1194 } | |
1195 | |
4584 | 1196 if (dv(i) == 0) |
1197 { | |
1198 retval = 0; | |
1199 break; | |
1200 } | |
1201 | |
4563 | 1202 if (dv(i) > retval) |
1203 retval = dv(i); | |
1204 } | |
1205 | |
1206 return retval; | |
1207 } | |
1208 | |
5659 | 1209 Matrix |
1210 octave_value::size (void) const | |
1211 { | |
1212 dim_vector dv = dims (); | |
1213 | |
1214 int n_dims = dv.length (); | |
1215 | |
1216 Matrix retval (1, n_dims); | |
1217 | |
1218 while (n_dims--) | |
1219 retval(n_dims) = dv(n_dims); | |
1220 | |
1221 return retval; | |
1222 } | |
1223 | |
3351 | 1224 Cell |
1225 octave_value::cell_value (void) const | |
1226 { | |
1227 return rep->cell_value (); | |
1228 } | |
1229 | |
2376 | 1230 Octave_map |
1231 octave_value::map_value (void) const | |
1232 { | |
1233 return rep->map_value (); | |
1234 } | |
1235 | |
2974 | 1236 octave_function * |
1237 octave_value::function_value (bool silent) | |
1238 { | |
1239 return rep->function_value (silent); | |
1240 } | |
1241 | |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
1242 const octave_function * |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
1243 octave_value::function_value (bool silent) const |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
1244 { |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
1245 return rep->function_value (silent); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
1246 } |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
1247 |
4700 | 1248 octave_user_function * |
1249 octave_value::user_function_value (bool silent) | |
1250 { | |
1251 return rep->user_function_value (silent); | |
1252 } | |
1253 | |
7719
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
1254 octave_user_script * |
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
1255 octave_value::user_script_value (bool silent) |
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
1256 { |
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
1257 return rep->user_script_value (silent); |
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
1258 } |
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
1259 |
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
1260 octave_user_code * |
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
1261 octave_value::user_code_value (bool silent) |
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
1262 { |
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
1263 return rep->user_code_value (silent); |
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
1264 } |
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7651
diff
changeset
|
1265 |
4346 | 1266 octave_fcn_handle * |
4343 | 1267 octave_value::fcn_handle_value (bool silent) |
1268 { | |
1269 return rep->fcn_handle_value (silent); | |
1270 } | |
1271 | |
4933 | 1272 octave_fcn_inline * |
1273 octave_value::fcn_inline_value (bool silent) | |
1274 { | |
1275 return rep->fcn_inline_value (silent); | |
1276 } | |
1277 | |
2880 | 1278 octave_value_list |
1279 octave_value::list_value (void) const | |
1280 { | |
1281 return rep->list_value (); | |
1282 } | |
1283 | |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1284 static dim_vector |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1285 make_vector_dims (const dim_vector& dv, bool force_vector_conversion, |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1286 const std::string& my_type, const std::string& wanted_type) |
3419 | 1287 { |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1288 dim_vector retval (dv); |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1289 retval.chop_trailing_singletons (); |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1290 octave_idx_type nel = dv.numel (); |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1291 |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1292 if (retval.length () > 2 || (retval(0) != 1 && retval(1) != 1)) |
3419 | 1293 { |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1294 if (!force_vector_conversion) |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1295 gripe_implicit_conversion ("Octave:array-as-vector", |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1296 my_type.c_str (), wanted_type.c_str ()); |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1297 retval = dim_vector (nel); |
3419 | 1298 } |
1299 | |
1300 return retval; | |
1301 } | |
1302 | |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1303 ColumnVector |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1304 octave_value::column_vector_value (bool force_string_conv, |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1305 bool frc_vec_conv) const |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1306 { |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1307 return ColumnVector (vector_value (force_string_conv, |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1308 frc_vec_conv)); |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1309 } |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1310 |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1311 ComplexColumnVector |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1312 octave_value::complex_column_vector_value (bool force_string_conv, |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1313 bool frc_vec_conv) const |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1314 { |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1315 return ComplexColumnVector (complex_vector_value (force_string_conv, |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1316 frc_vec_conv)); |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1317 } |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1318 |
3419 | 1319 RowVector |
1320 octave_value::row_vector_value (bool force_string_conv, | |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1321 bool frc_vec_conv) const |
3419 | 1322 { |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1323 return RowVector (vector_value (force_string_conv, |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1324 frc_vec_conv)); |
3419 | 1325 } |
1326 | |
1327 ComplexRowVector | |
1328 octave_value::complex_row_vector_value (bool force_string_conv, | |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1329 bool frc_vec_conv) const |
3419 | 1330 { |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1331 return ComplexRowVector (complex_vector_value (force_string_conv, |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1332 frc_vec_conv)); |
3419 | 1333 } |
1334 | |
1335 Array<double> | |
2376 | 1336 octave_value::vector_value (bool force_string_conv, |
1337 bool force_vector_conversion) const | |
1338 { | |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1339 Array<double> retval = array_value (force_string_conv); |
2376 | 1340 |
1341 if (error_state) | |
1342 return retval; | |
1343 else | |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1344 return retval.reshape (make_vector_dims (retval.dims (), |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1345 force_vector_conversion, |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1346 type_name (), "real vector")); |
2376 | 1347 } |
1348 | |
7997
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1349 template <class T> |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1350 static Array<int> |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1351 convert_to_int_array (const Array<octave_int<T> >& A) |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1352 { |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1353 Array<int> O (A.dims ()); |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1354 octave_idx_type n = A.numel (); |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1355 |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1356 octave_int<int>::clear_trunc_flag (); |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1357 for (octave_idx_type i = 0; i < n; i++) |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1358 O.xelem (i) = octave_int<int> (A.xelem (i)); |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1359 if (octave_int<int>::get_trunc_flag ()) |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1360 { |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1361 gripe_truncated_conversion (octave_int<T>::type_name (), "int"); |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1362 octave_int<int>::clear_trunc_flag (); |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1363 } |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1364 |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1365 return O; |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1366 } |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1367 |
4044 | 1368 Array<int> |
1369 octave_value::int_vector_value (bool force_string_conv, bool require_int, | |
1370 bool force_vector_conversion) const | |
1371 { | |
1372 Array<int> retval; | |
1373 | |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1374 if (is_integer_type ()) |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1375 { |
7997
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1376 if (is_int32_type ()) |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1377 retval = convert_to_int_array (int32_array_value ()); |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1378 else if (is_int64_type ()) |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1379 retval = convert_to_int_array (int64_array_value ()); |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1380 else if (is_int16_type ()) |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1381 retval = convert_to_int_array (int16_array_value ()); |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1382 else if (is_int8_type ()) |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1383 retval = convert_to_int_array (int8_array_value ()); |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1384 else if (is_uint32_type ()) |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1385 retval = convert_to_int_array (uint32_array_value ()); |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1386 else if (is_uint64_type ()) |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1387 retval = convert_to_int_array (uint64_array_value ()); |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1388 else if (is_uint16_type ()) |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1389 retval = convert_to_int_array (uint16_array_value ()); |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1390 else if (is_uint8_type ()) |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1391 retval = convert_to_int_array (uint8_array_value ()); |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1392 else |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1393 retval = array_value (force_string_conv); |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1394 } |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1395 else |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1396 { |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1397 const NDArray a = array_value (force_string_conv); |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1398 if (! error_state) |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1399 { |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1400 if (require_int) |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1401 { |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1402 retval.resize (a.dims ()); |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1403 for (octave_idx_type i = 0; i < a.numel (); i++) |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1404 { |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1405 double ai = a.elem (i); |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1406 int v = static_cast<int> (ai); |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1407 if (ai == v) |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1408 retval.xelem (i) = v; |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1409 else |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1410 { |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1411 error ("conversion to integer value failed"); |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1412 break; |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1413 } |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1414 } |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1415 } |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1416 else |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1417 retval = Array<int> (a); |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1418 } |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1419 } |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1420 |
4044 | 1421 |
1422 if (error_state) | |
1423 return retval; | |
1424 else | |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1425 return retval.reshape (make_vector_dims (retval.dims (), |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1426 force_vector_conversion, |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1427 type_name (), "integer vector")); |
4044 | 1428 } |
1429 | |
3419 | 1430 Array<Complex> |
2376 | 1431 octave_value::complex_vector_value (bool force_string_conv, |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1432 bool force_vector_conversion) const |
2376 | 1433 { |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1434 Array<Complex> retval = complex_array_value (force_string_conv); |
2376 | 1435 |
1436 if (error_state) | |
1437 return retval; | |
1438 else | |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1439 return retval.reshape (make_vector_dims (retval.dims (), |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1440 force_vector_conversion, |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1441 type_name (), "complex vector")); |
2376 | 1442 } |
1443 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1444 FloatColumnVector |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1445 octave_value::float_column_vector_value (bool force_string_conv, |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1446 bool frc_vec_conv) const |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1447 { |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1448 return FloatColumnVector (float_vector_value (force_string_conv, |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1449 frc_vec_conv)); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1450 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1451 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1452 FloatComplexColumnVector |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1453 octave_value::float_complex_column_vector_value (bool force_string_conv, |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1454 bool frc_vec_conv) const |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1455 { |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1456 return FloatComplexColumnVector (float_complex_vector_value (force_string_conv, |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1457 frc_vec_conv)); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1458 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1459 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1460 FloatRowVector |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1461 octave_value::float_row_vector_value (bool force_string_conv, |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1462 bool frc_vec_conv) const |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1463 { |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1464 return FloatRowVector (float_vector_value (force_string_conv, |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1465 frc_vec_conv)); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1466 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1467 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1468 FloatComplexRowVector |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1469 octave_value::float_complex_row_vector_value (bool force_string_conv, |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1470 bool frc_vec_conv) const |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1471 { |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1472 return FloatComplexRowVector (float_complex_vector_value (force_string_conv, |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1473 frc_vec_conv)); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1474 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1475 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1476 Array<float> |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1477 octave_value::float_vector_value (bool force_string_conv, |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1478 bool force_vector_conversion) const |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1479 { |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1480 Array<float> retval = float_array_value (force_string_conv); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1481 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1482 if (error_state) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1483 return retval; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1484 else |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1485 return retval.reshape (make_vector_dims (retval.dims (), |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1486 force_vector_conversion, |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1487 type_name (), "real vector")); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1488 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1489 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1490 Array<FloatComplex> |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1491 octave_value::float_complex_vector_value (bool force_string_conv, |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1492 bool force_vector_conversion) const |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1493 { |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1494 Array<FloatComplex> retval = float_complex_array_value (force_string_conv); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1495 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1496 if (error_state) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1497 return retval; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1498 else |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1499 return retval.reshape (make_vector_dims (retval.dims (), |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1500 force_vector_conversion, |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1501 type_name (), "complex vector")); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1502 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1503 |
4944 | 1504 int |
1505 octave_value::write (octave_stream& os, int block_size, | |
1506 oct_data_conv::data_type output_type, int skip, | |
1507 oct_mach_info::float_format flt_fmt) const | |
1508 { | |
1509 return rep->write (os, block_size, output_type, skip, flt_fmt); | |
1510 } | |
1511 | |
2413 | 1512 static void |
3933 | 1513 gripe_binary_op (const std::string& on, const std::string& tn1, |
1514 const std::string& tn2) | |
2376 | 1515 { |
2903 | 1516 error ("binary operator `%s' not implemented for `%s' by `%s' operations", |
2376 | 1517 on.c_str (), tn1.c_str (), tn2.c_str ()); |
1518 } | |
1519 | |
3203 | 1520 static void |
3523 | 1521 gripe_binary_op_conv (const std::string& on) |
3203 | 1522 { |
1523 error ("type conversion failed for binary operator `%s'", on.c_str ()); | |
1524 } | |
1525 | |
2376 | 1526 octave_value |
3933 | 1527 do_binary_op (octave_value::binary_op op, |
1528 const octave_value& v1, const octave_value& v2) | |
2376 | 1529 { |
1530 octave_value retval; | |
1531 | |
1532 int t1 = v1.type_id (); | |
1533 int t2 = v2.type_id (); | |
1534 | |
7336 | 1535 if (t1 == octave_class::static_type_id () |
1536 || t2 == octave_class::static_type_id ()) | |
1537 { | |
1538 octave_value_typeinfo::binary_class_op_fcn f | |
1539 = octave_value_typeinfo::lookup_binary_class_op (op); | |
2376 | 1540 |
7336 | 1541 if (f) |
7487
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1542 { |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1543 try |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1544 { |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1545 retval = f (v1, v2); |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1546 } |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1547 catch (octave_execution_exception) |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1548 { |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1549 octave_exception_state = octave_no_exception; |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1550 error ("caught execution error in library function"); |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1551 } |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1552 } |
7336 | 1553 else |
1554 gripe_binary_op (octave_value::binary_op_as_string (op), | |
1555 v1.class_name (), v2.class_name ()); | |
1556 } | |
2376 | 1557 else |
1558 { | |
7336 | 1559 // FIXME -- we need to handle overloading operators for built-in |
1560 // classes (double, char, int8, etc.) | |
2376 | 1561 |
7336 | 1562 octave_value_typeinfo::binary_op_fcn f |
1563 = octave_value_typeinfo::lookup_binary_op (op, t1, t2); | |
1564 | |
1565 if (f) | |
7487
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1566 { |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1567 try |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1568 { |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1569 retval = f (*v1.rep, *v2.rep); |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1570 } |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1571 catch (octave_execution_exception) |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1572 { |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1573 octave_exception_state = octave_no_exception; |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1574 error ("caught execution error in library function"); |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1575 } |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1576 } |
7336 | 1577 else |
2376 | 1578 { |
7336 | 1579 octave_value tv1; |
1580 octave_base_value::type_conv_fcn cf1 = v1.numeric_conversion_function (); | |
1581 | |
1582 if (cf1) | |
1583 { | |
1584 octave_base_value *tmp = cf1 (*v1.rep); | |
3203 | 1585 |
7336 | 1586 if (tmp) |
1587 { | |
1588 tv1 = octave_value (tmp); | |
1589 t1 = tv1.type_id (); | |
1590 } | |
1591 else | |
1592 { | |
1593 gripe_binary_op_conv (octave_value::binary_op_as_string (op)); | |
1594 return retval; | |
1595 } | |
3203 | 1596 } |
1597 else | |
7336 | 1598 tv1 = v1; |
1599 | |
1600 octave_value tv2; | |
1601 octave_base_value::type_conv_fcn cf2 = v2.numeric_conversion_function (); | |
1602 | |
1603 if (cf2) | |
3203 | 1604 { |
7336 | 1605 octave_base_value *tmp = cf2 (*v2.rep); |
2376 | 1606 |
7336 | 1607 if (tmp) |
1608 { | |
1609 tv2 = octave_value (tmp); | |
1610 t2 = tv2.type_id (); | |
1611 } | |
1612 else | |
1613 { | |
1614 gripe_binary_op_conv (octave_value::binary_op_as_string (op)); | |
1615 return retval; | |
1616 } | |
3203 | 1617 } |
1618 else | |
7336 | 1619 tv2 = v2; |
1620 | |
1621 if (cf1 || cf2) | |
3203 | 1622 { |
7336 | 1623 f = octave_value_typeinfo::lookup_binary_op (op, t1, t2); |
1624 | |
1625 if (f) | |
7487
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1626 { |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1627 try |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1628 { |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1629 retval = f (*tv1.rep, *tv2.rep); |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1630 } |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1631 catch (octave_execution_exception) |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1632 { |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1633 octave_exception_state = octave_no_exception; |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1634 error ("caught execution error in library function"); |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1635 } |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1636 } |
7336 | 1637 else |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1638 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1639 //demote double -> single and try again |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1640 cf1 = tv1.numeric_demotion_function (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1641 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1642 if (cf1) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1643 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1644 octave_base_value *tmp = cf1 (*tv1.rep); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1645 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1646 if (tmp) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1647 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1648 tv1 = octave_value (tmp); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1649 t1 = tv1.type_id (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1650 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1651 else |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1652 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1653 gripe_binary_op_conv (octave_value::binary_op_as_string (op)); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1654 return retval; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1655 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1656 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1657 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1658 cf2 = tv2.numeric_demotion_function (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1659 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1660 if (cf2) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1661 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1662 octave_base_value *tmp = cf2 (*tv2.rep); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1663 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1664 if (tmp) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1665 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1666 tv2 = octave_value (tmp); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1667 t2 = tv2.type_id (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1668 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1669 else |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1670 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1671 gripe_binary_op_conv (octave_value::binary_op_as_string (op)); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1672 return retval; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1673 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1674 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1675 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1676 if (cf1 || cf2) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1677 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1678 f = octave_value_typeinfo::lookup_binary_op (op, t1, t2); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1679 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1680 if (f) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1681 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1682 try |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1683 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1684 retval = f (*tv1.rep, *tv2.rep); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1685 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1686 catch (octave_execution_exception) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1687 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1688 octave_exception_state = octave_no_exception; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1689 error ("caught execution error in library function"); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1690 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1691 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1692 else |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1693 gripe_binary_op (octave_value::binary_op_as_string (op), |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1694 v1.type_name (), v2.type_name ()); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1695 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1696 else |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1697 gripe_binary_op (octave_value::binary_op_as_string (op), |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1698 v1.type_name (), v2.type_name ()); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1699 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1700 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1701 else |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1702 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1703 //demote double -> single and try again |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1704 cf1 = tv1.numeric_demotion_function (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1705 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1706 if (cf1) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1707 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1708 octave_base_value *tmp = cf1 (*tv1.rep); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1709 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1710 if (tmp) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1711 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1712 tv1 = octave_value (tmp); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1713 t1 = tv1.type_id (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1714 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1715 else |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1716 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1717 gripe_binary_op_conv (octave_value::binary_op_as_string (op)); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1718 return retval; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1719 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1720 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1721 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1722 cf2 = tv2.numeric_demotion_function (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1723 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1724 if (cf2) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1725 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1726 octave_base_value *tmp = cf2 (*tv2.rep); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1727 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1728 if (tmp) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1729 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1730 tv2 = octave_value (tmp); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1731 t2 = tv2.type_id (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1732 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1733 else |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1734 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1735 gripe_binary_op_conv (octave_value::binary_op_as_string (op)); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1736 return retval; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1737 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1738 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1739 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1740 if (cf1 || cf2) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1741 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1742 f = octave_value_typeinfo::lookup_binary_op (op, t1, t2); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1743 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1744 if (f) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1745 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1746 try |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1747 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1748 retval = f (*tv1.rep, *tv2.rep); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1749 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1750 catch (octave_execution_exception) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1751 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1752 octave_exception_state = octave_no_exception; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1753 error ("caught execution error in library function"); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1754 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1755 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1756 else |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1757 gripe_binary_op (octave_value::binary_op_as_string (op), |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1758 v1.type_name (), v2.type_name ()); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1759 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1760 else |
7336 | 1761 gripe_binary_op (octave_value::binary_op_as_string (op), |
1762 v1.type_name (), v2.type_name ()); | |
3203 | 1763 } |
2376 | 1764 } |
1765 } | |
1766 | |
1767 return retval; | |
1768 } | |
1769 | |
7800
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1770 static octave_value |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1771 decompose_binary_op (octave_value::compound_binary_op op, |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1772 const octave_value& v1, const octave_value& v2) |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1773 { |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1774 octave_value retval; |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1775 |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1776 switch (op) |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1777 { |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1778 case octave_value::op_trans_mul: |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1779 retval = do_binary_op (octave_value::op_mul, |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1780 do_unary_op (octave_value::op_transpose, v1), |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1781 v2); |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1782 break; |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1783 case octave_value::op_mul_trans: |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1784 retval = do_binary_op (octave_value::op_mul, |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1785 v1, |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1786 do_unary_op (octave_value::op_transpose, v2)); |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1787 break; |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1788 case octave_value::op_herm_mul: |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1789 retval = do_binary_op (octave_value::op_mul, |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1790 do_unary_op (octave_value::op_hermitian, v1), |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1791 v2); |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1792 break; |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1793 case octave_value::op_mul_herm: |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1794 retval = do_binary_op (octave_value::op_mul, |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1795 v1, |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1796 do_unary_op (octave_value::op_hermitian, v2)); |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1797 break; |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1798 default: |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1799 error ("invalid compound operator"); |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1800 break; |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1801 } |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1802 |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1803 return retval; |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1804 } |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1805 |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1806 octave_value |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1807 do_binary_op (octave_value::compound_binary_op op, |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1808 const octave_value& v1, const octave_value& v2) |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1809 { |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1810 octave_value retval; |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1811 |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1812 int t1 = v1.type_id (); |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1813 int t2 = v2.type_id (); |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1814 |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1815 if (t1 == octave_class::static_type_id () |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1816 || t2 == octave_class::static_type_id ()) |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1817 { |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1818 octave_value_typeinfo::binary_class_op_fcn f |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1819 = octave_value_typeinfo::lookup_binary_class_op (op); |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1820 |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1821 if (f) |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1822 { |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1823 try |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1824 { |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1825 retval = f (v1, v2); |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1826 } |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1827 catch (octave_execution_exception) |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1828 { |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1829 octave_exception_state = octave_no_exception; |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1830 error ("caught execution error in library function"); |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1831 } |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1832 } |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1833 else |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1834 retval = decompose_binary_op (op, v1, v2); |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1835 } |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1836 else |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1837 { |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1838 octave_value_typeinfo::binary_op_fcn f |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1839 = octave_value_typeinfo::lookup_binary_op (op, t1, t2); |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1840 |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1841 if (f) |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1842 { |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1843 try |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1844 { |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1845 retval = f (*v1.rep, *v2.rep); |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1846 } |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1847 catch (octave_execution_exception) |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1848 { |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1849 octave_exception_state = octave_no_exception; |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1850 error ("caught execution error in library function"); |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1851 } |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1852 } |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1853 else |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1854 retval = decompose_binary_op (op, v1, v2); |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1855 } |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1856 |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1857 return retval; |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1858 } |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1859 |
4915 | 1860 static void |
1861 gripe_cat_op (const std::string& tn1, const std::string& tn2) | |
1862 { | |
1863 error ("concatenation operator not implemented for `%s' by `%s' operations", | |
1864 tn1.c_str (), tn2.c_str ()); | |
1865 } | |
1866 | |
1867 static void | |
1868 gripe_cat_op_conv (void) | |
1869 { | |
1870 error ("type conversion failed for concatenation operator"); | |
1871 } | |
1872 | |
1873 octave_value | |
1874 do_cat_op (const octave_value& v1, const octave_value& v2, | |
6867 | 1875 const Array<octave_idx_type>& ra_idx) |
4915 | 1876 { |
1877 octave_value retval; | |
1878 | |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7800
diff
changeset
|
1879 // Can't rapid return for concatenation with an empty object here as |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7800
diff
changeset
|
1880 // something like cat(1,[],single([]) must return the correct type. |
5164 | 1881 |
4915 | 1882 int t1 = v1.type_id (); |
1883 int t2 = v2.type_id (); | |
1884 | |
5759 | 1885 octave_value_typeinfo::cat_op_fcn f |
1886 = octave_value_typeinfo::lookup_cat_op (t1, t2); | |
4915 | 1887 |
1888 if (f) | |
7487
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1889 { |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1890 try |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1891 { |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1892 retval = f (*v1.rep, *v2.rep, ra_idx); |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1893 } |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1894 catch (octave_execution_exception) |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1895 { |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1896 octave_exception_state = octave_no_exception; |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1897 error ("caught execution error in library function"); |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1898 } |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1899 } |
4915 | 1900 else |
1901 { | |
1902 octave_value tv1; | |
5759 | 1903 octave_base_value::type_conv_fcn cf1 = v1.numeric_conversion_function (); |
4915 | 1904 |
1905 if (cf1) | |
1906 { | |
5759 | 1907 octave_base_value *tmp = cf1 (*v1.rep); |
4915 | 1908 |
1909 if (tmp) | |
1910 { | |
1911 tv1 = octave_value (tmp); | |
1912 t1 = tv1.type_id (); | |
1913 } | |
1914 else | |
1915 { | |
1916 gripe_cat_op_conv (); | |
1917 return retval; | |
1918 } | |
1919 } | |
1920 else | |
1921 tv1 = v1; | |
1922 | |
1923 octave_value tv2; | |
5759 | 1924 octave_base_value::type_conv_fcn cf2 = v2.numeric_conversion_function (); |
4915 | 1925 |
1926 if (cf2) | |
1927 { | |
5759 | 1928 octave_base_value *tmp = cf2 (*v2.rep); |
4915 | 1929 |
1930 if (tmp) | |
1931 { | |
1932 tv2 = octave_value (tmp); | |
1933 t2 = tv2.type_id (); | |
1934 } | |
1935 else | |
1936 { | |
1937 gripe_cat_op_conv (); | |
1938 return retval; | |
1939 } | |
1940 } | |
1941 else | |
1942 tv2 = v2; | |
1943 | |
1944 if (cf1 || cf2) | |
1945 { | |
1946 f = octave_value_typeinfo::lookup_cat_op (t1, t2); | |
1947 | |
1948 if (f) | |
7487
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1949 { |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1950 try |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1951 { |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1952 retval = f (*tv1.rep, *tv2.rep, ra_idx); |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1953 } |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1954 catch (octave_execution_exception) |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1955 { |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1956 octave_exception_state = octave_no_exception; |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1957 error ("caught execution error in library function"); |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1958 } |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1959 } |
4915 | 1960 else |
1961 gripe_cat_op (v1.type_name (), v2.type_name ()); | |
1962 } | |
1963 else | |
1964 gripe_cat_op (v1.type_name (), v2.type_name ()); | |
1965 } | |
1966 | |
1967 return retval; | |
1968 } | |
1969 | |
3933 | 1970 void |
1971 octave_value::print_info (std::ostream& os, const std::string& prefix) const | |
1972 { | |
1973 os << prefix << "type_name: " << type_name () << "\n" | |
1974 << prefix << "count: " << get_count () << "\n" | |
1975 << prefix << "rep info: "; | |
1976 | |
1977 rep->print_info (os, prefix + " "); | |
1978 } | |
1979 | |
3203 | 1980 static void |
3523 | 1981 gripe_unary_op (const std::string& on, const std::string& tn) |
3203 | 1982 { |
1983 error ("unary operator `%s' not implemented for `%s' operands", | |
1984 on.c_str (), tn.c_str ()); | |
1985 } | |
1986 | |
1987 static void | |
3523 | 1988 gripe_unary_op_conv (const std::string& on) |
3203 | 1989 { |
1990 error ("type conversion failed for unary operator `%s'", on.c_str ()); | |
1991 } | |
1992 | |
1993 octave_value | |
1994 do_unary_op (octave_value::unary_op op, const octave_value& v) | |
1995 { | |
1996 octave_value retval; | |
1997 | |
1998 int t = v.type_id (); | |
1999 | |
7336 | 2000 if (t == octave_class::static_type_id ()) |
2001 { | |
2002 octave_value_typeinfo::unary_class_op_fcn f | |
2003 = octave_value_typeinfo::lookup_unary_class_op (op); | |
3203 | 2004 |
7336 | 2005 if (f) |
7487
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2006 { |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2007 try |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2008 { |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2009 retval = f (v); |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2010 } |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2011 catch (octave_execution_exception) |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2012 { |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2013 octave_exception_state = octave_no_exception; |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2014 error ("caught execution error in library function"); |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2015 } |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2016 } |
7336 | 2017 else |
2018 gripe_unary_op (octave_value::unary_op_as_string (op), | |
2019 v.class_name ()); | |
2020 } | |
3203 | 2021 else |
2022 { | |
7336 | 2023 // FIXME -- we need to handle overloading operators for built-in |
2024 // classes (double, char, int8, etc.) | |
2025 | |
2026 octave_value_typeinfo::unary_op_fcn f | |
2027 = octave_value_typeinfo::lookup_unary_op (op, t); | |
3203 | 2028 |
7336 | 2029 if (f) |
7487
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2030 { |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2031 try |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2032 { |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2033 retval = f (*v.rep); |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2034 } |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2035 catch (octave_execution_exception) |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2036 { |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2037 octave_exception_state = octave_no_exception; |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2038 error ("caught execution error in library function"); |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2039 } |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2040 } |
7336 | 2041 else |
3203 | 2042 { |
7336 | 2043 octave_value tv; |
2044 octave_base_value::type_conv_fcn cf | |
2045 = v.numeric_conversion_function (); | |
3203 | 2046 |
7336 | 2047 if (cf) |
3203 | 2048 { |
7336 | 2049 octave_base_value *tmp = cf (*v.rep); |
3203 | 2050 |
7336 | 2051 if (tmp) |
2052 { | |
2053 tv = octave_value (tmp); | |
2054 t = tv.type_id (); | |
2055 | |
2056 f = octave_value_typeinfo::lookup_unary_op (op, t); | |
3203 | 2057 |
7336 | 2058 if (f) |
7487
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2059 { |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2060 try |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2061 { |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2062 retval = f (*tv.rep); |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2063 } |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2064 catch (octave_execution_exception) |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2065 { |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2066 octave_exception_state = octave_no_exception; |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2067 error ("caught execution error in library function"); |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2068 } |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2069 } |
7336 | 2070 else |
2071 gripe_unary_op (octave_value::unary_op_as_string (op), | |
2072 v.type_name ()); | |
2073 } | |
3203 | 2074 else |
7336 | 2075 gripe_unary_op_conv (octave_value::unary_op_as_string (op)); |
3203 | 2076 } |
2077 else | |
7336 | 2078 gripe_unary_op (octave_value::unary_op_as_string (op), |
2079 v.type_name ()); | |
3203 | 2080 } |
2081 } | |
2082 | |
2083 return retval; | |
2084 } | |
2085 | |
2086 static void | |
3933 | 2087 gripe_unary_op_conversion_failed (const std::string& op, |
2088 const std::string& tn) | |
3203 | 2089 { |
2090 error ("operator %s: type conversion for `%s' failed", | |
2091 op.c_str (), tn.c_str ()); | |
2092 } | |
2093 | |
3933 | 2094 const octave_value& |
2095 octave_value::do_non_const_unary_op (unary_op op) | |
3203 | 2096 { |
2097 octave_value retval; | |
2098 | |
2099 int t = type_id (); | |
2100 | |
5759 | 2101 octave_value_typeinfo::non_const_unary_op_fcn f |
3203 | 2102 = octave_value_typeinfo::lookup_non_const_unary_op (op, t); |
2103 | |
2104 if (f) | |
2105 { | |
2106 make_unique (); | |
2107 | |
7487
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2108 try |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2109 { |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2110 f (*rep); |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2111 } |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2112 catch (octave_execution_exception) |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2113 { |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2114 octave_exception_state = octave_no_exception; |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2115 error ("caught execution error in library function"); |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2116 } |
3203 | 2117 } |
2118 else | |
2119 { | |
5759 | 2120 octave_base_value::type_conv_fcn cf = numeric_conversion_function (); |
3203 | 2121 |
2122 if (cf) | |
2123 { | |
5759 | 2124 octave_base_value *tmp = cf (*rep); |
3203 | 2125 |
2126 if (tmp) | |
2127 { | |
5759 | 2128 octave_base_value *old_rep = rep; |
3203 | 2129 rep = tmp; |
2130 | |
2131 t = type_id (); | |
2132 | |
2133 f = octave_value_typeinfo::lookup_non_const_unary_op (op, t); | |
2134 | |
2135 if (f) | |
2136 { | |
7487
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2137 try |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2138 { |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2139 f (*rep); |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2140 } |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2141 catch (octave_execution_exception) |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2142 { |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2143 octave_exception_state = octave_no_exception; |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2144 error ("caught execution error in library function"); |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2145 } |
3203 | 2146 |
2147 if (old_rep && --old_rep->count == 0) | |
2148 delete old_rep; | |
2149 } | |
2150 else | |
2151 { | |
2152 if (old_rep) | |
2153 { | |
2154 if (--rep->count == 0) | |
2155 delete rep; | |
2156 | |
2157 rep = old_rep; | |
2158 } | |
2159 | |
2160 gripe_unary_op (octave_value::unary_op_as_string (op), | |
2161 type_name ()); | |
2162 } | |
2163 } | |
2164 else | |
2165 gripe_unary_op_conversion_failed | |
2166 (octave_value::unary_op_as_string (op), type_name ()); | |
2167 } | |
2168 else | |
2169 gripe_unary_op (octave_value::unary_op_as_string (op), type_name ()); | |
2170 } | |
3933 | 2171 |
2172 return *this; | |
3203 | 2173 } |
2174 | |
3933 | 2175 #if 0 |
3205 | 2176 static void |
3933 | 2177 gripe_unary_op_failed_or_no_method (const std::string& on, |
2178 const std::string& tn) | |
3205 | 2179 { |
2180 error ("operator %s: no method, or unable to evaluate for %s operand", | |
2181 on.c_str (), tn.c_str ()); | |
2182 } | |
3933 | 2183 #endif |
3205 | 2184 |
2185 void | |
4661 | 2186 octave_value::do_non_const_unary_op (unary_op, const octave_value_list&) |
3205 | 2187 { |
3933 | 2188 abort (); |
2189 } | |
2190 | |
2191 octave_value | |
4247 | 2192 octave_value::do_non_const_unary_op (unary_op op, const std::string& type, |
4219 | 2193 const std::list<octave_value_list>& idx) |
3933 | 2194 { |
2195 octave_value retval; | |
2196 | |
2197 if (idx.empty ()) | |
2198 { | |
2199 do_non_const_unary_op (op); | |
3205 | 2200 |
3933 | 2201 retval = *this; |
2202 } | |
2203 else | |
2204 { | |
5775 | 2205 // FIXME -- only do the following stuff if we can't find a |
3933 | 2206 // specific function to call to handle the op= operation for the |
2207 // types we have. | |
3205 | 2208 |
3933 | 2209 assign_op assop = unary_op_to_assign_op (op); |
2210 | |
2211 retval = assign (assop, type, idx, 1.0); | |
2212 } | |
2213 | |
2214 return retval; | |
3205 | 2215 } |
2216 | |
2217 octave_value::assign_op | |
2218 octave_value::unary_op_to_assign_op (unary_op op) | |
2219 { | |
2220 assign_op binop = unknown_assign_op; | |
2221 | |
2222 switch (op) | |
2223 { | |
3533 | 2224 case op_incr: |
2225 binop = op_add_eq; | |
3205 | 2226 break; |
2227 | |
3533 | 2228 case op_decr: |
2229 binop = op_sub_eq; | |
3205 | 2230 break; |
2231 | |
2232 default: | |
2233 { | |
3523 | 2234 std::string on = unary_op_as_string (op); |
3205 | 2235 error ("operator %s: no assign operator found", on.c_str ()); |
2236 } | |
2237 } | |
2238 | |
2239 return binop; | |
2240 } | |
2241 | |
3204 | 2242 octave_value::binary_op |
2243 octave_value::op_eq_to_binary_op (assign_op op) | |
2244 { | |
2245 binary_op binop = unknown_binary_op; | |
2246 | |
2247 switch (op) | |
2248 { | |
3533 | 2249 case op_add_eq: |
2250 binop = op_add; | |
3204 | 2251 break; |
2252 | |
3533 | 2253 case op_sub_eq: |
2254 binop = op_sub; | |
3204 | 2255 break; |
2256 | |
3533 | 2257 case op_mul_eq: |
2258 binop = op_mul; | |
3204 | 2259 break; |
2260 | |
3533 | 2261 case op_div_eq: |
2262 binop = op_div; | |
3204 | 2263 break; |
2264 | |
3533 | 2265 case op_ldiv_eq: |
2266 binop = op_ldiv; | |
3204 | 2267 break; |
2268 | |
4018 | 2269 case op_pow_eq: |
2270 binop = op_pow; | |
2271 break; | |
2272 | |
3533 | 2273 case op_lshift_eq: |
2274 binop = op_lshift; | |
3204 | 2275 break; |
2276 | |
3533 | 2277 case op_rshift_eq: |
2278 binop = op_rshift; | |
3204 | 2279 break; |
2280 | |
3533 | 2281 case op_el_mul_eq: |
2282 binop = op_el_mul; | |
3204 | 2283 break; |
2284 | |
3533 | 2285 case op_el_div_eq: |
2286 binop = op_el_div; | |
3204 | 2287 break; |
2288 | |
3533 | 2289 case op_el_ldiv_eq: |
2290 binop = op_el_ldiv; | |
3204 | 2291 break; |
2292 | |
4018 | 2293 case op_el_pow_eq: |
2294 binop = op_el_pow; | |
2295 break; | |
2296 | |
3533 | 2297 case op_el_and_eq: |
2298 binop = op_el_and; | |
3204 | 2299 break; |
2300 | |
3533 | 2301 case op_el_or_eq: |
2302 binop = op_el_or; | |
3204 | 2303 break; |
2304 | |
2305 default: | |
2306 { | |
3523 | 2307 std::string on = assign_op_as_string (op); |
3204 | 2308 error ("operator %s: no binary operator found", on.c_str ()); |
2309 } | |
2310 } | |
2311 | |
2312 return binop; | |
2313 } | |
2314 | |
3933 | 2315 octave_value |
2316 octave_value::empty_conv (const std::string& type, const octave_value& rhs) | |
2317 { | |
2318 octave_value retval; | |
2319 | |
2320 if (type.length () > 0) | |
2321 { | |
2322 switch (type[0]) | |
2323 { | |
2324 case '(': | |
2325 { | |
2326 if (type.length () > 1 && type[1] == '.') | |
2327 retval = Octave_map (); | |
2328 else | |
2329 retval = octave_value (rhs.empty_clone ()); | |
2330 } | |
2331 break; | |
2332 | |
2333 case '{': | |
2334 retval = Cell (); | |
2335 break; | |
2336 | |
2337 case '.': | |
2338 retval = Octave_map (); | |
2339 break; | |
2340 | |
2341 default: | |
2342 panic_impossible (); | |
2343 } | |
2344 } | |
2345 else | |
2346 retval = octave_value (rhs.empty_clone ()); | |
2347 | |
2348 return retval; | |
2349 } | |
2350 | |
2376 | 2351 void |
2352 install_types (void) | |
2353 { | |
2354 octave_base_value::register_type (); | |
3928 | 2355 octave_cell::register_type (); |
2376 | 2356 octave_scalar::register_type (); |
2357 octave_complex::register_type (); | |
2358 octave_matrix::register_type (); | |
2359 octave_complex_matrix::register_type (); | |
2360 octave_range::register_type (); | |
2825 | 2361 octave_bool::register_type (); |
2362 octave_bool_matrix::register_type (); | |
2376 | 2363 octave_char_matrix::register_type (); |
2364 octave_char_matrix_str::register_type (); | |
5279 | 2365 octave_char_matrix_sq_str::register_type (); |
4901 | 2366 octave_int8_scalar::register_type (); |
2367 octave_int16_scalar::register_type (); | |
2368 octave_int32_scalar::register_type (); | |
2369 octave_int64_scalar::register_type (); | |
2370 octave_uint8_scalar::register_type (); | |
2371 octave_uint16_scalar::register_type (); | |
2372 octave_uint32_scalar::register_type (); | |
2373 octave_uint64_scalar::register_type (); | |
2374 octave_int8_matrix::register_type (); | |
2375 octave_int16_matrix::register_type (); | |
2376 octave_int32_matrix::register_type (); | |
2377 octave_int64_matrix::register_type (); | |
2378 octave_uint8_matrix::register_type (); | |
2379 octave_uint16_matrix::register_type (); | |
2380 octave_uint32_matrix::register_type (); | |
2381 octave_uint64_matrix::register_type (); | |
5164 | 2382 octave_sparse_bool_matrix::register_type (); |
2383 octave_sparse_matrix::register_type (); | |
2384 octave_sparse_complex_matrix::register_type (); | |
2376 | 2385 octave_struct::register_type (); |
7336 | 2386 octave_class::register_type (); |
2880 | 2387 octave_list::register_type (); |
3977 | 2388 octave_cs_list::register_type (); |
2376 | 2389 octave_magic_colon::register_type (); |
2974 | 2390 octave_builtin::register_type (); |
2391 octave_user_function::register_type (); | |
4649 | 2392 octave_dld_function::register_type (); |
4643 | 2393 octave_fcn_handle::register_type (); |
4966 | 2394 octave_fcn_inline::register_type (); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
2395 octave_float_scalar::register_type (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
2396 octave_float_complex::register_type (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
2397 octave_float_matrix::register_type (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
2398 octave_float_complex_matrix::register_type (); |
2376 | 2399 } |
2400 | |
4970 | 2401 #if 0 |
2402 DEFUN (cast, args, , | |
2403 "-*- texinfo -*-\n\ | |
2404 @deftypefn {Built-in Function} {} cast (@var{val}, @var{type})\n\ | |
2405 Convert @var{val} to the new data type @var{type}.\n\ | |
5642 | 2406 @seealso{class, typeinfo}\n\ |
2407 @end deftypefn") | |
4970 | 2408 { |
2409 octave_value retval; | |
2410 | |
2411 if (args.length () == 2) | |
2412 error ("cast: not implemented"); | |
2413 else | |
5823 | 2414 print_usage (); |
4970 | 2415 |
2416 return retval; | |
2417 } | |
2418 #endif | |
2419 | |
4791 | 2420 DEFUN (sizeof, args, , |
2421 "-*- texinfo -*-\n\ | |
2422 @deftypefn {Built-in Function} {} sizeof (@var{val})\n\ | |
2423 Return the size of @var{val} in bytes\n\ | |
2424 @end deftypefn") | |
2425 { | |
2426 octave_value retval; | |
2427 | |
2428 if (args.length () == 1) | |
2429 retval = args(0).byte_size (); | |
2430 else | |
5823 | 2431 print_usage (); |
4791 | 2432 |
2433 return retval; | |
2434 } | |
2435 | |
6153 | 2436 static void |
2437 decode_subscripts (const char* name, const octave_value& arg, | |
2438 std::string& type_string, | |
2439 std::list<octave_value_list>& idx) | |
2440 { | |
2441 Octave_map m = arg.map_value (); | |
2442 | |
2443 if (! error_state | |
6639 | 2444 && m.nfields () == 2 && m.contains ("type") && m.contains ("subs")) |
6153 | 2445 { |
2446 Cell& type = m.contents ("type"); | |
2447 Cell& subs = m.contents ("subs"); | |
2448 | |
2449 type_string = std::string (type.length(), '\0'); | |
2450 | |
2451 for (int k = 0; k < type.length (); k++) | |
2452 { | |
2453 std::string item = type(k).string_value (); | |
2454 | |
2455 if (! error_state) | |
2456 { | |
2457 if (item == "{}") | |
2458 type_string[k] = '{'; | |
2459 else if (item == "()") | |
2460 type_string[k] = '('; | |
2461 else if (item == ".") | |
2462 type_string[k] = '.'; | |
2463 else | |
2464 { | |
2465 error("%s: invalid indexing type `%s'", name, item.c_str ()); | |
2466 return; | |
2467 } | |
2468 } | |
2469 else | |
2470 { | |
2471 error ("%s: expecting type(%d) to be a character string", | |
2472 name, k+1); | |
2473 return; | |
2474 } | |
2475 | |
2476 octave_value_list idx_item; | |
2477 | |
2478 if (subs(k).is_string ()) | |
2479 idx_item(0) = subs(k); | |
2480 else if (subs(k).is_cell ()) | |
2481 { | |
2482 Cell subs_cell = subs(k).cell_value (); | |
2483 | |
2484 for (int n = 0; n < subs_cell.length (); n++) | |
2485 { | |
2486 if (subs_cell(n).is_string () | |
2487 && subs_cell(n).string_value () == ":") | |
2488 idx_item(n) = octave_value(octave_value::magic_colon_t); | |
2489 else | |
2490 idx_item(n) = subs_cell(n); | |
2491 } | |
2492 } | |
2493 else | |
2494 { | |
2495 error ("%s: expecting subs(%d) to be a character string or cell array", | |
2496 name, k+1); | |
2497 return; | |
2498 } | |
2499 | |
2500 idx.push_back (idx_item); | |
2501 } | |
2502 } | |
2503 else | |
2504 error ("%s: second argument must be a structure with fields `type' and `subs'", name); | |
2505 } | |
2506 | |
2507 DEFUN (subsref, args, nargout, | |
2508 "-*- texinfo -*-\n\ | |
2509 @deftypefn {Built-in Function} {} subsref (@var{val}, @var{idx})\n\ | |
2510 Perform the subscripted element selection operation according to\n\ | |
2511 the subscript specified by @var{idx}.\n\ | |
2512 \n\ | |
2513 The subscript @var{idx} is expected to be a structure array with\n\ | |
2514 fields @samp{type} and @samp{subs}. Valid values for @samp{type}\n\ | |
6550 | 2515 are @samp{\"()\"}, @samp{\"@{@}\"}, and @samp{\".\"}.\n\ |
6153 | 2516 The @samp{subs} field may be either @samp{\":\"} or a cell array\n\ |
2517 of index values.\n\ | |
6631 | 2518 \n\ |
2519 The following example shows how to extract the two first columns of\n\ | |
2520 a matrix\n\ | |
2521 \n\ | |
2522 @example\n\ | |
2523 val = magic(3)\n\ | |
2524 @result{} val = [ 8 1 6\n\ | |
2525 3 5 7\n\ | |
2526 4 9 2 ]\n\ | |
2527 idx.type = \"()\";\n\ | |
2528 idx.subs = @{\":\", 1:2@};\n\ | |
2529 subsref(val, idx)\n\ | |
2530 @result{} [ 8 1 \n\ | |
2531 3 5 \n\ | |
2532 4 9 ]\n\ | |
2533 @end example\n\ | |
2534 \n\ | |
2535 @noindent\n\ | |
2536 Note that this is the same as writing @code{val(:,1:2)}.\n\ | |
6157 | 2537 @seealso{subsasgn, substruct}\n\ |
6153 | 2538 @end deftypefn") |
2539 { | |
2540 octave_value_list retval; | |
2541 | |
2542 if (args.length () == 2) | |
2543 { | |
2544 std::string type; | |
2545 std::list<octave_value_list> idx; | |
2546 | |
2547 decode_subscripts ("subsref", args(1), type, idx); | |
2548 | |
2549 if (! error_state) | |
2550 retval = args(0).subsref (type, idx, nargout); | |
2551 } | |
2552 else | |
2553 print_usage (); | |
2554 | |
2555 return retval; | |
2556 } | |
2557 | |
2558 DEFUN (subsasgn, args, , | |
2559 "-*- texinfo -*-\n\ | |
2560 @deftypefn {Built-in Function} {} subsasgn (@var{val}, @var{idx}, @var{rhs})\n\ | |
2561 Perform the subscripted assignment operation according to\n\ | |
2562 the subscript specified by @var{idx}.\n\ | |
2563 \n\ | |
2564 The subscript @var{idx} is expected to be a structure array with\n\ | |
2565 fields @samp{type} and @samp{subs}. Valid values for @samp{type}\n\ | |
6248 | 2566 are @samp{\"()\"}, @samp{\"@{@}\"}, and @samp{\".\"}.\n\ |
6153 | 2567 The @samp{subs} field may be either @samp{\":\"} or a cell array\n\ |
2568 of index values.\n\ | |
6631 | 2569 \n\ |
2570 The following example shows how to set the two first columns of a\n\ | |
2571 3-by-3 matrix to zero.\n\ | |
2572 \n\ | |
2573 @example\n\ | |
2574 val = magic(3);\n\ | |
2575 idx.type = \"()\";\n\ | |
2576 idx.subs = @{\":\", 1:2@};\n\ | |
2577 subsasgn (val, idx, 0)\n\ | |
2578 @result{} [ 0 0 6\n\ | |
2579 0 0 7\n\ | |
2580 0 0 2 ]\n\ | |
2581 @end example\n\ | |
2582 \n\ | |
2583 Note that this is the same as writing @code{val(:,1:2) = 0}.\n\ | |
6157 | 2584 @seealso{subsref, substruct}\n\ |
6153 | 2585 @end deftypefn") |
2586 { | |
2587 octave_value retval; | |
2588 | |
2589 if (args.length () == 3) | |
2590 { | |
2591 std::string type; | |
2592 std::list<octave_value_list> idx; | |
2593 | |
2594 decode_subscripts ("subsasgn", args(1), type, idx); | |
2595 | |
2596 if (! error_state) | |
2597 retval = args(0).subsasgn (type, idx, args(2)); | |
2598 } | |
2599 else | |
2600 print_usage (); | |
2601 | |
2602 return retval; | |
2603 } | |
2604 | |
2376 | 2605 /* |
2606 ;;; Local Variables: *** | |
2607 ;;; mode: C++ *** | |
2608 ;;; End: *** | |
2609 */ |