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