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