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