Mercurial > octave
annotate src/ov.cc @ 8345:c777f3ce02d8
smarter conversion lookup
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Tue, 25 Nov 2008 14:04:55 +0100 |
parents | 283989f2da9b |
children | 8302788f09db |
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; |
8345
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1617 octave_base_value::type_conv_info cf1 = v1.numeric_conversion_function (); |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1618 |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1619 octave_value tv2; |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1620 octave_base_value::type_conv_info cf2 = v2.numeric_conversion_function (); |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1621 |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1622 // Try biased (one-sided) conversions first. |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1623 if (cf2.type_id () >= 0 && |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1624 octave_value_typeinfo::lookup_binary_op (op, t1, cf2.type_id ())) |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1625 cf1 = 0; |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1626 else if (cf1.type_id () >= 0 && |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1627 octave_value_typeinfo::lookup_binary_op (op, cf1.type_id (), t2)) |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1628 cf2 = 0; |
7336 | 1629 |
1630 if (cf1) | |
1631 { | |
1632 octave_base_value *tmp = cf1 (*v1.rep); | |
3203 | 1633 |
7336 | 1634 if (tmp) |
1635 { | |
1636 tv1 = octave_value (tmp); | |
1637 t1 = tv1.type_id (); | |
1638 } | |
1639 else | |
1640 { | |
1641 gripe_binary_op_conv (octave_value::binary_op_as_string (op)); | |
1642 return retval; | |
1643 } | |
3203 | 1644 } |
1645 else | |
7336 | 1646 tv1 = v1; |
1647 | |
1648 if (cf2) | |
3203 | 1649 { |
7336 | 1650 octave_base_value *tmp = cf2 (*v2.rep); |
2376 | 1651 |
7336 | 1652 if (tmp) |
1653 { | |
1654 tv2 = octave_value (tmp); | |
1655 t2 = tv2.type_id (); | |
1656 } | |
1657 else | |
1658 { | |
1659 gripe_binary_op_conv (octave_value::binary_op_as_string (op)); | |
1660 return retval; | |
1661 } | |
3203 | 1662 } |
1663 else | |
7336 | 1664 tv2 = v2; |
1665 | |
1666 if (cf1 || cf2) | |
3203 | 1667 { |
8345
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1668 retval = do_binary_op (op, tv1, tv2); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1669 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1670 else |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1671 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1672 //demote double -> single and try again |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1673 cf1 = tv1.numeric_demotion_function (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1674 |
8345
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1675 cf2 = tv2.numeric_demotion_function (); |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1676 |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1677 // Try biased (one-sided) conversions first. |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1678 if (cf2.type_id () >= 0 |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1679 && octave_value_typeinfo::lookup_binary_op (op, t1, cf2.type_id ())) |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1680 cf1 = 0; |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1681 else if (cf1.type_id () >= 0 |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1682 && octave_value_typeinfo::lookup_binary_op (op, cf1.type_id (), t2)) |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1683 cf2 = 0; |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1684 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1685 if (cf1) |
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 octave_base_value *tmp = cf1 (*tv1.rep); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1688 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1689 if (tmp) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1690 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1691 tv1 = octave_value (tmp); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1692 t1 = tv1.type_id (); |
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 else |
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 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
|
1697 return retval; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1698 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1699 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1700 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1701 if (cf2) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1702 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1703 octave_base_value *tmp = cf2 (*tv2.rep); |
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 if (tmp) |
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 tv2 = octave_value (tmp); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1708 t2 = tv2.type_id (); |
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 else |
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 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
|
1713 return retval; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1714 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1715 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1716 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1717 if (cf1 || cf2) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1718 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1719 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
|
1720 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1721 if (f) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1722 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1723 try |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1724 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1725 retval = f (*tv1.rep, *tv2.rep); |
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 catch (octave_execution_exception) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1728 { |
8011
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7999
diff
changeset
|
1729 gripe_library_execution_error (); |
7789
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 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1732 else |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1733 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
|
1734 v1.type_name (), v2.type_name ()); |
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 |
7336 | 1737 gripe_binary_op (octave_value::binary_op_as_string (op), |
1738 v1.type_name (), v2.type_name ()); | |
3203 | 1739 } |
2376 | 1740 } |
1741 } | |
1742 | |
1743 return retval; | |
1744 } | |
1745 | |
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
|
1746 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
|
1747 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
|
1748 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
|
1749 { |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1750 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
|
1751 |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1752 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
|
1753 { |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1754 case octave_value::op_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
|
1755 retval = do_binary_op (octave_value::op_mul, |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1756 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
|
1757 v2); |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1758 break; |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1759 case octave_value::op_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
|
1760 retval = do_binary_op (octave_value::op_mul, |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1761 v1, |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1762 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
|
1763 break; |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1764 case octave_value::op_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
|
1765 retval = do_binary_op (octave_value::op_mul, |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1766 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
|
1767 v2); |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1768 break; |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1769 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
|
1770 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
|
1771 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
|
1772 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
|
1773 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
|
1774 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
|
1775 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
|
1776 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
|
1777 } |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1778 |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1779 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
|
1780 } |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1781 |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1782 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
|
1783 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
|
1784 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
|
1785 { |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1786 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
|
1787 |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1788 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
|
1789 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
|
1790 |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1791 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
|
1792 || 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
|
1793 { |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1794 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
|
1795 = 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
|
1796 |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1797 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
|
1798 { |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1799 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
|
1800 { |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1801 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
|
1802 } |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1803 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
|
1804 { |
8011
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7999
diff
changeset
|
1805 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
|
1806 } |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1807 } |
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 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
|
1809 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
|
1810 } |
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 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
|
1812 { |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1813 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
|
1814 = 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
|
1815 |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1816 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
|
1817 { |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1818 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
|
1819 { |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1820 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
|
1821 } |
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 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
|
1823 { |
8011
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7999
diff
changeset
|
1824 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
|
1825 } |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1826 } |
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 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
|
1828 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
|
1829 } |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1830 |
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 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
|
1832 } |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1833 |
4915 | 1834 static void |
1835 gripe_cat_op (const std::string& tn1, const std::string& tn2) | |
1836 { | |
1837 error ("concatenation operator not implemented for `%s' by `%s' operations", | |
1838 tn1.c_str (), tn2.c_str ()); | |
1839 } | |
1840 | |
1841 static void | |
1842 gripe_cat_op_conv (void) | |
1843 { | |
1844 error ("type conversion failed for concatenation operator"); | |
1845 } | |
1846 | |
1847 octave_value | |
1848 do_cat_op (const octave_value& v1, const octave_value& v2, | |
6867 | 1849 const Array<octave_idx_type>& ra_idx) |
4915 | 1850 { |
1851 octave_value retval; | |
1852 | |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7800
diff
changeset
|
1853 // 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
|
1854 // something like cat(1,[],single([]) must return the correct type. |
5164 | 1855 |
4915 | 1856 int t1 = v1.type_id (); |
1857 int t2 = v2.type_id (); | |
1858 | |
5759 | 1859 octave_value_typeinfo::cat_op_fcn f |
1860 = octave_value_typeinfo::lookup_cat_op (t1, t2); | |
4915 | 1861 |
1862 if (f) | |
7487
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1863 { |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1864 try |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1865 { |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1866 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
|
1867 } |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1868 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
|
1869 { |
8011
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7999
diff
changeset
|
1870 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
|
1871 } |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1872 } |
4915 | 1873 else |
1874 { | |
1875 octave_value tv1; | |
8345
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1876 octave_base_value::type_conv_info cf1 = v1.numeric_conversion_function (); |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1877 |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1878 octave_value tv2; |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1879 octave_base_value::type_conv_info cf2 = v2.numeric_conversion_function (); |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1880 |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1881 // Try biased (one-sided) conversions first. |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1882 if (cf2.type_id () >= 0 |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1883 && octave_value_typeinfo::lookup_cat_op (t1, cf2.type_id ())) |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1884 cf1 = 0; |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1885 else if (cf1.type_id () >= 0 |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1886 && octave_value_typeinfo::lookup_cat_op (cf1.type_id (), t2)) |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1887 cf2 = 0; |
4915 | 1888 |
1889 if (cf1) | |
1890 { | |
5759 | 1891 octave_base_value *tmp = cf1 (*v1.rep); |
4915 | 1892 |
1893 if (tmp) | |
1894 { | |
1895 tv1 = octave_value (tmp); | |
1896 t1 = tv1.type_id (); | |
1897 } | |
1898 else | |
1899 { | |
1900 gripe_cat_op_conv (); | |
1901 return retval; | |
1902 } | |
1903 } | |
1904 else | |
1905 tv1 = v1; | |
1906 | |
1907 if (cf2) | |
1908 { | |
5759 | 1909 octave_base_value *tmp = cf2 (*v2.rep); |
4915 | 1910 |
1911 if (tmp) | |
1912 { | |
1913 tv2 = octave_value (tmp); | |
1914 t2 = tv2.type_id (); | |
1915 } | |
1916 else | |
1917 { | |
1918 gripe_cat_op_conv (); | |
1919 return retval; | |
1920 } | |
1921 } | |
1922 else | |
1923 tv2 = v2; | |
1924 | |
1925 if (cf1 || cf2) | |
1926 { | |
8345
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1927 retval = do_cat_op (tv1, tv2, ra_idx); |
4915 | 1928 } |
1929 else | |
1930 gripe_cat_op (v1.type_name (), v2.type_name ()); | |
1931 } | |
1932 | |
1933 return retval; | |
1934 } | |
1935 | |
3933 | 1936 void |
1937 octave_value::print_info (std::ostream& os, const std::string& prefix) const | |
1938 { | |
1939 os << prefix << "type_name: " << type_name () << "\n" | |
1940 << prefix << "count: " << get_count () << "\n" | |
1941 << prefix << "rep info: "; | |
1942 | |
1943 rep->print_info (os, prefix + " "); | |
1944 } | |
1945 | |
3203 | 1946 static void |
3523 | 1947 gripe_unary_op (const std::string& on, const std::string& tn) |
3203 | 1948 { |
1949 error ("unary operator `%s' not implemented for `%s' operands", | |
1950 on.c_str (), tn.c_str ()); | |
1951 } | |
1952 | |
1953 static void | |
3523 | 1954 gripe_unary_op_conv (const std::string& on) |
3203 | 1955 { |
1956 error ("type conversion failed for unary operator `%s'", on.c_str ()); | |
1957 } | |
1958 | |
1959 octave_value | |
1960 do_unary_op (octave_value::unary_op op, const octave_value& v) | |
1961 { | |
1962 octave_value retval; | |
1963 | |
1964 int t = v.type_id (); | |
1965 | |
7336 | 1966 if (t == octave_class::static_type_id ()) |
1967 { | |
1968 octave_value_typeinfo::unary_class_op_fcn f | |
1969 = octave_value_typeinfo::lookup_unary_class_op (op); | |
3203 | 1970 |
7336 | 1971 if (f) |
7487
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1972 { |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1973 try |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1974 { |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1975 retval = f (v); |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1976 } |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1977 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
|
1978 { |
8011
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7999
diff
changeset
|
1979 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
|
1980 } |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1981 } |
7336 | 1982 else |
1983 gripe_unary_op (octave_value::unary_op_as_string (op), | |
1984 v.class_name ()); | |
1985 } | |
3203 | 1986 else |
1987 { | |
7336 | 1988 // FIXME -- we need to handle overloading operators for built-in |
1989 // classes (double, char, int8, etc.) | |
1990 | |
1991 octave_value_typeinfo::unary_op_fcn f | |
1992 = octave_value_typeinfo::lookup_unary_op (op, t); | |
3203 | 1993 |
7336 | 1994 if (f) |
7487
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1995 { |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1996 try |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1997 { |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1998 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
|
1999 } |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2000 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
|
2001 { |
8011
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7999
diff
changeset
|
2002 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
|
2003 } |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2004 } |
7336 | 2005 else |
3203 | 2006 { |
7336 | 2007 octave_value tv; |
2008 octave_base_value::type_conv_fcn cf | |
2009 = v.numeric_conversion_function (); | |
3203 | 2010 |
7336 | 2011 if (cf) |
3203 | 2012 { |
7336 | 2013 octave_base_value *tmp = cf (*v.rep); |
3203 | 2014 |
7336 | 2015 if (tmp) |
2016 { | |
2017 tv = octave_value (tmp); | |
8345
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
2018 retval = do_unary_op (op, tv); |
7336 | 2019 } |
3203 | 2020 else |
7336 | 2021 gripe_unary_op_conv (octave_value::unary_op_as_string (op)); |
3203 | 2022 } |
2023 else | |
7336 | 2024 gripe_unary_op (octave_value::unary_op_as_string (op), |
2025 v.type_name ()); | |
3203 | 2026 } |
2027 } | |
2028 | |
2029 return retval; | |
2030 } | |
2031 | |
2032 static void | |
3933 | 2033 gripe_unary_op_conversion_failed (const std::string& op, |
2034 const std::string& tn) | |
3203 | 2035 { |
2036 error ("operator %s: type conversion for `%s' failed", | |
2037 op.c_str (), tn.c_str ()); | |
2038 } | |
2039 | |
3933 | 2040 const octave_value& |
2041 octave_value::do_non_const_unary_op (unary_op op) | |
3203 | 2042 { |
2043 octave_value retval; | |
2044 | |
2045 int t = type_id (); | |
2046 | |
5759 | 2047 octave_value_typeinfo::non_const_unary_op_fcn f |
3203 | 2048 = octave_value_typeinfo::lookup_non_const_unary_op (op, t); |
2049 | |
2050 if (f) | |
2051 { | |
2052 make_unique (); | |
2053 | |
7487
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2054 try |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2055 { |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2056 f (*rep); |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2057 } |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2058 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
|
2059 { |
8011
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7999
diff
changeset
|
2060 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
|
2061 } |
3203 | 2062 } |
2063 else | |
2064 { | |
5759 | 2065 octave_base_value::type_conv_fcn cf = numeric_conversion_function (); |
3203 | 2066 |
2067 if (cf) | |
2068 { | |
5759 | 2069 octave_base_value *tmp = cf (*rep); |
3203 | 2070 |
2071 if (tmp) | |
2072 { | |
5759 | 2073 octave_base_value *old_rep = rep; |
3203 | 2074 rep = tmp; |
2075 | |
2076 t = type_id (); | |
2077 | |
2078 f = octave_value_typeinfo::lookup_non_const_unary_op (op, t); | |
2079 | |
2080 if (f) | |
2081 { | |
7487
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2082 try |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2083 { |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2084 f (*rep); |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2085 } |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2086 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
|
2087 { |
8011
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7999
diff
changeset
|
2088 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
|
2089 } |
3203 | 2090 |
2091 if (old_rep && --old_rep->count == 0) | |
2092 delete old_rep; | |
2093 } | |
2094 else | |
2095 { | |
2096 if (old_rep) | |
2097 { | |
2098 if (--rep->count == 0) | |
2099 delete rep; | |
2100 | |
2101 rep = old_rep; | |
2102 } | |
2103 | |
2104 gripe_unary_op (octave_value::unary_op_as_string (op), | |
2105 type_name ()); | |
2106 } | |
2107 } | |
2108 else | |
2109 gripe_unary_op_conversion_failed | |
2110 (octave_value::unary_op_as_string (op), type_name ()); | |
2111 } | |
2112 else | |
2113 gripe_unary_op (octave_value::unary_op_as_string (op), type_name ()); | |
2114 } | |
3933 | 2115 |
2116 return *this; | |
3203 | 2117 } |
2118 | |
3933 | 2119 #if 0 |
3205 | 2120 static void |
3933 | 2121 gripe_unary_op_failed_or_no_method (const std::string& on, |
2122 const std::string& tn) | |
3205 | 2123 { |
2124 error ("operator %s: no method, or unable to evaluate for %s operand", | |
2125 on.c_str (), tn.c_str ()); | |
2126 } | |
3933 | 2127 #endif |
3205 | 2128 |
2129 void | |
4661 | 2130 octave_value::do_non_const_unary_op (unary_op, const octave_value_list&) |
3205 | 2131 { |
3933 | 2132 abort (); |
2133 } | |
2134 | |
2135 octave_value | |
4247 | 2136 octave_value::do_non_const_unary_op (unary_op op, const std::string& type, |
4219 | 2137 const std::list<octave_value_list>& idx) |
3933 | 2138 { |
2139 octave_value retval; | |
2140 | |
2141 if (idx.empty ()) | |
2142 { | |
2143 do_non_const_unary_op (op); | |
3205 | 2144 |
3933 | 2145 retval = *this; |
2146 } | |
2147 else | |
2148 { | |
5775 | 2149 // FIXME -- only do the following stuff if we can't find a |
3933 | 2150 // specific function to call to handle the op= operation for the |
2151 // types we have. | |
3205 | 2152 |
3933 | 2153 assign_op assop = unary_op_to_assign_op (op); |
2154 | |
2155 retval = assign (assop, type, idx, 1.0); | |
2156 } | |
2157 | |
2158 return retval; | |
3205 | 2159 } |
2160 | |
2161 octave_value::assign_op | |
2162 octave_value::unary_op_to_assign_op (unary_op op) | |
2163 { | |
2164 assign_op binop = unknown_assign_op; | |
2165 | |
2166 switch (op) | |
2167 { | |
3533 | 2168 case op_incr: |
2169 binop = op_add_eq; | |
3205 | 2170 break; |
2171 | |
3533 | 2172 case op_decr: |
2173 binop = op_sub_eq; | |
3205 | 2174 break; |
2175 | |
2176 default: | |
2177 { | |
3523 | 2178 std::string on = unary_op_as_string (op); |
3205 | 2179 error ("operator %s: no assign operator found", on.c_str ()); |
2180 } | |
2181 } | |
2182 | |
2183 return binop; | |
2184 } | |
2185 | |
3204 | 2186 octave_value::binary_op |
2187 octave_value::op_eq_to_binary_op (assign_op op) | |
2188 { | |
2189 binary_op binop = unknown_binary_op; | |
2190 | |
2191 switch (op) | |
2192 { | |
3533 | 2193 case op_add_eq: |
2194 binop = op_add; | |
3204 | 2195 break; |
2196 | |
3533 | 2197 case op_sub_eq: |
2198 binop = op_sub; | |
3204 | 2199 break; |
2200 | |
3533 | 2201 case op_mul_eq: |
2202 binop = op_mul; | |
3204 | 2203 break; |
2204 | |
3533 | 2205 case op_div_eq: |
2206 binop = op_div; | |
3204 | 2207 break; |
2208 | |
3533 | 2209 case op_ldiv_eq: |
2210 binop = op_ldiv; | |
3204 | 2211 break; |
2212 | |
4018 | 2213 case op_pow_eq: |
2214 binop = op_pow; | |
2215 break; | |
2216 | |
3533 | 2217 case op_lshift_eq: |
2218 binop = op_lshift; | |
3204 | 2219 break; |
2220 | |
3533 | 2221 case op_rshift_eq: |
2222 binop = op_rshift; | |
3204 | 2223 break; |
2224 | |
3533 | 2225 case op_el_mul_eq: |
2226 binop = op_el_mul; | |
3204 | 2227 break; |
2228 | |
3533 | 2229 case op_el_div_eq: |
2230 binop = op_el_div; | |
3204 | 2231 break; |
2232 | |
3533 | 2233 case op_el_ldiv_eq: |
2234 binop = op_el_ldiv; | |
3204 | 2235 break; |
2236 | |
4018 | 2237 case op_el_pow_eq: |
2238 binop = op_el_pow; | |
2239 break; | |
2240 | |
3533 | 2241 case op_el_and_eq: |
2242 binop = op_el_and; | |
3204 | 2243 break; |
2244 | |
3533 | 2245 case op_el_or_eq: |
2246 binop = op_el_or; | |
3204 | 2247 break; |
2248 | |
2249 default: | |
2250 { | |
3523 | 2251 std::string on = assign_op_as_string (op); |
3204 | 2252 error ("operator %s: no binary operator found", on.c_str ()); |
2253 } | |
2254 } | |
2255 | |
2256 return binop; | |
2257 } | |
2258 | |
3933 | 2259 octave_value |
2260 octave_value::empty_conv (const std::string& type, const octave_value& rhs) | |
2261 { | |
2262 octave_value retval; | |
2263 | |
2264 if (type.length () > 0) | |
2265 { | |
2266 switch (type[0]) | |
2267 { | |
2268 case '(': | |
2269 { | |
2270 if (type.length () > 1 && type[1] == '.') | |
2271 retval = Octave_map (); | |
2272 else | |
2273 retval = octave_value (rhs.empty_clone ()); | |
2274 } | |
2275 break; | |
2276 | |
2277 case '{': | |
2278 retval = Cell (); | |
2279 break; | |
2280 | |
2281 case '.': | |
2282 retval = Octave_map (); | |
2283 break; | |
2284 | |
2285 default: | |
2286 panic_impossible (); | |
2287 } | |
2288 } | |
2289 else | |
2290 retval = octave_value (rhs.empty_clone ()); | |
2291 | |
2292 return retval; | |
2293 } | |
2294 | |
2376 | 2295 void |
2296 install_types (void) | |
2297 { | |
2298 octave_base_value::register_type (); | |
3928 | 2299 octave_cell::register_type (); |
2376 | 2300 octave_scalar::register_type (); |
2301 octave_complex::register_type (); | |
2302 octave_matrix::register_type (); | |
2303 octave_complex_matrix::register_type (); | |
2304 octave_range::register_type (); | |
2825 | 2305 octave_bool::register_type (); |
2306 octave_bool_matrix::register_type (); | |
2376 | 2307 octave_char_matrix::register_type (); |
2308 octave_char_matrix_str::register_type (); | |
5279 | 2309 octave_char_matrix_sq_str::register_type (); |
4901 | 2310 octave_int8_scalar::register_type (); |
2311 octave_int16_scalar::register_type (); | |
2312 octave_int32_scalar::register_type (); | |
2313 octave_int64_scalar::register_type (); | |
2314 octave_uint8_scalar::register_type (); | |
2315 octave_uint16_scalar::register_type (); | |
2316 octave_uint32_scalar::register_type (); | |
2317 octave_uint64_scalar::register_type (); | |
2318 octave_int8_matrix::register_type (); | |
2319 octave_int16_matrix::register_type (); | |
2320 octave_int32_matrix::register_type (); | |
2321 octave_int64_matrix::register_type (); | |
2322 octave_uint8_matrix::register_type (); | |
2323 octave_uint16_matrix::register_type (); | |
2324 octave_uint32_matrix::register_type (); | |
2325 octave_uint64_matrix::register_type (); | |
5164 | 2326 octave_sparse_bool_matrix::register_type (); |
2327 octave_sparse_matrix::register_type (); | |
2328 octave_sparse_complex_matrix::register_type (); | |
2376 | 2329 octave_struct::register_type (); |
7336 | 2330 octave_class::register_type (); |
2880 | 2331 octave_list::register_type (); |
3977 | 2332 octave_cs_list::register_type (); |
2376 | 2333 octave_magic_colon::register_type (); |
2974 | 2334 octave_builtin::register_type (); |
2335 octave_user_function::register_type (); | |
4649 | 2336 octave_dld_function::register_type (); |
4643 | 2337 octave_fcn_handle::register_type (); |
4966 | 2338 octave_fcn_inline::register_type (); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
2339 octave_float_scalar::register_type (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
2340 octave_float_complex::register_type (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
2341 octave_float_matrix::register_type (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
2342 octave_float_complex_matrix::register_type (); |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8039
diff
changeset
|
2343 octave_null_matrix::register_type (); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8039
diff
changeset
|
2344 octave_null_str::register_type (); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8039
diff
changeset
|
2345 octave_null_sq_str::register_type (); |
2376 | 2346 } |
2347 | |
4970 | 2348 #if 0 |
2349 DEFUN (cast, args, , | |
2350 "-*- texinfo -*-\n\ | |
2351 @deftypefn {Built-in Function} {} cast (@var{val}, @var{type})\n\ | |
2352 Convert @var{val} to the new data type @var{type}.\n\ | |
5642 | 2353 @seealso{class, typeinfo}\n\ |
2354 @end deftypefn") | |
4970 | 2355 { |
2356 octave_value retval; | |
2357 | |
2358 if (args.length () == 2) | |
2359 error ("cast: not implemented"); | |
2360 else | |
5823 | 2361 print_usage (); |
4970 | 2362 |
2363 return retval; | |
2364 } | |
2365 #endif | |
2366 | |
4791 | 2367 DEFUN (sizeof, args, , |
2368 "-*- texinfo -*-\n\ | |
2369 @deftypefn {Built-in Function} {} sizeof (@var{val})\n\ | |
2370 Return the size of @var{val} in bytes\n\ | |
2371 @end deftypefn") | |
2372 { | |
2373 octave_value retval; | |
2374 | |
2375 if (args.length () == 1) | |
2376 retval = args(0).byte_size (); | |
2377 else | |
5823 | 2378 print_usage (); |
4791 | 2379 |
2380 return retval; | |
2381 } | |
2382 | |
6153 | 2383 static void |
2384 decode_subscripts (const char* name, const octave_value& arg, | |
2385 std::string& type_string, | |
2386 std::list<octave_value_list>& idx) | |
2387 { | |
2388 Octave_map m = arg.map_value (); | |
2389 | |
2390 if (! error_state | |
6639 | 2391 && m.nfields () == 2 && m.contains ("type") && m.contains ("subs")) |
6153 | 2392 { |
2393 Cell& type = m.contents ("type"); | |
2394 Cell& subs = m.contents ("subs"); | |
2395 | |
2396 type_string = std::string (type.length(), '\0'); | |
2397 | |
2398 for (int k = 0; k < type.length (); k++) | |
2399 { | |
2400 std::string item = type(k).string_value (); | |
2401 | |
2402 if (! error_state) | |
2403 { | |
2404 if (item == "{}") | |
2405 type_string[k] = '{'; | |
2406 else if (item == "()") | |
2407 type_string[k] = '('; | |
2408 else if (item == ".") | |
2409 type_string[k] = '.'; | |
2410 else | |
2411 { | |
2412 error("%s: invalid indexing type `%s'", name, item.c_str ()); | |
2413 return; | |
2414 } | |
2415 } | |
2416 else | |
2417 { | |
2418 error ("%s: expecting type(%d) to be a character string", | |
2419 name, k+1); | |
2420 return; | |
2421 } | |
2422 | |
2423 octave_value_list idx_item; | |
2424 | |
2425 if (subs(k).is_string ()) | |
2426 idx_item(0) = subs(k); | |
2427 else if (subs(k).is_cell ()) | |
2428 { | |
2429 Cell subs_cell = subs(k).cell_value (); | |
2430 | |
2431 for (int n = 0; n < subs_cell.length (); n++) | |
2432 { | |
2433 if (subs_cell(n).is_string () | |
2434 && subs_cell(n).string_value () == ":") | |
2435 idx_item(n) = octave_value(octave_value::magic_colon_t); | |
2436 else | |
2437 idx_item(n) = subs_cell(n); | |
2438 } | |
2439 } | |
2440 else | |
2441 { | |
2442 error ("%s: expecting subs(%d) to be a character string or cell array", | |
2443 name, k+1); | |
2444 return; | |
2445 } | |
2446 | |
2447 idx.push_back (idx_item); | |
2448 } | |
2449 } | |
2450 else | |
2451 error ("%s: second argument must be a structure with fields `type' and `subs'", name); | |
2452 } | |
2453 | |
2454 DEFUN (subsref, args, nargout, | |
2455 "-*- texinfo -*-\n\ | |
2456 @deftypefn {Built-in Function} {} subsref (@var{val}, @var{idx})\n\ | |
2457 Perform the subscripted element selection operation according to\n\ | |
2458 the subscript specified by @var{idx}.\n\ | |
2459 \n\ | |
2460 The subscript @var{idx} is expected to be a structure array with\n\ | |
2461 fields @samp{type} and @samp{subs}. Valid values for @samp{type}\n\ | |
6550 | 2462 are @samp{\"()\"}, @samp{\"@{@}\"}, and @samp{\".\"}.\n\ |
6153 | 2463 The @samp{subs} field may be either @samp{\":\"} or a cell array\n\ |
2464 of index values.\n\ | |
6631 | 2465 \n\ |
2466 The following example shows how to extract the two first columns of\n\ | |
2467 a matrix\n\ | |
2468 \n\ | |
2469 @example\n\ | |
2470 val = magic(3)\n\ | |
2471 @result{} val = [ 8 1 6\n\ | |
2472 3 5 7\n\ | |
2473 4 9 2 ]\n\ | |
2474 idx.type = \"()\";\n\ | |
2475 idx.subs = @{\":\", 1:2@};\n\ | |
2476 subsref(val, idx)\n\ | |
2477 @result{} [ 8 1 \n\ | |
2478 3 5 \n\ | |
2479 4 9 ]\n\ | |
2480 @end example\n\ | |
2481 \n\ | |
2482 @noindent\n\ | |
2483 Note that this is the same as writing @code{val(:,1:2)}.\n\ | |
6157 | 2484 @seealso{subsasgn, substruct}\n\ |
6153 | 2485 @end deftypefn") |
2486 { | |
2487 octave_value_list retval; | |
2488 | |
2489 if (args.length () == 2) | |
2490 { | |
2491 std::string type; | |
2492 std::list<octave_value_list> idx; | |
2493 | |
2494 decode_subscripts ("subsref", args(1), type, idx); | |
2495 | |
2496 if (! error_state) | |
2497 retval = args(0).subsref (type, idx, nargout); | |
2498 } | |
2499 else | |
2500 print_usage (); | |
2501 | |
2502 return retval; | |
2503 } | |
2504 | |
2505 DEFUN (subsasgn, args, , | |
2506 "-*- texinfo -*-\n\ | |
2507 @deftypefn {Built-in Function} {} subsasgn (@var{val}, @var{idx}, @var{rhs})\n\ | |
2508 Perform the subscripted assignment operation according to\n\ | |
2509 the subscript specified by @var{idx}.\n\ | |
2510 \n\ | |
2511 The subscript @var{idx} is expected to be a structure array with\n\ | |
2512 fields @samp{type} and @samp{subs}. Valid values for @samp{type}\n\ | |
6248 | 2513 are @samp{\"()\"}, @samp{\"@{@}\"}, and @samp{\".\"}.\n\ |
6153 | 2514 The @samp{subs} field may be either @samp{\":\"} or a cell array\n\ |
2515 of index values.\n\ | |
6631 | 2516 \n\ |
2517 The following example shows how to set the two first columns of a\n\ | |
2518 3-by-3 matrix to zero.\n\ | |
2519 \n\ | |
2520 @example\n\ | |
2521 val = magic(3);\n\ | |
2522 idx.type = \"()\";\n\ | |
2523 idx.subs = @{\":\", 1:2@};\n\ | |
2524 subsasgn (val, idx, 0)\n\ | |
2525 @result{} [ 0 0 6\n\ | |
2526 0 0 7\n\ | |
2527 0 0 2 ]\n\ | |
2528 @end example\n\ | |
2529 \n\ | |
2530 Note that this is the same as writing @code{val(:,1:2) = 0}.\n\ | |
6157 | 2531 @seealso{subsref, substruct}\n\ |
6153 | 2532 @end deftypefn") |
2533 { | |
2534 octave_value retval; | |
2535 | |
2536 if (args.length () == 3) | |
2537 { | |
2538 std::string type; | |
2539 std::list<octave_value_list> idx; | |
2540 | |
2541 decode_subscripts ("subsasgn", args(1), type, idx); | |
2542 | |
2543 if (! error_state) | |
2544 retval = args(0).subsasgn (type, idx, args(2)); | |
2545 } | |
2546 else | |
2547 print_usage (); | |
2548 | |
2549 return retval; | |
2550 } | |
2551 | |
2376 | 2552 /* |
2553 ;;; Local Variables: *** | |
2554 ;;; mode: C++ *** | |
2555 ;;; End: *** | |
2556 */ |