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