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