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