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