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