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