Mercurial > octave-nkf
annotate src/ov.cc @ 7892:7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Mon, 26 May 2008 14:01:55 +0200 |
parents | f336dd8e96d0 |
children | 2b8952e133c9 |
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 | |
4044 | 1349 Array<int> |
1350 octave_value::int_vector_value (bool force_string_conv, bool require_int, | |
1351 bool force_vector_conversion) const | |
1352 { | |
1353 Array<int> retval; | |
1354 | |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1355 if (is_integer_type ()) |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1356 { |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1357 // query for the first type that is wide enough |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1358 #if SIZEOF_INT == 2 |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1359 retval = int16_array_value (); |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1360 #elif SIZEOF_INT == 4 |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1361 retval = int32_array_value (); |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1362 #else |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1363 retval = int64_array_value (); |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1364 #endif |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1365 } |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1366 else |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1367 { |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1368 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
|
1369 if (! error_state) |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1370 { |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1371 if (require_int) |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1372 { |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1373 retval.resize (a.dims ()); |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1374 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
|
1375 { |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1376 double ai = a.elem (i); |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1377 int v = static_cast<int> (ai); |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1378 if (ai == v) |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1379 retval.xelem (i) = v; |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1380 else |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1381 { |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1382 error ("conversion to integer value failed"); |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1383 break; |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1384 } |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1385 } |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1386 } |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1387 else |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1388 retval = Array<int> (a); |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1389 } |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1390 } |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1391 |
4044 | 1392 |
1393 if (error_state) | |
1394 return retval; | |
1395 else | |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1396 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
|
1397 force_vector_conversion, |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1398 type_name (), "integer vector")); |
4044 | 1399 } |
1400 | |
3419 | 1401 Array<Complex> |
2376 | 1402 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
|
1403 bool force_vector_conversion) const |
2376 | 1404 { |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1405 Array<Complex> retval = complex_array_value (force_string_conv); |
2376 | 1406 |
1407 if (error_state) | |
1408 return retval; | |
1409 else | |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1410 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
|
1411 force_vector_conversion, |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1412 type_name (), "complex vector")); |
2376 | 1413 } |
1414 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1415 FloatColumnVector |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1416 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
|
1417 bool frc_vec_conv) const |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1418 { |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1419 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
|
1420 frc_vec_conv)); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1421 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1422 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1423 FloatComplexColumnVector |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1424 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
|
1425 bool frc_vec_conv) const |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1426 { |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1427 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
|
1428 frc_vec_conv)); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1429 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1430 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1431 FloatRowVector |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1432 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
|
1433 bool frc_vec_conv) const |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1434 { |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1435 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
|
1436 frc_vec_conv)); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1437 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1438 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1439 FloatComplexRowVector |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1440 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
|
1441 bool frc_vec_conv) const |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1442 { |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1443 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
|
1444 frc_vec_conv)); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1445 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1446 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1447 Array<float> |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1448 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
|
1449 bool force_vector_conversion) const |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1450 { |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1451 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
|
1452 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1453 if (error_state) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1454 return retval; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1455 else |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1456 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
|
1457 force_vector_conversion, |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1458 type_name (), "real vector")); |
7789
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 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1461 Array<FloatComplex> |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1462 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
|
1463 bool force_vector_conversion) const |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1464 { |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1465 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
|
1466 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1467 if (error_state) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1468 return retval; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1469 else |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1470 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
|
1471 force_vector_conversion, |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1472 type_name (), "complex vector")); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1473 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1474 |
4944 | 1475 int |
1476 octave_value::write (octave_stream& os, int block_size, | |
1477 oct_data_conv::data_type output_type, int skip, | |
1478 oct_mach_info::float_format flt_fmt) const | |
1479 { | |
1480 return rep->write (os, block_size, output_type, skip, flt_fmt); | |
1481 } | |
1482 | |
2413 | 1483 static void |
3933 | 1484 gripe_binary_op (const std::string& on, const std::string& tn1, |
1485 const std::string& tn2) | |
2376 | 1486 { |
2903 | 1487 error ("binary operator `%s' not implemented for `%s' by `%s' operations", |
2376 | 1488 on.c_str (), tn1.c_str (), tn2.c_str ()); |
1489 } | |
1490 | |
3203 | 1491 static void |
3523 | 1492 gripe_binary_op_conv (const std::string& on) |
3203 | 1493 { |
1494 error ("type conversion failed for binary operator `%s'", on.c_str ()); | |
1495 } | |
1496 | |
2376 | 1497 octave_value |
3933 | 1498 do_binary_op (octave_value::binary_op op, |
1499 const octave_value& v1, const octave_value& v2) | |
2376 | 1500 { |
1501 octave_value retval; | |
1502 | |
1503 int t1 = v1.type_id (); | |
1504 int t2 = v2.type_id (); | |
1505 | |
7336 | 1506 if (t1 == octave_class::static_type_id () |
1507 || t2 == octave_class::static_type_id ()) | |
1508 { | |
1509 octave_value_typeinfo::binary_class_op_fcn f | |
1510 = octave_value_typeinfo::lookup_binary_class_op (op); | |
2376 | 1511 |
7336 | 1512 if (f) |
7487
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1513 { |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1514 try |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1515 { |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1516 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
|
1517 } |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1518 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
|
1519 { |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1520 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
|
1521 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
|
1522 } |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1523 } |
7336 | 1524 else |
1525 gripe_binary_op (octave_value::binary_op_as_string (op), | |
1526 v1.class_name (), v2.class_name ()); | |
1527 } | |
2376 | 1528 else |
1529 { | |
7336 | 1530 // FIXME -- we need to handle overloading operators for built-in |
1531 // classes (double, char, int8, etc.) | |
2376 | 1532 |
7336 | 1533 octave_value_typeinfo::binary_op_fcn f |
1534 = octave_value_typeinfo::lookup_binary_op (op, t1, t2); | |
1535 | |
1536 if (f) | |
7487
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1537 { |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1538 try |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1539 { |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1540 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
|
1541 } |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1542 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
|
1543 { |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1544 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
|
1545 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
|
1546 } |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1547 } |
7336 | 1548 else |
2376 | 1549 { |
7336 | 1550 octave_value tv1; |
1551 octave_base_value::type_conv_fcn cf1 = v1.numeric_conversion_function (); | |
1552 | |
1553 if (cf1) | |
1554 { | |
1555 octave_base_value *tmp = cf1 (*v1.rep); | |
3203 | 1556 |
7336 | 1557 if (tmp) |
1558 { | |
1559 tv1 = octave_value (tmp); | |
1560 t1 = tv1.type_id (); | |
1561 } | |
1562 else | |
1563 { | |
1564 gripe_binary_op_conv (octave_value::binary_op_as_string (op)); | |
1565 return retval; | |
1566 } | |
3203 | 1567 } |
1568 else | |
7336 | 1569 tv1 = v1; |
1570 | |
1571 octave_value tv2; | |
1572 octave_base_value::type_conv_fcn cf2 = v2.numeric_conversion_function (); | |
1573 | |
1574 if (cf2) | |
3203 | 1575 { |
7336 | 1576 octave_base_value *tmp = cf2 (*v2.rep); |
2376 | 1577 |
7336 | 1578 if (tmp) |
1579 { | |
1580 tv2 = octave_value (tmp); | |
1581 t2 = tv2.type_id (); | |
1582 } | |
1583 else | |
1584 { | |
1585 gripe_binary_op_conv (octave_value::binary_op_as_string (op)); | |
1586 return retval; | |
1587 } | |
3203 | 1588 } |
1589 else | |
7336 | 1590 tv2 = v2; |
1591 | |
1592 if (cf1 || cf2) | |
3203 | 1593 { |
7336 | 1594 f = octave_value_typeinfo::lookup_binary_op (op, t1, t2); |
1595 | |
1596 if (f) | |
7487
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1597 { |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1598 try |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1599 { |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1600 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
|
1601 } |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1602 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
|
1603 { |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1604 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
|
1605 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
|
1606 } |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1607 } |
7336 | 1608 else |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1609 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1610 //demote double -> single and try again |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1611 cf1 = tv1.numeric_demotion_function (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1612 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1613 if (cf1) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1614 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1615 octave_base_value *tmp = cf1 (*tv1.rep); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1616 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1617 if (tmp) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1618 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1619 tv1 = octave_value (tmp); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1620 t1 = tv1.type_id (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1621 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1622 else |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1623 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1624 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
|
1625 return retval; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1626 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1627 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1628 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1629 cf2 = tv2.numeric_demotion_function (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1630 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1631 if (cf2) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1632 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1633 octave_base_value *tmp = cf2 (*tv2.rep); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1634 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1635 if (tmp) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1636 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1637 tv2 = octave_value (tmp); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1638 t2 = tv2.type_id (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1639 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1640 else |
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 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
|
1643 return retval; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1644 } |
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 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1647 if (cf1 || cf2) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1648 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1649 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
|
1650 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1651 if (f) |
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 try |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1654 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1655 retval = f (*tv1.rep, *tv2.rep); |
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 catch (octave_execution_exception) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1658 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1659 octave_exception_state = octave_no_exception; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1660 error ("caught execution error in library function"); |
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 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1663 else |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1664 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
|
1665 v1.type_name (), v2.type_name ()); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1666 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1667 else |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1668 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
|
1669 v1.type_name (), v2.type_name ()); |
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 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1672 else |
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 //demote double -> single and try again |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1675 cf1 = tv1.numeric_demotion_function (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1676 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1677 if (cf1) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1678 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1679 octave_base_value *tmp = cf1 (*tv1.rep); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1680 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1681 if (tmp) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1682 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1683 tv1 = octave_value (tmp); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1684 t1 = tv1.type_id (); |
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 else |
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 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
|
1689 return retval; |
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 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1693 cf2 = tv2.numeric_demotion_function (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1694 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1695 if (cf2) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1696 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1697 octave_base_value *tmp = cf2 (*tv2.rep); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1698 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1699 if (tmp) |
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 tv2 = octave_value (tmp); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1702 t2 = tv2.type_id (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1703 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1704 else |
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 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
|
1707 return retval; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1708 } |
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 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1711 if (cf1 || cf2) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1712 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1713 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
|
1714 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1715 if (f) |
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 try |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1718 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1719 retval = f (*tv1.rep, *tv2.rep); |
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 catch (octave_execution_exception) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1722 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1723 octave_exception_state = octave_no_exception; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1724 error ("caught execution error in library function"); |
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 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1727 else |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1728 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
|
1729 v1.type_name (), v2.type_name ()); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1730 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1731 else |
7336 | 1732 gripe_binary_op (octave_value::binary_op_as_string (op), |
1733 v1.type_name (), v2.type_name ()); | |
3203 | 1734 } |
2376 | 1735 } |
1736 } | |
1737 | |
1738 return retval; | |
1739 } | |
1740 | |
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
|
1741 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
|
1742 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
|
1743 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
|
1744 { |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1745 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
|
1746 |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1747 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
|
1748 { |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1749 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
|
1750 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
|
1751 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
|
1752 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
|
1753 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
|
1754 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
|
1755 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
|
1756 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
|
1757 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
|
1758 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
|
1759 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
|
1760 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
|
1761 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
|
1762 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
|
1763 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
|
1764 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
|
1765 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
|
1766 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
|
1767 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
|
1768 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
|
1769 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
|
1770 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
|
1771 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
|
1772 } |
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 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
|
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 |
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 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
|
1778 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
|
1779 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
|
1780 { |
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 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
|
1782 |
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 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
|
1784 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
|
1785 |
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 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
|
1787 || 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
|
1788 { |
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 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
|
1790 = 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
|
1791 |
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 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
|
1793 { |
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 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
|
1795 { |
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 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
|
1797 } |
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 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
|
1799 { |
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 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
|
1801 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
|
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 } |
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 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
|
1805 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
|
1806 } |
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 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
|
1808 { |
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 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
|
1810 = 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
|
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 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
|
1813 { |
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 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
|
1815 { |
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 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
|
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 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
|
1819 { |
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 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
|
1821 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
|
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 } |
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 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
|
1825 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
|
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 |
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 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
|
1829 } |
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 |
4915 | 1831 static void |
1832 gripe_cat_op (const std::string& tn1, const std::string& tn2) | |
1833 { | |
1834 error ("concatenation operator not implemented for `%s' by `%s' operations", | |
1835 tn1.c_str (), tn2.c_str ()); | |
1836 } | |
1837 | |
1838 static void | |
1839 gripe_cat_op_conv (void) | |
1840 { | |
1841 error ("type conversion failed for concatenation operator"); | |
1842 } | |
1843 | |
1844 octave_value | |
1845 do_cat_op (const octave_value& v1, const octave_value& v2, | |
6867 | 1846 const Array<octave_idx_type>& ra_idx) |
4915 | 1847 { |
1848 octave_value retval; | |
1849 | |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7800
diff
changeset
|
1850 // 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
|
1851 // something like cat(1,[],single([]) must return the correct type. |
5164 | 1852 |
4915 | 1853 int t1 = v1.type_id (); |
1854 int t2 = v2.type_id (); | |
1855 | |
5759 | 1856 octave_value_typeinfo::cat_op_fcn f |
1857 = octave_value_typeinfo::lookup_cat_op (t1, t2); | |
4915 | 1858 |
1859 if (f) | |
7487
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1860 { |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1861 try |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1862 { |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1863 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
|
1864 } |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1865 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
|
1866 { |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1867 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
|
1868 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
|
1869 } |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1870 } |
4915 | 1871 else |
1872 { | |
1873 octave_value tv1; | |
5759 | 1874 octave_base_value::type_conv_fcn cf1 = v1.numeric_conversion_function (); |
4915 | 1875 |
1876 if (cf1) | |
1877 { | |
5759 | 1878 octave_base_value *tmp = cf1 (*v1.rep); |
4915 | 1879 |
1880 if (tmp) | |
1881 { | |
1882 tv1 = octave_value (tmp); | |
1883 t1 = tv1.type_id (); | |
1884 } | |
1885 else | |
1886 { | |
1887 gripe_cat_op_conv (); | |
1888 return retval; | |
1889 } | |
1890 } | |
1891 else | |
1892 tv1 = v1; | |
1893 | |
1894 octave_value tv2; | |
5759 | 1895 octave_base_value::type_conv_fcn cf2 = v2.numeric_conversion_function (); |
4915 | 1896 |
1897 if (cf2) | |
1898 { | |
5759 | 1899 octave_base_value *tmp = cf2 (*v2.rep); |
4915 | 1900 |
1901 if (tmp) | |
1902 { | |
1903 tv2 = octave_value (tmp); | |
1904 t2 = tv2.type_id (); | |
1905 } | |
1906 else | |
1907 { | |
1908 gripe_cat_op_conv (); | |
1909 return retval; | |
1910 } | |
1911 } | |
1912 else | |
1913 tv2 = v2; | |
1914 | |
1915 if (cf1 || cf2) | |
1916 { | |
1917 f = octave_value_typeinfo::lookup_cat_op (t1, t2); | |
1918 | |
1919 if (f) | |
7487
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1920 { |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1921 try |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1922 { |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1923 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
|
1924 } |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1925 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
|
1926 { |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1927 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
|
1928 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
|
1929 } |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1930 } |
4915 | 1931 else |
1932 gripe_cat_op (v1.type_name (), v2.type_name ()); | |
1933 } | |
1934 else | |
1935 gripe_cat_op (v1.type_name (), v2.type_name ()); | |
1936 } | |
1937 | |
1938 return retval; | |
1939 } | |
1940 | |
3933 | 1941 void |
1942 octave_value::print_info (std::ostream& os, const std::string& prefix) const | |
1943 { | |
1944 os << prefix << "type_name: " << type_name () << "\n" | |
1945 << prefix << "count: " << get_count () << "\n" | |
1946 << prefix << "rep info: "; | |
1947 | |
1948 rep->print_info (os, prefix + " "); | |
1949 } | |
1950 | |
3203 | 1951 static void |
3523 | 1952 gripe_unary_op (const std::string& on, const std::string& tn) |
3203 | 1953 { |
1954 error ("unary operator `%s' not implemented for `%s' operands", | |
1955 on.c_str (), tn.c_str ()); | |
1956 } | |
1957 | |
1958 static void | |
3523 | 1959 gripe_unary_op_conv (const std::string& on) |
3203 | 1960 { |
1961 error ("type conversion failed for unary operator `%s'", on.c_str ()); | |
1962 } | |
1963 | |
1964 octave_value | |
1965 do_unary_op (octave_value::unary_op op, const octave_value& v) | |
1966 { | |
1967 octave_value retval; | |
1968 | |
1969 int t = v.type_id (); | |
1970 | |
7336 | 1971 if (t == octave_class::static_type_id ()) |
1972 { | |
1973 octave_value_typeinfo::unary_class_op_fcn f | |
1974 = octave_value_typeinfo::lookup_unary_class_op (op); | |
3203 | 1975 |
7336 | 1976 if (f) |
7487
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1977 { |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1978 try |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1979 { |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1980 retval = f (v); |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1981 } |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1982 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
|
1983 { |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1984 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
|
1985 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
|
1986 } |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1987 } |
7336 | 1988 else |
1989 gripe_unary_op (octave_value::unary_op_as_string (op), | |
1990 v.class_name ()); | |
1991 } | |
3203 | 1992 else |
1993 { | |
7336 | 1994 // FIXME -- we need to handle overloading operators for built-in |
1995 // classes (double, char, int8, etc.) | |
1996 | |
1997 octave_value_typeinfo::unary_op_fcn f | |
1998 = octave_value_typeinfo::lookup_unary_op (op, t); | |
3203 | 1999 |
7336 | 2000 if (f) |
7487
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2001 { |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2002 try |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2003 { |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2004 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
|
2005 } |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2006 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
|
2007 { |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2008 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
|
2009 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
|
2010 } |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2011 } |
7336 | 2012 else |
3203 | 2013 { |
7336 | 2014 octave_value tv; |
2015 octave_base_value::type_conv_fcn cf | |
2016 = v.numeric_conversion_function (); | |
3203 | 2017 |
7336 | 2018 if (cf) |
3203 | 2019 { |
7336 | 2020 octave_base_value *tmp = cf (*v.rep); |
3203 | 2021 |
7336 | 2022 if (tmp) |
2023 { | |
2024 tv = octave_value (tmp); | |
2025 t = tv.type_id (); | |
2026 | |
2027 f = 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 (*tv.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 |
2042 gripe_unary_op (octave_value::unary_op_as_string (op), | |
2043 v.type_name ()); | |
2044 } | |
3203 | 2045 else |
7336 | 2046 gripe_unary_op_conv (octave_value::unary_op_as_string (op)); |
3203 | 2047 } |
2048 else | |
7336 | 2049 gripe_unary_op (octave_value::unary_op_as_string (op), |
2050 v.type_name ()); | |
3203 | 2051 } |
2052 } | |
2053 | |
2054 return retval; | |
2055 } | |
2056 | |
2057 static void | |
3933 | 2058 gripe_unary_op_conversion_failed (const std::string& op, |
2059 const std::string& tn) | |
3203 | 2060 { |
2061 error ("operator %s: type conversion for `%s' failed", | |
2062 op.c_str (), tn.c_str ()); | |
2063 } | |
2064 | |
3933 | 2065 const octave_value& |
2066 octave_value::do_non_const_unary_op (unary_op op) | |
3203 | 2067 { |
2068 octave_value retval; | |
2069 | |
2070 int t = type_id (); | |
2071 | |
5759 | 2072 octave_value_typeinfo::non_const_unary_op_fcn f |
3203 | 2073 = octave_value_typeinfo::lookup_non_const_unary_op (op, t); |
2074 | |
2075 if (f) | |
2076 { | |
2077 make_unique (); | |
2078 | |
7487
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2079 try |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2080 { |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2081 f (*rep); |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2082 } |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2083 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
|
2084 { |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2085 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
|
2086 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
|
2087 } |
3203 | 2088 } |
2089 else | |
2090 { | |
5759 | 2091 octave_base_value::type_conv_fcn cf = numeric_conversion_function (); |
3203 | 2092 |
2093 if (cf) | |
2094 { | |
5759 | 2095 octave_base_value *tmp = cf (*rep); |
3203 | 2096 |
2097 if (tmp) | |
2098 { | |
5759 | 2099 octave_base_value *old_rep = rep; |
3203 | 2100 rep = tmp; |
2101 | |
2102 t = type_id (); | |
2103 | |
2104 f = octave_value_typeinfo::lookup_non_const_unary_op (op, t); | |
2105 | |
2106 if (f) | |
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 if (old_rep && --old_rep->count == 0) | |
2119 delete old_rep; | |
2120 } | |
2121 else | |
2122 { | |
2123 if (old_rep) | |
2124 { | |
2125 if (--rep->count == 0) | |
2126 delete rep; | |
2127 | |
2128 rep = old_rep; | |
2129 } | |
2130 | |
2131 gripe_unary_op (octave_value::unary_op_as_string (op), | |
2132 type_name ()); | |
2133 } | |
2134 } | |
2135 else | |
2136 gripe_unary_op_conversion_failed | |
2137 (octave_value::unary_op_as_string (op), type_name ()); | |
2138 } | |
2139 else | |
2140 gripe_unary_op (octave_value::unary_op_as_string (op), type_name ()); | |
2141 } | |
3933 | 2142 |
2143 return *this; | |
3203 | 2144 } |
2145 | |
3933 | 2146 #if 0 |
3205 | 2147 static void |
3933 | 2148 gripe_unary_op_failed_or_no_method (const std::string& on, |
2149 const std::string& tn) | |
3205 | 2150 { |
2151 error ("operator %s: no method, or unable to evaluate for %s operand", | |
2152 on.c_str (), tn.c_str ()); | |
2153 } | |
3933 | 2154 #endif |
3205 | 2155 |
2156 void | |
4661 | 2157 octave_value::do_non_const_unary_op (unary_op, const octave_value_list&) |
3205 | 2158 { |
3933 | 2159 abort (); |
2160 } | |
2161 | |
2162 octave_value | |
4247 | 2163 octave_value::do_non_const_unary_op (unary_op op, const std::string& type, |
4219 | 2164 const std::list<octave_value_list>& idx) |
3933 | 2165 { |
2166 octave_value retval; | |
2167 | |
2168 if (idx.empty ()) | |
2169 { | |
2170 do_non_const_unary_op (op); | |
3205 | 2171 |
3933 | 2172 retval = *this; |
2173 } | |
2174 else | |
2175 { | |
5775 | 2176 // FIXME -- only do the following stuff if we can't find a |
3933 | 2177 // specific function to call to handle the op= operation for the |
2178 // types we have. | |
3205 | 2179 |
3933 | 2180 assign_op assop = unary_op_to_assign_op (op); |
2181 | |
2182 retval = assign (assop, type, idx, 1.0); | |
2183 } | |
2184 | |
2185 return retval; | |
3205 | 2186 } |
2187 | |
2188 octave_value::assign_op | |
2189 octave_value::unary_op_to_assign_op (unary_op op) | |
2190 { | |
2191 assign_op binop = unknown_assign_op; | |
2192 | |
2193 switch (op) | |
2194 { | |
3533 | 2195 case op_incr: |
2196 binop = op_add_eq; | |
3205 | 2197 break; |
2198 | |
3533 | 2199 case op_decr: |
2200 binop = op_sub_eq; | |
3205 | 2201 break; |
2202 | |
2203 default: | |
2204 { | |
3523 | 2205 std::string on = unary_op_as_string (op); |
3205 | 2206 error ("operator %s: no assign operator found", on.c_str ()); |
2207 } | |
2208 } | |
2209 | |
2210 return binop; | |
2211 } | |
2212 | |
3204 | 2213 octave_value::binary_op |
2214 octave_value::op_eq_to_binary_op (assign_op op) | |
2215 { | |
2216 binary_op binop = unknown_binary_op; | |
2217 | |
2218 switch (op) | |
2219 { | |
3533 | 2220 case op_add_eq: |
2221 binop = op_add; | |
3204 | 2222 break; |
2223 | |
3533 | 2224 case op_sub_eq: |
2225 binop = op_sub; | |
3204 | 2226 break; |
2227 | |
3533 | 2228 case op_mul_eq: |
2229 binop = op_mul; | |
3204 | 2230 break; |
2231 | |
3533 | 2232 case op_div_eq: |
2233 binop = op_div; | |
3204 | 2234 break; |
2235 | |
3533 | 2236 case op_ldiv_eq: |
2237 binop = op_ldiv; | |
3204 | 2238 break; |
2239 | |
4018 | 2240 case op_pow_eq: |
2241 binop = op_pow; | |
2242 break; | |
2243 | |
3533 | 2244 case op_lshift_eq: |
2245 binop = op_lshift; | |
3204 | 2246 break; |
2247 | |
3533 | 2248 case op_rshift_eq: |
2249 binop = op_rshift; | |
3204 | 2250 break; |
2251 | |
3533 | 2252 case op_el_mul_eq: |
2253 binop = op_el_mul; | |
3204 | 2254 break; |
2255 | |
3533 | 2256 case op_el_div_eq: |
2257 binop = op_el_div; | |
3204 | 2258 break; |
2259 | |
3533 | 2260 case op_el_ldiv_eq: |
2261 binop = op_el_ldiv; | |
3204 | 2262 break; |
2263 | |
4018 | 2264 case op_el_pow_eq: |
2265 binop = op_el_pow; | |
2266 break; | |
2267 | |
3533 | 2268 case op_el_and_eq: |
2269 binop = op_el_and; | |
3204 | 2270 break; |
2271 | |
3533 | 2272 case op_el_or_eq: |
2273 binop = op_el_or; | |
3204 | 2274 break; |
2275 | |
2276 default: | |
2277 { | |
3523 | 2278 std::string on = assign_op_as_string (op); |
3204 | 2279 error ("operator %s: no binary operator found", on.c_str ()); |
2280 } | |
2281 } | |
2282 | |
2283 return binop; | |
2284 } | |
2285 | |
3933 | 2286 octave_value |
2287 octave_value::empty_conv (const std::string& type, const octave_value& rhs) | |
2288 { | |
2289 octave_value retval; | |
2290 | |
2291 if (type.length () > 0) | |
2292 { | |
2293 switch (type[0]) | |
2294 { | |
2295 case '(': | |
2296 { | |
2297 if (type.length () > 1 && type[1] == '.') | |
2298 retval = Octave_map (); | |
2299 else | |
2300 retval = octave_value (rhs.empty_clone ()); | |
2301 } | |
2302 break; | |
2303 | |
2304 case '{': | |
2305 retval = Cell (); | |
2306 break; | |
2307 | |
2308 case '.': | |
2309 retval = Octave_map (); | |
2310 break; | |
2311 | |
2312 default: | |
2313 panic_impossible (); | |
2314 } | |
2315 } | |
2316 else | |
2317 retval = octave_value (rhs.empty_clone ()); | |
2318 | |
2319 return retval; | |
2320 } | |
2321 | |
2376 | 2322 void |
2323 install_types (void) | |
2324 { | |
2325 octave_base_value::register_type (); | |
3928 | 2326 octave_cell::register_type (); |
2376 | 2327 octave_scalar::register_type (); |
2328 octave_complex::register_type (); | |
2329 octave_matrix::register_type (); | |
2330 octave_complex_matrix::register_type (); | |
2331 octave_range::register_type (); | |
2825 | 2332 octave_bool::register_type (); |
2333 octave_bool_matrix::register_type (); | |
2376 | 2334 octave_char_matrix::register_type (); |
2335 octave_char_matrix_str::register_type (); | |
5279 | 2336 octave_char_matrix_sq_str::register_type (); |
4901 | 2337 octave_int8_scalar::register_type (); |
2338 octave_int16_scalar::register_type (); | |
2339 octave_int32_scalar::register_type (); | |
2340 octave_int64_scalar::register_type (); | |
2341 octave_uint8_scalar::register_type (); | |
2342 octave_uint16_scalar::register_type (); | |
2343 octave_uint32_scalar::register_type (); | |
2344 octave_uint64_scalar::register_type (); | |
2345 octave_int8_matrix::register_type (); | |
2346 octave_int16_matrix::register_type (); | |
2347 octave_int32_matrix::register_type (); | |
2348 octave_int64_matrix::register_type (); | |
2349 octave_uint8_matrix::register_type (); | |
2350 octave_uint16_matrix::register_type (); | |
2351 octave_uint32_matrix::register_type (); | |
2352 octave_uint64_matrix::register_type (); | |
5164 | 2353 octave_sparse_bool_matrix::register_type (); |
2354 octave_sparse_matrix::register_type (); | |
2355 octave_sparse_complex_matrix::register_type (); | |
2376 | 2356 octave_struct::register_type (); |
7336 | 2357 octave_class::register_type (); |
2880 | 2358 octave_list::register_type (); |
3977 | 2359 octave_cs_list::register_type (); |
2376 | 2360 octave_magic_colon::register_type (); |
2974 | 2361 octave_builtin::register_type (); |
2362 octave_user_function::register_type (); | |
4649 | 2363 octave_dld_function::register_type (); |
4643 | 2364 octave_fcn_handle::register_type (); |
4966 | 2365 octave_fcn_inline::register_type (); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
2366 octave_float_scalar::register_type (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
2367 octave_float_complex::register_type (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
2368 octave_float_matrix::register_type (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
2369 octave_float_complex_matrix::register_type (); |
2376 | 2370 } |
2371 | |
4970 | 2372 #if 0 |
2373 DEFUN (cast, args, , | |
2374 "-*- texinfo -*-\n\ | |
2375 @deftypefn {Built-in Function} {} cast (@var{val}, @var{type})\n\ | |
2376 Convert @var{val} to the new data type @var{type}.\n\ | |
5642 | 2377 @seealso{class, typeinfo}\n\ |
2378 @end deftypefn") | |
4970 | 2379 { |
2380 octave_value retval; | |
2381 | |
2382 if (args.length () == 2) | |
2383 error ("cast: not implemented"); | |
2384 else | |
5823 | 2385 print_usage (); |
4970 | 2386 |
2387 return retval; | |
2388 } | |
2389 #endif | |
2390 | |
4791 | 2391 DEFUN (sizeof, args, , |
2392 "-*- texinfo -*-\n\ | |
2393 @deftypefn {Built-in Function} {} sizeof (@var{val})\n\ | |
2394 Return the size of @var{val} in bytes\n\ | |
2395 @end deftypefn") | |
2396 { | |
2397 octave_value retval; | |
2398 | |
2399 if (args.length () == 1) | |
2400 retval = args(0).byte_size (); | |
2401 else | |
5823 | 2402 print_usage (); |
4791 | 2403 |
2404 return retval; | |
2405 } | |
2406 | |
6153 | 2407 static void |
2408 decode_subscripts (const char* name, const octave_value& arg, | |
2409 std::string& type_string, | |
2410 std::list<octave_value_list>& idx) | |
2411 { | |
2412 Octave_map m = arg.map_value (); | |
2413 | |
2414 if (! error_state | |
6639 | 2415 && m.nfields () == 2 && m.contains ("type") && m.contains ("subs")) |
6153 | 2416 { |
2417 Cell& type = m.contents ("type"); | |
2418 Cell& subs = m.contents ("subs"); | |
2419 | |
2420 type_string = std::string (type.length(), '\0'); | |
2421 | |
2422 for (int k = 0; k < type.length (); k++) | |
2423 { | |
2424 std::string item = type(k).string_value (); | |
2425 | |
2426 if (! error_state) | |
2427 { | |
2428 if (item == "{}") | |
2429 type_string[k] = '{'; | |
2430 else if (item == "()") | |
2431 type_string[k] = '('; | |
2432 else if (item == ".") | |
2433 type_string[k] = '.'; | |
2434 else | |
2435 { | |
2436 error("%s: invalid indexing type `%s'", name, item.c_str ()); | |
2437 return; | |
2438 } | |
2439 } | |
2440 else | |
2441 { | |
2442 error ("%s: expecting type(%d) to be a character string", | |
2443 name, k+1); | |
2444 return; | |
2445 } | |
2446 | |
2447 octave_value_list idx_item; | |
2448 | |
2449 if (subs(k).is_string ()) | |
2450 idx_item(0) = subs(k); | |
2451 else if (subs(k).is_cell ()) | |
2452 { | |
2453 Cell subs_cell = subs(k).cell_value (); | |
2454 | |
2455 for (int n = 0; n < subs_cell.length (); n++) | |
2456 { | |
2457 if (subs_cell(n).is_string () | |
2458 && subs_cell(n).string_value () == ":") | |
2459 idx_item(n) = octave_value(octave_value::magic_colon_t); | |
2460 else | |
2461 idx_item(n) = subs_cell(n); | |
2462 } | |
2463 } | |
2464 else | |
2465 { | |
2466 error ("%s: expecting subs(%d) to be a character string or cell array", | |
2467 name, k+1); | |
2468 return; | |
2469 } | |
2470 | |
2471 idx.push_back (idx_item); | |
2472 } | |
2473 } | |
2474 else | |
2475 error ("%s: second argument must be a structure with fields `type' and `subs'", name); | |
2476 } | |
2477 | |
2478 DEFUN (subsref, args, nargout, | |
2479 "-*- texinfo -*-\n\ | |
2480 @deftypefn {Built-in Function} {} subsref (@var{val}, @var{idx})\n\ | |
2481 Perform the subscripted element selection operation according to\n\ | |
2482 the subscript specified by @var{idx}.\n\ | |
2483 \n\ | |
2484 The subscript @var{idx} is expected to be a structure array with\n\ | |
2485 fields @samp{type} and @samp{subs}. Valid values for @samp{type}\n\ | |
6550 | 2486 are @samp{\"()\"}, @samp{\"@{@}\"}, and @samp{\".\"}.\n\ |
6153 | 2487 The @samp{subs} field may be either @samp{\":\"} or a cell array\n\ |
2488 of index values.\n\ | |
6631 | 2489 \n\ |
2490 The following example shows how to extract the two first columns of\n\ | |
2491 a matrix\n\ | |
2492 \n\ | |
2493 @example\n\ | |
2494 val = magic(3)\n\ | |
2495 @result{} val = [ 8 1 6\n\ | |
2496 3 5 7\n\ | |
2497 4 9 2 ]\n\ | |
2498 idx.type = \"()\";\n\ | |
2499 idx.subs = @{\":\", 1:2@};\n\ | |
2500 subsref(val, idx)\n\ | |
2501 @result{} [ 8 1 \n\ | |
2502 3 5 \n\ | |
2503 4 9 ]\n\ | |
2504 @end example\n\ | |
2505 \n\ | |
2506 @noindent\n\ | |
2507 Note that this is the same as writing @code{val(:,1:2)}.\n\ | |
6157 | 2508 @seealso{subsasgn, substruct}\n\ |
6153 | 2509 @end deftypefn") |
2510 { | |
2511 octave_value_list retval; | |
2512 | |
2513 if (args.length () == 2) | |
2514 { | |
2515 std::string type; | |
2516 std::list<octave_value_list> idx; | |
2517 | |
2518 decode_subscripts ("subsref", args(1), type, idx); | |
2519 | |
2520 if (! error_state) | |
2521 retval = args(0).subsref (type, idx, nargout); | |
2522 } | |
2523 else | |
2524 print_usage (); | |
2525 | |
2526 return retval; | |
2527 } | |
2528 | |
2529 DEFUN (subsasgn, args, , | |
2530 "-*- texinfo -*-\n\ | |
2531 @deftypefn {Built-in Function} {} subsasgn (@var{val}, @var{idx}, @var{rhs})\n\ | |
2532 Perform the subscripted assignment operation according to\n\ | |
2533 the subscript specified by @var{idx}.\n\ | |
2534 \n\ | |
2535 The subscript @var{idx} is expected to be a structure array with\n\ | |
2536 fields @samp{type} and @samp{subs}. Valid values for @samp{type}\n\ | |
6248 | 2537 are @samp{\"()\"}, @samp{\"@{@}\"}, and @samp{\".\"}.\n\ |
6153 | 2538 The @samp{subs} field may be either @samp{\":\"} or a cell array\n\ |
2539 of index values.\n\ | |
6631 | 2540 \n\ |
2541 The following example shows how to set the two first columns of a\n\ | |
2542 3-by-3 matrix to zero.\n\ | |
2543 \n\ | |
2544 @example\n\ | |
2545 val = magic(3);\n\ | |
2546 idx.type = \"()\";\n\ | |
2547 idx.subs = @{\":\", 1:2@};\n\ | |
2548 subsasgn (val, idx, 0)\n\ | |
2549 @result{} [ 0 0 6\n\ | |
2550 0 0 7\n\ | |
2551 0 0 2 ]\n\ | |
2552 @end example\n\ | |
2553 \n\ | |
2554 Note that this is the same as writing @code{val(:,1:2) = 0}.\n\ | |
6157 | 2555 @seealso{subsref, substruct}\n\ |
6153 | 2556 @end deftypefn") |
2557 { | |
2558 octave_value retval; | |
2559 | |
2560 if (args.length () == 3) | |
2561 { | |
2562 std::string type; | |
2563 std::list<octave_value_list> idx; | |
2564 | |
2565 decode_subscripts ("subsasgn", args(1), type, idx); | |
2566 | |
2567 if (! error_state) | |
2568 retval = args(0).subsasgn (type, idx, args(2)); | |
2569 } | |
2570 else | |
2571 print_usage (); | |
2572 | |
2573 return retval; | |
2574 } | |
2575 | |
2376 | 2576 /* |
2577 ;;; Local Variables: *** | |
2578 ;;; mode: C++ *** | |
2579 ;;; End: *** | |
2580 */ |