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