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