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