Mercurial > octave-nkf
annotate src/ov.cc @ 9479:d9716e3ee0dd
supply optimized compiled sub2ind & ind2sub
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Mon, 03 Aug 2009 15:52:40 +0200 |
parents | ff612fdaee95 |
children | 1beb23d2b892 |
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 | |
9351
e2344f4af0cb
autocache indices returned from find et al.
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
977 octave_value::octave_value (const Array<octave_idx_type>& inda, bool zero_based, |
e2344f4af0cb
autocache indices returned from find et al.
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
978 bool cache_index) |
e2344f4af0cb
autocache indices returned from find et al.
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
979 : rep (new octave_matrix (inda, zero_based, cache_index)) |
e2344f4af0cb
autocache indices returned from find et al.
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
980 { |
e2344f4af0cb
autocache indices returned from find et al.
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
981 maybe_mutate (); |
e2344f4af0cb
autocache indices returned from find et al.
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
982 } |
e2344f4af0cb
autocache indices returned from find et al.
Jaroslav Hajek <highegg@gmail.com>
parents:
9329
diff
changeset
|
983 |
9479
d9716e3ee0dd
supply optimized compiled sub2ind & ind2sub
Jaroslav Hajek <highegg@gmail.com>
parents:
9368
diff
changeset
|
984 octave_value::octave_value (const idx_vector& idx) |
d9716e3ee0dd
supply optimized compiled sub2ind & ind2sub
Jaroslav Hajek <highegg@gmail.com>
parents:
9368
diff
changeset
|
985 : rep () |
d9716e3ee0dd
supply optimized compiled sub2ind & ind2sub
Jaroslav Hajek <highegg@gmail.com>
parents:
9368
diff
changeset
|
986 { |
d9716e3ee0dd
supply optimized compiled sub2ind & ind2sub
Jaroslav Hajek <highegg@gmail.com>
parents:
9368
diff
changeset
|
987 double scalar; |
d9716e3ee0dd
supply optimized compiled sub2ind & ind2sub
Jaroslav Hajek <highegg@gmail.com>
parents:
9368
diff
changeset
|
988 Range range; |
d9716e3ee0dd
supply optimized compiled sub2ind & ind2sub
Jaroslav Hajek <highegg@gmail.com>
parents:
9368
diff
changeset
|
989 NDArray array; |
d9716e3ee0dd
supply optimized compiled sub2ind & ind2sub
Jaroslav Hajek <highegg@gmail.com>
parents:
9368
diff
changeset
|
990 idx_vector::idx_class_type idx_class; |
d9716e3ee0dd
supply optimized compiled sub2ind & ind2sub
Jaroslav Hajek <highegg@gmail.com>
parents:
9368
diff
changeset
|
991 |
d9716e3ee0dd
supply optimized compiled sub2ind & ind2sub
Jaroslav Hajek <highegg@gmail.com>
parents:
9368
diff
changeset
|
992 idx.unconvert (idx_class, scalar, range, array); |
d9716e3ee0dd
supply optimized compiled sub2ind & ind2sub
Jaroslav Hajek <highegg@gmail.com>
parents:
9368
diff
changeset
|
993 |
d9716e3ee0dd
supply optimized compiled sub2ind & ind2sub
Jaroslav Hajek <highegg@gmail.com>
parents:
9368
diff
changeset
|
994 switch (idx_class) |
d9716e3ee0dd
supply optimized compiled sub2ind & ind2sub
Jaroslav Hajek <highegg@gmail.com>
parents:
9368
diff
changeset
|
995 { |
d9716e3ee0dd
supply optimized compiled sub2ind & ind2sub
Jaroslav Hajek <highegg@gmail.com>
parents:
9368
diff
changeset
|
996 case idx_vector::class_colon: |
d9716e3ee0dd
supply optimized compiled sub2ind & ind2sub
Jaroslav Hajek <highegg@gmail.com>
parents:
9368
diff
changeset
|
997 rep = new octave_magic_colon (); |
d9716e3ee0dd
supply optimized compiled sub2ind & ind2sub
Jaroslav Hajek <highegg@gmail.com>
parents:
9368
diff
changeset
|
998 break; |
d9716e3ee0dd
supply optimized compiled sub2ind & ind2sub
Jaroslav Hajek <highegg@gmail.com>
parents:
9368
diff
changeset
|
999 case idx_vector::class_range: |
d9716e3ee0dd
supply optimized compiled sub2ind & ind2sub
Jaroslav Hajek <highegg@gmail.com>
parents:
9368
diff
changeset
|
1000 rep = new octave_range (range, idx); |
d9716e3ee0dd
supply optimized compiled sub2ind & ind2sub
Jaroslav Hajek <highegg@gmail.com>
parents:
9368
diff
changeset
|
1001 break; |
d9716e3ee0dd
supply optimized compiled sub2ind & ind2sub
Jaroslav Hajek <highegg@gmail.com>
parents:
9368
diff
changeset
|
1002 case idx_vector::class_scalar: |
d9716e3ee0dd
supply optimized compiled sub2ind & ind2sub
Jaroslav Hajek <highegg@gmail.com>
parents:
9368
diff
changeset
|
1003 rep = new octave_scalar (scalar); |
d9716e3ee0dd
supply optimized compiled sub2ind & ind2sub
Jaroslav Hajek <highegg@gmail.com>
parents:
9368
diff
changeset
|
1004 break; |
d9716e3ee0dd
supply optimized compiled sub2ind & ind2sub
Jaroslav Hajek <highegg@gmail.com>
parents:
9368
diff
changeset
|
1005 case idx_vector::class_vector: |
d9716e3ee0dd
supply optimized compiled sub2ind & ind2sub
Jaroslav Hajek <highegg@gmail.com>
parents:
9368
diff
changeset
|
1006 rep = new octave_matrix (array, idx); |
d9716e3ee0dd
supply optimized compiled sub2ind & ind2sub
Jaroslav Hajek <highegg@gmail.com>
parents:
9368
diff
changeset
|
1007 break; |
d9716e3ee0dd
supply optimized compiled sub2ind & ind2sub
Jaroslav Hajek <highegg@gmail.com>
parents:
9368
diff
changeset
|
1008 default: |
d9716e3ee0dd
supply optimized compiled sub2ind & ind2sub
Jaroslav Hajek <highegg@gmail.com>
parents:
9368
diff
changeset
|
1009 assert (false); |
d9716e3ee0dd
supply optimized compiled sub2ind & ind2sub
Jaroslav Hajek <highegg@gmail.com>
parents:
9368
diff
changeset
|
1010 break; |
d9716e3ee0dd
supply optimized compiled sub2ind & ind2sub
Jaroslav Hajek <highegg@gmail.com>
parents:
9368
diff
changeset
|
1011 } |
d9716e3ee0dd
supply optimized compiled sub2ind & ind2sub
Jaroslav Hajek <highegg@gmail.com>
parents:
9368
diff
changeset
|
1012 |
d9716e3ee0dd
supply optimized compiled sub2ind & ind2sub
Jaroslav Hajek <highegg@gmail.com>
parents:
9368
diff
changeset
|
1013 // FIXME: needed? |
d9716e3ee0dd
supply optimized compiled sub2ind & ind2sub
Jaroslav Hajek <highegg@gmail.com>
parents:
9368
diff
changeset
|
1014 maybe_mutate (); |
d9716e3ee0dd
supply optimized compiled sub2ind & ind2sub
Jaroslav Hajek <highegg@gmail.com>
parents:
9368
diff
changeset
|
1015 } |
d9716e3ee0dd
supply optimized compiled sub2ind & ind2sub
Jaroslav Hajek <highegg@gmail.com>
parents:
9368
diff
changeset
|
1016 |
2376 | 1017 octave_value::octave_value (double base, double limit, double inc) |
2423 | 1018 : rep (new octave_range (base, limit, inc)) |
1019 { | |
1020 maybe_mutate (); | |
1021 } | |
2376 | 1022 |
1023 octave_value::octave_value (const Range& r) | |
2423 | 1024 : rep (new octave_range (r)) |
1025 { | |
1026 maybe_mutate (); | |
1027 } | |
2376 | 1028 |
1029 octave_value::octave_value (const Octave_map& m) | |
2825 | 1030 : rep (new octave_struct (m)) |
1031 { | |
2880 | 1032 } |
1033 | |
7336 | 1034 octave_value::octave_value (const Octave_map& m, const std::string& id) |
1035 : rep (new octave_class (m, id)) | |
1036 { | |
1037 } | |
1038 | |
4587 | 1039 octave_value::octave_value (const octave_value_list& l, bool is_csl) |
5477 | 1040 : rep (is_csl |
5759 | 1041 ? dynamic_cast<octave_base_value *> (new octave_cs_list (l)) |
1042 : dynamic_cast<octave_base_value *> (new octave_list (l))) | |
2880 | 1043 { |
1044 } | |
2376 | 1045 |
1046 octave_value::octave_value (octave_value::magic_colon) | |
2825 | 1047 : rep (new octave_magic_colon ()) |
1048 { | |
1049 } | |
2376 | 1050 |
5759 | 1051 octave_value::octave_value (octave_base_value *new_rep) |
2825 | 1052 : rep (new_rep) |
1053 { | |
1054 } | |
2376 | 1055 |
7336 | 1056 octave_value::octave_value (octave_base_value *new_rep, int xcount) |
1057 : rep (new_rep) | |
1058 { | |
1059 rep->count = xcount; | |
1060 } | |
1061 | |
5759 | 1062 octave_base_value * |
3933 | 1063 octave_value::clone (void) const |
2880 | 1064 { |
1065 panic_impossible (); | |
3546 | 1066 return 0; |
2880 | 1067 } |
1068 | |
2409 | 1069 void |
1070 octave_value::maybe_mutate (void) | |
1071 { | |
5759 | 1072 octave_base_value *tmp = rep->try_narrowing_conversion (); |
2409 | 1073 |
1074 if (tmp && tmp != rep) | |
1075 { | |
1076 if (--rep->count == 0) | |
1077 delete rep; | |
1078 | |
1079 rep = tmp; | |
1080 } | |
1081 } | |
1082 | |
4247 | 1083 octave_value |
4271 | 1084 octave_value::single_subsref (const std::string& type, |
1085 const octave_value_list& idx) | |
4247 | 1086 { |
1087 std::list<octave_value_list> i; | |
1088 | |
1089 i.push_back (idx); | |
1090 | |
1091 return rep->subsref (type, i); | |
1092 } | |
1093 | |
2974 | 1094 octave_value_list |
4247 | 1095 octave_value::subsref (const std::string& type, |
4219 | 1096 const std::list<octave_value_list>& idx, int nargout) |
3933 | 1097 { |
7651
443a8f5a50fd
require both subsref variants to be defined in octave_value subclasses
John W. Eaton <jwe@octave.org>
parents:
7503
diff
changeset
|
1098 if (nargout == 1) |
3933 | 1099 return rep->subsref (type, idx); |
1100 else | |
1101 return rep->subsref (type, idx, nargout); | |
1102 } | |
1103 | |
1104 octave_value | |
4247 | 1105 octave_value::next_subsref (const std::string& type, |
4219 | 1106 const std::list<octave_value_list>& idx, |
4233 | 1107 size_t skip) |
3933 | 1108 { |
4582 | 1109 if (! error_state && idx.size () > skip) |
3933 | 1110 { |
4219 | 1111 std::list<octave_value_list> new_idx (idx); |
4233 | 1112 for (size_t i = 0; i < skip; i++) |
4219 | 1113 new_idx.erase (new_idx.begin ()); |
3933 | 1114 return subsref (type.substr (skip), new_idx); |
1115 } | |
1116 else | |
1117 return *this; | |
1118 } | |
1119 | |
1120 octave_value_list | |
4994 | 1121 octave_value::next_subsref (int nargout, const std::string& type, |
1122 const std::list<octave_value_list>& idx, | |
1123 size_t skip) | |
1124 { | |
1125 if (! error_state && idx.size () > skip) | |
1126 { | |
1127 std::list<octave_value_list> new_idx (idx); | |
1128 for (size_t i = 0; i < skip; i++) | |
1129 new_idx.erase (new_idx.begin ()); | |
1130 return subsref (type.substr (skip), new_idx, nargout); | |
1131 } | |
1132 else | |
1133 return *this; | |
1134 } | |
1135 | |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8531
diff
changeset
|
1136 octave_value |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8531
diff
changeset
|
1137 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
|
1138 const std::list<octave_value_list>& idx, |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8531
diff
changeset
|
1139 size_t skip) |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8531
diff
changeset
|
1140 { |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8531
diff
changeset
|
1141 if (! error_state && idx.size () > skip) |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8531
diff
changeset
|
1142 { |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8531
diff
changeset
|
1143 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
|
1144 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
|
1145 new_idx.erase (new_idx.begin ()); |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8531
diff
changeset
|
1146 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
|
1147 } |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8531
diff
changeset
|
1148 else |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8531
diff
changeset
|
1149 return *this; |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8531
diff
changeset
|
1150 } |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8531
diff
changeset
|
1151 |
4994 | 1152 octave_value_list |
3544 | 1153 octave_value::do_multi_index_op (int nargout, const octave_value_list& idx) |
2974 | 1154 { |
3544 | 1155 return rep->do_multi_index_op (nargout, idx); |
2974 | 1156 } |
1157 | |
3933 | 1158 #if 0 |
3204 | 1159 static void |
3933 | 1160 gripe_assign_failed (const std::string& on, const std::string& tn1, |
1161 const std::string& tn2) | |
3204 | 1162 { |
1163 error ("assignment failed for `%s %s %s'", | |
1164 tn1.c_str (), on.c_str (), tn2.c_str ()); | |
1165 } | |
3933 | 1166 #endif |
3204 | 1167 |
1168 static void | |
3933 | 1169 gripe_assign_failed_or_no_method (const std::string& on, |
1170 const std::string& tn1, | |
3523 | 1171 const std::string& tn2) |
3204 | 1172 { |
1173 error ("assignment failed, or no method for `%s %s %s'", | |
1174 tn1.c_str (), on.c_str (), tn2.c_str ()); | |
1175 } | |
1176 | |
3933 | 1177 octave_value |
4247 | 1178 octave_value::subsasgn (const std::string& type, |
4219 | 1179 const std::list<octave_value_list>& idx, |
3933 | 1180 const octave_value& rhs) |
1181 { | |
1182 return rep->subsasgn (type, idx, rhs); | |
1183 } | |
1184 | |
1185 octave_value | |
4247 | 1186 octave_value::assign (assign_op op, const std::string& type, |
4219 | 1187 const std::list<octave_value_list>& idx, |
3933 | 1188 const octave_value& rhs) |
1189 { | |
1190 octave_value retval; | |
1191 | |
1192 make_unique (); | |
1193 | |
1194 octave_value t_rhs = rhs; | |
1195 | |
1196 if (op != op_asn_eq) | |
1197 { | |
5775 | 1198 // FIXME -- only do the following stuff if we can't find |
3933 | 1199 // a specific function to call to handle the op= operation for |
1200 // the types we have. | |
1201 | |
7651
443a8f5a50fd
require both subsref variants to be defined in octave_value subclasses
John W. Eaton <jwe@octave.org>
parents:
7503
diff
changeset
|
1202 octave_value t = subsref (type, idx); |
3933 | 1203 |
1204 if (! error_state) | |
1205 { | |
1206 binary_op binop = op_eq_to_binary_op (op); | |
1207 | |
1208 if (! error_state) | |
1209 t_rhs = do_binary_op (binop, t, rhs); | |
1210 } | |
1211 } | |
1212 | |
1213 if (! error_state) | |
1214 { | |
7336 | 1215 if (type[0] == '.' && ! (is_map () || is_object ())) |
3933 | 1216 { |
1217 octave_value tmp = Octave_map (); | |
1218 retval = tmp.subsasgn (type, idx, t_rhs); | |
1219 } | |
1220 else | |
1221 retval = subsasgn (type, idx, t_rhs); | |
1222 } | |
1223 | |
1224 if (error_state) | |
1225 gripe_assign_failed_or_no_method (assign_op_as_string (op), | |
1226 type_name (), rhs.type_name ()); | |
1227 | |
1228 return retval; | |
1229 } | |
1230 | |
1231 const octave_value& | |
3203 | 1232 octave_value::assign (assign_op op, const octave_value& rhs) |
2880 | 1233 { |
3533 | 1234 if (op == op_asn_eq) |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8039
diff
changeset
|
1235 // 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
|
1236 operator = (rhs.storable_value ()); |
3203 | 1237 else |
1238 { | |
5775 | 1239 // FIXME -- only do the following stuff if we can't find |
3204 | 1240 // a specific function to call to handle the op= operation for |
1241 // the types we have. | |
1242 | |
1243 binary_op binop = op_eq_to_binary_op (op); | |
1244 | |
1245 if (! error_state) | |
1246 { | |
1247 octave_value t = do_binary_op (binop, *this, rhs); | |
1248 | |
1249 if (! error_state) | |
1250 operator = (t); | |
1251 } | |
1252 | |
1253 if (error_state) | |
1254 gripe_assign_failed_or_no_method (assign_op_as_string (op), | |
1255 type_name (), rhs.type_name ()); | |
1256 } | |
1257 | |
3933 | 1258 return *this; |
2376 | 1259 } |
1260 | |
5275 | 1261 octave_idx_type |
4563 | 1262 octave_value::length (void) const |
1263 { | |
1264 int retval = 0; | |
1265 | |
1266 dim_vector dv = dims (); | |
4584 | 1267 |
4563 | 1268 for (int i = 0; i < dv.length (); i++) |
1269 { | |
1270 if (dv(i) < 0) | |
1271 { | |
1272 retval = -1; | |
1273 break; | |
1274 } | |
1275 | |
4584 | 1276 if (dv(i) == 0) |
1277 { | |
1278 retval = 0; | |
1279 break; | |
1280 } | |
1281 | |
4563 | 1282 if (dv(i) > retval) |
1283 retval = dv(i); | |
1284 } | |
1285 | |
1286 return retval; | |
1287 } | |
1288 | |
8346
8302788f09db
fix empty matrix handling in switch statement
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
1289 bool |
8302788f09db
fix empty matrix handling in switch statement
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
1290 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
|
1291 { |
8302788f09db
fix empty matrix handling in switch statement
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
1292 bool retval = false; |
8302788f09db
fix empty matrix handling in switch statement
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
1293 |
8302788f09db
fix empty matrix handling in switch statement
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
1294 // 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
|
1295 |
8302788f09db
fix empty matrix handling in switch statement
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
1296 if (rows () == test.rows () && columns () == test.columns ()) |
8302788f09db
fix empty matrix handling in switch statement
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
1297 { |
8302788f09db
fix empty matrix handling in switch statement
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
1298 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
|
1299 |
8302788f09db
fix empty matrix handling in switch statement
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
1300 // Empty array also means a match. |
8302788f09db
fix empty matrix handling in switch statement
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
1301 if (! error_state && tmp.is_defined ()) |
8302788f09db
fix empty matrix handling in switch statement
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
1302 retval = tmp.is_true () || tmp.is_empty (); |
8302788f09db
fix empty matrix handling in switch statement
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
1303 } |
8302788f09db
fix empty matrix handling in switch statement
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
1304 |
8302788f09db
fix empty matrix handling in switch statement
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
1305 return retval; |
8302788f09db
fix empty matrix handling in switch statement
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
1306 } |
8302788f09db
fix empty matrix handling in switch statement
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
1307 |
3351 | 1308 Cell |
1309 octave_value::cell_value (void) const | |
1310 { | |
1311 return rep->cell_value (); | |
1312 } | |
1313 | |
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
|
1314 // 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
|
1315 // 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
|
1316 |
260294a5520f
octave_value::idx_type_value: move definition to ov.cc from ov.h
John W. Eaton <jwe@octave.org>
parents:
8011
diff
changeset
|
1317 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
|
1318 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
|
1319 { |
260294a5520f
octave_value::idx_type_value: move definition to ov.cc from ov.h
John W. Eaton <jwe@octave.org>
parents:
8011
diff
changeset
|
1320 #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
|
1321 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
|
1322 #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
|
1323 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
|
1324 #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
|
1325 #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
|
1326 #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
|
1327 } |
260294a5520f
octave_value::idx_type_value: move definition to ov.cc from ov.h
John W. Eaton <jwe@octave.org>
parents:
8011
diff
changeset
|
1328 |
2376 | 1329 Octave_map |
1330 octave_value::map_value (void) const | |
1331 { | |
1332 return rep->map_value (); | |
1333 } | |
1334 | |
2974 | 1335 octave_function * |
1336 octave_value::function_value (bool silent) | |
1337 { | |
1338 return rep->function_value (silent); | |
1339 } | |
1340 | |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
1341 const octave_function * |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
1342 octave_value::function_value (bool silent) const |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
1343 { |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
1344 return rep->function_value (silent); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
1345 } |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
1346 |
4700 | 1347 octave_user_function * |
1348 octave_value::user_function_value (bool silent) | |
1349 { | |
1350 return rep->user_function_value (silent); | |
1351 } | |
1352 | |
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
|
1353 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
|
1354 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
|
1355 { |
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
|
1356 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
|
1357 } |
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
|
1358 |
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
|
1359 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
|
1360 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
|
1361 { |
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
|
1362 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
|
1363 } |
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
|
1364 |
4346 | 1365 octave_fcn_handle * |
4343 | 1366 octave_value::fcn_handle_value (bool silent) |
1367 { | |
1368 return rep->fcn_handle_value (silent); | |
1369 } | |
1370 | |
4933 | 1371 octave_fcn_inline * |
1372 octave_value::fcn_inline_value (bool silent) | |
1373 { | |
1374 return rep->fcn_inline_value (silent); | |
1375 } | |
1376 | |
2880 | 1377 octave_value_list |
1378 octave_value::list_value (void) const | |
1379 { | |
1380 return rep->list_value (); | |
1381 } | |
1382 | |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1383 static dim_vector |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1384 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
|
1385 const std::string& my_type, const std::string& wanted_type) |
3419 | 1386 { |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1387 dim_vector retval (dv); |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1388 retval.chop_trailing_singletons (); |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1389 octave_idx_type nel = dv.numel (); |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1390 |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1391 if (retval.length () > 2 || (retval(0) != 1 && retval(1) != 1)) |
3419 | 1392 { |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1393 if (!force_vector_conversion) |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1394 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
|
1395 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
|
1396 retval = dim_vector (nel); |
3419 | 1397 } |
1398 | |
1399 return retval; | |
1400 } | |
1401 | |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1402 ColumnVector |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1403 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
|
1404 bool frc_vec_conv) const |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1405 { |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1406 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
|
1407 frc_vec_conv)); |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1408 } |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1409 |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1410 ComplexColumnVector |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1411 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
|
1412 bool frc_vec_conv) const |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1413 { |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1414 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
|
1415 frc_vec_conv)); |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1416 } |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1417 |
3419 | 1418 RowVector |
1419 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
|
1420 bool frc_vec_conv) const |
3419 | 1421 { |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1422 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
|
1423 frc_vec_conv)); |
3419 | 1424 } |
1425 | |
1426 ComplexRowVector | |
1427 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
|
1428 bool frc_vec_conv) const |
3419 | 1429 { |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1430 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
|
1431 frc_vec_conv)); |
3419 | 1432 } |
1433 | |
1434 Array<double> | |
2376 | 1435 octave_value::vector_value (bool force_string_conv, |
1436 bool force_vector_conversion) const | |
1437 { | |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1438 Array<double> retval = array_value (force_string_conv); |
2376 | 1439 |
1440 if (error_state) | |
1441 return retval; | |
1442 else | |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1443 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
|
1444 force_vector_conversion, |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1445 type_name (), "real vector")); |
2376 | 1446 } |
1447 | |
7997
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1448 template <class T> |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1449 static Array<int> |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1450 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
|
1451 { |
7999 | 1452 Array<int> retval (A.dims ()); |
7997
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1453 octave_idx_type n = A.numel (); |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1454 |
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
|
1455 octave_int<int>::clear_conv_flag (); |
7997
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1456 for (octave_idx_type i = 0; i < n; i++) |
7999 | 1457 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
|
1458 |
7997
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1459 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
|
1460 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
|
1461 |
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
|
1462 octave_int<int>::clear_conv_flag (); |
7997
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1463 |
7999 | 1464 return retval; |
7997
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1465 } |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1466 |
4044 | 1467 Array<int> |
1468 octave_value::int_vector_value (bool force_string_conv, bool require_int, | |
1469 bool force_vector_conversion) const | |
1470 { | |
1471 Array<int> retval; | |
1472 | |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1473 if (is_integer_type ()) |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1474 { |
7997
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1475 if (is_int32_type ()) |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1476 retval = convert_to_int_array (int32_array_value ()); |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1477 else if (is_int64_type ()) |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1478 retval = convert_to_int_array (int64_array_value ()); |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1479 else if (is_int16_type ()) |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1480 retval = convert_to_int_array (int16_array_value ()); |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1481 else if (is_int8_type ()) |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1482 retval = convert_to_int_array (int8_array_value ()); |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1483 else if (is_uint32_type ()) |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1484 retval = convert_to_int_array (uint32_array_value ()); |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1485 else if (is_uint64_type ()) |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1486 retval = convert_to_int_array (uint64_array_value ()); |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1487 else if (is_uint16_type ()) |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1488 retval = convert_to_int_array (uint16_array_value ()); |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1489 else if (is_uint8_type ()) |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1490 retval = convert_to_int_array (uint8_array_value ()); |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1491 else |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1492 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
|
1493 } |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1494 else |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1495 { |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1496 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
|
1497 if (! error_state) |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1498 { |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1499 if (require_int) |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1500 { |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1501 retval.resize (a.dims ()); |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1502 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
|
1503 { |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1504 double ai = a.elem (i); |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1505 int v = static_cast<int> (ai); |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1506 if (ai == v) |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1507 retval.xelem (i) = v; |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1508 else |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1509 { |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1510 error ("conversion to integer value failed"); |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1511 break; |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1512 } |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1513 } |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1514 } |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1515 else |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1516 retval = Array<int> (a); |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1517 } |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1518 } |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1519 |
4044 | 1520 |
1521 if (error_state) | |
1522 return retval; | |
1523 else | |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1524 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
|
1525 force_vector_conversion, |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1526 type_name (), "integer vector")); |
4044 | 1527 } |
1528 | |
8811 | 1529 template <class T> |
1530 static Array<octave_idx_type> | |
1531 convert_to_octave_idx_type_array (const Array<octave_int<T> >& A) | |
1532 { | |
1533 Array<octave_idx_type> retval (A.dims ()); | |
1534 octave_idx_type n = A.numel (); | |
1535 | |
1536 octave_int<int>::clear_conv_flag (); | |
1537 for (octave_idx_type i = 0; i < n; i++) | |
1538 retval.xelem (i) = octave_int<octave_idx_type> (A.xelem (i)); | |
1539 | |
1540 if (octave_int<int>::get_trunc_flag ()) | |
1541 gripe_truncated_conversion (octave_int<T>::type_name (), "int"); | |
1542 | |
1543 octave_int<int>::clear_conv_flag (); | |
1544 | |
1545 return retval; | |
1546 } | |
1547 | |
1548 Array<octave_idx_type> | |
9479
d9716e3ee0dd
supply optimized compiled sub2ind & ind2sub
Jaroslav Hajek <highegg@gmail.com>
parents:
9368
diff
changeset
|
1549 octave_value::octave_idx_type_vector_value (bool require_int, |
d9716e3ee0dd
supply optimized compiled sub2ind & ind2sub
Jaroslav Hajek <highegg@gmail.com>
parents:
9368
diff
changeset
|
1550 bool force_string_conv, |
8811 | 1551 bool force_vector_conversion) const |
1552 { | |
1553 Array<octave_idx_type> retval; | |
1554 | |
1555 if (is_integer_type ()) | |
1556 { | |
1557 if (is_int32_type ()) | |
1558 retval = convert_to_octave_idx_type_array (int32_array_value ()); | |
1559 else if (is_int64_type ()) | |
1560 retval = convert_to_octave_idx_type_array (int64_array_value ()); | |
1561 else if (is_int16_type ()) | |
1562 retval = convert_to_octave_idx_type_array (int16_array_value ()); | |
1563 else if (is_int8_type ()) | |
1564 retval = convert_to_octave_idx_type_array (int8_array_value ()); | |
1565 else if (is_uint32_type ()) | |
1566 retval = convert_to_octave_idx_type_array (uint32_array_value ()); | |
1567 else if (is_uint64_type ()) | |
1568 retval = convert_to_octave_idx_type_array (uint64_array_value ()); | |
1569 else if (is_uint16_type ()) | |
1570 retval = convert_to_octave_idx_type_array (uint16_array_value ()); | |
1571 else if (is_uint8_type ()) | |
1572 retval = convert_to_octave_idx_type_array (uint8_array_value ()); | |
1573 else | |
1574 retval = array_value (force_string_conv); | |
1575 } | |
1576 else | |
1577 { | |
1578 const NDArray a = array_value (force_string_conv); | |
1579 if (! error_state) | |
1580 { | |
1581 if (require_int) | |
1582 { | |
1583 retval.resize (a.dims ()); | |
1584 for (octave_idx_type i = 0; i < a.numel (); i++) | |
1585 { | |
1586 double ai = a.elem (i); | |
1587 octave_idx_type v = static_cast<octave_idx_type> (ai); | |
1588 if (ai == v) | |
1589 retval.xelem (i) = v; | |
1590 else | |
1591 { | |
1592 error ("conversion to integer value failed"); | |
1593 break; | |
1594 } | |
1595 } | |
1596 } | |
1597 else | |
1598 retval = Array<octave_idx_type> (a); | |
1599 } | |
1600 } | |
1601 | |
1602 | |
1603 if (error_state) | |
1604 return retval; | |
1605 else | |
1606 return retval.reshape (make_vector_dims (retval.dims (), | |
1607 force_vector_conversion, | |
1608 type_name (), "integer vector")); | |
1609 } | |
1610 | |
3419 | 1611 Array<Complex> |
2376 | 1612 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
|
1613 bool force_vector_conversion) const |
2376 | 1614 { |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1615 Array<Complex> retval = complex_array_value (force_string_conv); |
2376 | 1616 |
1617 if (error_state) | |
1618 return retval; | |
1619 else | |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1620 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
|
1621 force_vector_conversion, |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1622 type_name (), "complex vector")); |
2376 | 1623 } |
1624 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1625 FloatColumnVector |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1626 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
|
1627 bool frc_vec_conv) const |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1628 { |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1629 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
|
1630 frc_vec_conv)); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1631 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1632 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1633 FloatComplexColumnVector |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1634 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
|
1635 bool frc_vec_conv) const |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1636 { |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1637 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
|
1638 frc_vec_conv)); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1639 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1640 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1641 FloatRowVector |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1642 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
|
1643 bool frc_vec_conv) const |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1644 { |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1645 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
|
1646 frc_vec_conv)); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1647 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1648 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1649 FloatComplexRowVector |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1650 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
|
1651 bool frc_vec_conv) const |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1652 { |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1653 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
|
1654 frc_vec_conv)); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1655 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1656 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1657 Array<float> |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1658 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
|
1659 bool force_vector_conversion) const |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1660 { |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1661 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
|
1662 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1663 if (error_state) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1664 return retval; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1665 else |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1666 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
|
1667 force_vector_conversion, |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1668 type_name (), "real vector")); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1669 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1670 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1671 Array<FloatComplex> |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1672 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
|
1673 bool force_vector_conversion) const |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1674 { |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1675 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
|
1676 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1677 if (error_state) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1678 return retval; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1679 else |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1680 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
|
1681 force_vector_conversion, |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1682 type_name (), "complex vector")); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1683 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1684 |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8039
diff
changeset
|
1685 octave_value |
8523
ad3afaaa19c1
implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
1686 octave_value::storable_value (void) const |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8039
diff
changeset
|
1687 { |
8523
ad3afaaa19c1
implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
1688 octave_value retval = *this; |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8039
diff
changeset
|
1689 if (is_null_value ()) |
8523
ad3afaaa19c1
implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
1690 retval = octave_value (rep->empty_clone ()); |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8039
diff
changeset
|
1691 else |
8523
ad3afaaa19c1
implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
1692 retval.maybe_economize (); |
ad3afaaa19c1
implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
1693 |
ad3afaaa19c1
implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
1694 return retval; |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8039
diff
changeset
|
1695 } |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8039
diff
changeset
|
1696 |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8039
diff
changeset
|
1697 void |
8523
ad3afaaa19c1
implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
1698 octave_value::make_storable_value (void) |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8039
diff
changeset
|
1699 { |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8039
diff
changeset
|
1700 if (is_null_value ()) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8039
diff
changeset
|
1701 { |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8039
diff
changeset
|
1702 octave_base_value *rc = rep->empty_clone (); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8039
diff
changeset
|
1703 if (--rep->count == 0) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8039
diff
changeset
|
1704 delete rep; |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8039
diff
changeset
|
1705 rep = rc; |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8039
diff
changeset
|
1706 } |
8523
ad3afaaa19c1
implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
1707 else |
ad3afaaa19c1
implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
1708 maybe_economize (); |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8039
diff
changeset
|
1709 } |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8039
diff
changeset
|
1710 |
4944 | 1711 int |
1712 octave_value::write (octave_stream& os, int block_size, | |
1713 oct_data_conv::data_type output_type, int skip, | |
1714 oct_mach_info::float_format flt_fmt) const | |
1715 { | |
1716 return rep->write (os, block_size, output_type, skip, flt_fmt); | |
1717 } | |
1718 | |
2413 | 1719 static void |
3933 | 1720 gripe_binary_op (const std::string& on, const std::string& tn1, |
1721 const std::string& tn2) | |
2376 | 1722 { |
2903 | 1723 error ("binary operator `%s' not implemented for `%s' by `%s' operations", |
2376 | 1724 on.c_str (), tn1.c_str (), tn2.c_str ()); |
1725 } | |
1726 | |
3203 | 1727 static void |
3523 | 1728 gripe_binary_op_conv (const std::string& on) |
3203 | 1729 { |
1730 error ("type conversion failed for binary operator `%s'", on.c_str ()); | |
1731 } | |
1732 | |
2376 | 1733 octave_value |
3933 | 1734 do_binary_op (octave_value::binary_op op, |
1735 const octave_value& v1, const octave_value& v2) | |
2376 | 1736 { |
1737 octave_value retval; | |
1738 | |
1739 int t1 = v1.type_id (); | |
1740 int t2 = v2.type_id (); | |
1741 | |
7336 | 1742 if (t1 == octave_class::static_type_id () |
1743 || t2 == octave_class::static_type_id ()) | |
1744 { | |
1745 octave_value_typeinfo::binary_class_op_fcn f | |
1746 = octave_value_typeinfo::lookup_binary_class_op (op); | |
2376 | 1747 |
7336 | 1748 if (f) |
7487
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1749 { |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1750 try |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1751 { |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1752 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
|
1753 } |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1754 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
|
1755 { |
8011
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7999
diff
changeset
|
1756 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
|
1757 } |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1758 } |
7336 | 1759 else |
1760 gripe_binary_op (octave_value::binary_op_as_string (op), | |
1761 v1.class_name (), v2.class_name ()); | |
1762 } | |
2376 | 1763 else |
1764 { | |
7336 | 1765 // FIXME -- we need to handle overloading operators for built-in |
1766 // classes (double, char, int8, etc.) | |
2376 | 1767 |
7336 | 1768 octave_value_typeinfo::binary_op_fcn f |
1769 = octave_value_typeinfo::lookup_binary_op (op, t1, t2); | |
1770 | |
1771 if (f) | |
7487
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1772 { |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1773 try |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1774 { |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1775 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
|
1776 } |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1777 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
|
1778 { |
8011
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7999
diff
changeset
|
1779 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
|
1780 } |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
1781 } |
7336 | 1782 else |
2376 | 1783 { |
7336 | 1784 octave_value tv1; |
8345
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1785 octave_base_value::type_conv_info cf1 = v1.numeric_conversion_function (); |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1786 |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1787 octave_value tv2; |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1788 octave_base_value::type_conv_info cf2 = v2.numeric_conversion_function (); |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1789 |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1790 // Try biased (one-sided) conversions first. |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1791 if (cf2.type_id () >= 0 && |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1792 octave_value_typeinfo::lookup_binary_op (op, t1, cf2.type_id ())) |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1793 cf1 = 0; |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1794 else if (cf1.type_id () >= 0 && |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1795 octave_value_typeinfo::lookup_binary_op (op, cf1.type_id (), t2)) |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1796 cf2 = 0; |
7336 | 1797 |
1798 if (cf1) | |
1799 { | |
1800 octave_base_value *tmp = cf1 (*v1.rep); | |
3203 | 1801 |
7336 | 1802 if (tmp) |
1803 { | |
1804 tv1 = octave_value (tmp); | |
1805 t1 = tv1.type_id (); | |
1806 } | |
1807 else | |
1808 { | |
1809 gripe_binary_op_conv (octave_value::binary_op_as_string (op)); | |
1810 return retval; | |
1811 } | |
3203 | 1812 } |
1813 else | |
7336 | 1814 tv1 = v1; |
1815 | |
1816 if (cf2) | |
3203 | 1817 { |
7336 | 1818 octave_base_value *tmp = cf2 (*v2.rep); |
2376 | 1819 |
7336 | 1820 if (tmp) |
1821 { | |
1822 tv2 = octave_value (tmp); | |
1823 t2 = tv2.type_id (); | |
1824 } | |
1825 else | |
1826 { | |
1827 gripe_binary_op_conv (octave_value::binary_op_as_string (op)); | |
1828 return retval; | |
1829 } | |
3203 | 1830 } |
1831 else | |
7336 | 1832 tv2 = v2; |
1833 | |
1834 if (cf1 || cf2) | |
3203 | 1835 { |
8345
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1836 retval = do_binary_op (op, tv1, tv2); |
7789
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 //demote double -> single and try again |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1841 cf1 = tv1.numeric_demotion_function (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1842 |
8345
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1843 cf2 = tv2.numeric_demotion_function (); |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1844 |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1845 // Try biased (one-sided) conversions first. |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1846 if (cf2.type_id () >= 0 |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1847 && octave_value_typeinfo::lookup_binary_op (op, t1, cf2.type_id ())) |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1848 cf1 = 0; |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1849 else if (cf1.type_id () >= 0 |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1850 && octave_value_typeinfo::lookup_binary_op (op, cf1.type_id (), t2)) |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1851 cf2 = 0; |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1852 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1853 if (cf1) |
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 octave_base_value *tmp = cf1 (*tv1.rep); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1856 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1857 if (tmp) |
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 tv1 = octave_value (tmp); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1860 t1 = tv1.type_id (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1861 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1862 else |
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 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
|
1865 return retval; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1866 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1867 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1868 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1869 if (cf2) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1870 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1871 octave_base_value *tmp = cf2 (*tv2.rep); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1872 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1873 if (tmp) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1874 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1875 tv2 = octave_value (tmp); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1876 t2 = tv2.type_id (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1877 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1878 else |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1879 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1880 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
|
1881 return retval; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1882 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1883 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1884 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1885 if (cf1 || cf2) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1886 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1887 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
|
1888 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1889 if (f) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1890 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1891 try |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1892 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1893 retval = f (*tv1.rep, *tv2.rep); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1894 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1895 catch (octave_execution_exception) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1896 { |
8011
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7999
diff
changeset
|
1897 gripe_library_execution_error (); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1898 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1899 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1900 else |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1901 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
|
1902 v1.type_name (), v2.type_name ()); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1903 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1904 else |
7336 | 1905 gripe_binary_op (octave_value::binary_op_as_string (op), |
1906 v1.type_name (), v2.type_name ()); | |
3203 | 1907 } |
2376 | 1908 } |
1909 } | |
1910 | |
1911 return retval; | |
1912 } | |
1913 | |
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
|
1914 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
|
1915 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
|
1916 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
|
1917 { |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1918 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
|
1919 |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1920 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
|
1921 { |
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 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
|
1923 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
|
1924 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
|
1925 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
|
1926 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
|
1927 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
|
1928 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
|
1929 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
|
1930 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
|
1931 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
|
1932 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
|
1933 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
|
1934 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
|
1935 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
|
1936 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
|
1937 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
|
1938 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
|
1939 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
|
1940 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
|
1941 break; |
8982
dc6bda6f9994
implement compound logical ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
1942 case octave_value::op_el_not_and: |
dc6bda6f9994
implement compound logical ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
1943 retval = do_binary_op (octave_value::op_el_and, |
dc6bda6f9994
implement compound logical ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
1944 do_unary_op (octave_value::op_not, v1), |
dc6bda6f9994
implement compound logical ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
1945 v2); |
dc6bda6f9994
implement compound logical ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
1946 break; |
dc6bda6f9994
implement compound logical ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
1947 case octave_value::op_el_not_or: |
dc6bda6f9994
implement compound logical ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
1948 retval = do_binary_op (octave_value::op_el_or, |
dc6bda6f9994
implement compound logical ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
1949 do_unary_op (octave_value::op_not, v1), |
dc6bda6f9994
implement compound logical ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
1950 v2); |
dc6bda6f9994
implement compound logical ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
1951 break; |
dc6bda6f9994
implement compound logical ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
1952 case octave_value::op_el_and_not: |
dc6bda6f9994
implement compound logical ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
1953 retval = do_binary_op (octave_value::op_el_and, |
dc6bda6f9994
implement compound logical ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
1954 v1, |
dc6bda6f9994
implement compound logical ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
1955 do_unary_op (octave_value::op_not, v2)); |
dc6bda6f9994
implement compound logical ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
1956 break; |
dc6bda6f9994
implement compound logical ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
1957 case octave_value::op_el_or_not: |
dc6bda6f9994
implement compound logical ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
1958 retval = do_binary_op (octave_value::op_el_or, |
dc6bda6f9994
implement compound logical ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
1959 v1, |
dc6bda6f9994
implement compound logical ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
1960 do_unary_op (octave_value::op_not, v2)); |
dc6bda6f9994
implement compound logical ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
1961 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
|
1962 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
|
1963 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
|
1964 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
|
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 |
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 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
|
1968 } |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1969 |
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 octave_value |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1971 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
|
1972 const octave_value& v1, const octave_value& v2) |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1973 { |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1974 octave_value retval; |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1975 |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1976 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
|
1977 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
|
1978 |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1979 if (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
|
1980 || 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
|
1981 { |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1982 octave_value_typeinfo::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
|
1983 = 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
|
1984 |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1985 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
|
1986 { |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1987 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
|
1988 { |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1989 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
|
1990 } |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1991 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
|
1992 { |
8011
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7999
diff
changeset
|
1993 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
|
1994 } |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1995 } |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1996 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
|
1997 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
|
1998 } |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
1999 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
|
2000 { |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
2001 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
|
2002 = 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
|
2003 |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
2004 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
|
2005 { |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
2006 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
|
2007 { |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
2008 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
|
2009 } |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
2010 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
|
2011 { |
8011
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7999
diff
changeset
|
2012 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
|
2013 } |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
2014 } |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
2015 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
|
2016 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
|
2017 } |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
2018 |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
2019 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
|
2020 } |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
2021 |
4915 | 2022 static void |
2023 gripe_cat_op (const std::string& tn1, const std::string& tn2) | |
2024 { | |
2025 error ("concatenation operator not implemented for `%s' by `%s' operations", | |
2026 tn1.c_str (), tn2.c_str ()); | |
2027 } | |
2028 | |
2029 static void | |
2030 gripe_cat_op_conv (void) | |
2031 { | |
2032 error ("type conversion failed for concatenation operator"); | |
2033 } | |
2034 | |
2035 octave_value | |
2036 do_cat_op (const octave_value& v1, const octave_value& v2, | |
6867 | 2037 const Array<octave_idx_type>& ra_idx) |
4915 | 2038 { |
2039 octave_value retval; | |
2040 | |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7800
diff
changeset
|
2041 // 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
|
2042 // something like cat(1,[],single([]) must return the correct type. |
5164 | 2043 |
4915 | 2044 int t1 = v1.type_id (); |
2045 int t2 = v2.type_id (); | |
2046 | |
5759 | 2047 octave_value_typeinfo::cat_op_fcn f |
2048 = octave_value_typeinfo::lookup_cat_op (t1, t2); | |
4915 | 2049 |
2050 if (f) | |
7487
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2051 { |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2052 try |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2053 { |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2054 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
|
2055 } |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2056 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
|
2057 { |
8011
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7999
diff
changeset
|
2058 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
|
2059 } |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2060 } |
4915 | 2061 else |
2062 { | |
2063 octave_value tv1; | |
8345
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
2064 octave_base_value::type_conv_info cf1 = v1.numeric_conversion_function (); |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
2065 |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
2066 octave_value tv2; |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
2067 octave_base_value::type_conv_info cf2 = v2.numeric_conversion_function (); |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
2068 |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
2069 // Try biased (one-sided) conversions first. |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
2070 if (cf2.type_id () >= 0 |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
2071 && octave_value_typeinfo::lookup_cat_op (t1, cf2.type_id ())) |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
2072 cf1 = 0; |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
2073 else if (cf1.type_id () >= 0 |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
2074 && octave_value_typeinfo::lookup_cat_op (cf1.type_id (), t2)) |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
2075 cf2 = 0; |
4915 | 2076 |
2077 if (cf1) | |
2078 { | |
5759 | 2079 octave_base_value *tmp = cf1 (*v1.rep); |
4915 | 2080 |
2081 if (tmp) | |
2082 { | |
2083 tv1 = octave_value (tmp); | |
2084 t1 = tv1.type_id (); | |
2085 } | |
2086 else | |
2087 { | |
2088 gripe_cat_op_conv (); | |
2089 return retval; | |
2090 } | |
2091 } | |
2092 else | |
2093 tv1 = v1; | |
2094 | |
2095 if (cf2) | |
2096 { | |
5759 | 2097 octave_base_value *tmp = cf2 (*v2.rep); |
4915 | 2098 |
2099 if (tmp) | |
2100 { | |
2101 tv2 = octave_value (tmp); | |
2102 t2 = tv2.type_id (); | |
2103 } | |
2104 else | |
2105 { | |
2106 gripe_cat_op_conv (); | |
2107 return retval; | |
2108 } | |
2109 } | |
2110 else | |
2111 tv2 = v2; | |
2112 | |
2113 if (cf1 || cf2) | |
2114 { | |
8345
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
2115 retval = do_cat_op (tv1, tv2, ra_idx); |
4915 | 2116 } |
2117 else | |
2118 gripe_cat_op (v1.type_name (), v2.type_name ()); | |
2119 } | |
2120 | |
2121 return retval; | |
2122 } | |
2123 | |
3933 | 2124 void |
2125 octave_value::print_info (std::ostream& os, const std::string& prefix) const | |
2126 { | |
2127 os << prefix << "type_name: " << type_name () << "\n" | |
2128 << prefix << "count: " << get_count () << "\n" | |
2129 << prefix << "rep info: "; | |
2130 | |
2131 rep->print_info (os, prefix + " "); | |
2132 } | |
2133 | |
3203 | 2134 static void |
3523 | 2135 gripe_unary_op (const std::string& on, const std::string& tn) |
3203 | 2136 { |
2137 error ("unary operator `%s' not implemented for `%s' operands", | |
2138 on.c_str (), tn.c_str ()); | |
2139 } | |
2140 | |
2141 static void | |
3523 | 2142 gripe_unary_op_conv (const std::string& on) |
3203 | 2143 { |
2144 error ("type conversion failed for unary operator `%s'", on.c_str ()); | |
2145 } | |
2146 | |
2147 octave_value | |
2148 do_unary_op (octave_value::unary_op op, const octave_value& v) | |
2149 { | |
2150 octave_value retval; | |
2151 | |
2152 int t = v.type_id (); | |
2153 | |
7336 | 2154 if (t == octave_class::static_type_id ()) |
2155 { | |
2156 octave_value_typeinfo::unary_class_op_fcn f | |
2157 = octave_value_typeinfo::lookup_unary_class_op (op); | |
3203 | 2158 |
7336 | 2159 if (f) |
7487
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2160 { |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2161 try |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2162 { |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2163 retval = f (v); |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2164 } |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2165 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
|
2166 { |
8011
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7999
diff
changeset
|
2167 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
|
2168 } |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2169 } |
7336 | 2170 else |
2171 gripe_unary_op (octave_value::unary_op_as_string (op), | |
2172 v.class_name ()); | |
2173 } | |
3203 | 2174 else |
2175 { | |
7336 | 2176 // FIXME -- we need to handle overloading operators for built-in |
2177 // classes (double, char, int8, etc.) | |
2178 | |
2179 octave_value_typeinfo::unary_op_fcn f | |
2180 = octave_value_typeinfo::lookup_unary_op (op, t); | |
3203 | 2181 |
7336 | 2182 if (f) |
7487
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2183 { |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2184 try |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2185 { |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2186 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
|
2187 } |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2188 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
|
2189 { |
8011
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7999
diff
changeset
|
2190 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
|
2191 } |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2192 } |
7336 | 2193 else |
3203 | 2194 { |
7336 | 2195 octave_value tv; |
2196 octave_base_value::type_conv_fcn cf | |
2197 = v.numeric_conversion_function (); | |
3203 | 2198 |
7336 | 2199 if (cf) |
3203 | 2200 { |
7336 | 2201 octave_base_value *tmp = cf (*v.rep); |
3203 | 2202 |
7336 | 2203 if (tmp) |
2204 { | |
2205 tv = octave_value (tmp); | |
8345
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
2206 retval = do_unary_op (op, tv); |
7336 | 2207 } |
3203 | 2208 else |
7336 | 2209 gripe_unary_op_conv (octave_value::unary_op_as_string (op)); |
3203 | 2210 } |
2211 else | |
7336 | 2212 gripe_unary_op (octave_value::unary_op_as_string (op), |
2213 v.type_name ()); | |
3203 | 2214 } |
2215 } | |
2216 | |
2217 return retval; | |
2218 } | |
2219 | |
2220 static void | |
3933 | 2221 gripe_unary_op_conversion_failed (const std::string& op, |
2222 const std::string& tn) | |
3203 | 2223 { |
2224 error ("operator %s: type conversion for `%s' failed", | |
2225 op.c_str (), tn.c_str ()); | |
2226 } | |
2227 | |
3933 | 2228 const octave_value& |
2229 octave_value::do_non_const_unary_op (unary_op op) | |
3203 | 2230 { |
2231 octave_value retval; | |
2232 | |
2233 int t = type_id (); | |
2234 | |
5759 | 2235 octave_value_typeinfo::non_const_unary_op_fcn f |
3203 | 2236 = octave_value_typeinfo::lookup_non_const_unary_op (op, t); |
2237 | |
2238 if (f) | |
2239 { | |
2240 make_unique (); | |
2241 | |
7487
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2242 try |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2243 { |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2244 f (*rep); |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2245 } |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2246 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
|
2247 { |
8011
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7999
diff
changeset
|
2248 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
|
2249 } |
3203 | 2250 } |
2251 else | |
2252 { | |
5759 | 2253 octave_base_value::type_conv_fcn cf = numeric_conversion_function (); |
3203 | 2254 |
2255 if (cf) | |
2256 { | |
5759 | 2257 octave_base_value *tmp = cf (*rep); |
3203 | 2258 |
2259 if (tmp) | |
2260 { | |
5759 | 2261 octave_base_value *old_rep = rep; |
3203 | 2262 rep = tmp; |
2263 | |
2264 t = type_id (); | |
2265 | |
2266 f = octave_value_typeinfo::lookup_non_const_unary_op (op, t); | |
2267 | |
2268 if (f) | |
2269 { | |
7487
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2270 try |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2271 { |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2272 f (*rep); |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2273 } |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2274 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
|
2275 { |
8011
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7999
diff
changeset
|
2276 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
|
2277 } |
3203 | 2278 |
2279 if (old_rep && --old_rep->count == 0) | |
2280 delete old_rep; | |
2281 } | |
2282 else | |
2283 { | |
2284 if (old_rep) | |
2285 { | |
2286 if (--rep->count == 0) | |
2287 delete rep; | |
2288 | |
2289 rep = old_rep; | |
2290 } | |
2291 | |
2292 gripe_unary_op (octave_value::unary_op_as_string (op), | |
2293 type_name ()); | |
2294 } | |
2295 } | |
2296 else | |
2297 gripe_unary_op_conversion_failed | |
2298 (octave_value::unary_op_as_string (op), type_name ()); | |
2299 } | |
2300 else | |
2301 gripe_unary_op (octave_value::unary_op_as_string (op), type_name ()); | |
2302 } | |
3933 | 2303 |
2304 return *this; | |
3203 | 2305 } |
2306 | |
3933 | 2307 #if 0 |
3205 | 2308 static void |
3933 | 2309 gripe_unary_op_failed_or_no_method (const std::string& on, |
2310 const std::string& tn) | |
3205 | 2311 { |
2312 error ("operator %s: no method, or unable to evaluate for %s operand", | |
2313 on.c_str (), tn.c_str ()); | |
2314 } | |
3933 | 2315 #endif |
3205 | 2316 |
2317 void | |
4661 | 2318 octave_value::do_non_const_unary_op (unary_op, const octave_value_list&) |
3205 | 2319 { |
3933 | 2320 abort (); |
2321 } | |
2322 | |
2323 octave_value | |
4247 | 2324 octave_value::do_non_const_unary_op (unary_op op, const std::string& type, |
4219 | 2325 const std::list<octave_value_list>& idx) |
3933 | 2326 { |
2327 octave_value retval; | |
2328 | |
2329 if (idx.empty ()) | |
2330 { | |
2331 do_non_const_unary_op (op); | |
3205 | 2332 |
3933 | 2333 retval = *this; |
2334 } | |
2335 else | |
2336 { | |
5775 | 2337 // FIXME -- only do the following stuff if we can't find a |
3933 | 2338 // specific function to call to handle the op= operation for the |
2339 // types we have. | |
3205 | 2340 |
3933 | 2341 assign_op assop = unary_op_to_assign_op (op); |
2342 | |
2343 retval = assign (assop, type, idx, 1.0); | |
2344 } | |
2345 | |
2346 return retval; | |
3205 | 2347 } |
2348 | |
2349 octave_value::assign_op | |
2350 octave_value::unary_op_to_assign_op (unary_op op) | |
2351 { | |
2352 assign_op binop = unknown_assign_op; | |
2353 | |
2354 switch (op) | |
2355 { | |
3533 | 2356 case op_incr: |
2357 binop = op_add_eq; | |
3205 | 2358 break; |
2359 | |
3533 | 2360 case op_decr: |
2361 binop = op_sub_eq; | |
3205 | 2362 break; |
2363 | |
2364 default: | |
2365 { | |
3523 | 2366 std::string on = unary_op_as_string (op); |
3205 | 2367 error ("operator %s: no assign operator found", on.c_str ()); |
2368 } | |
2369 } | |
2370 | |
2371 return binop; | |
2372 } | |
2373 | |
3204 | 2374 octave_value::binary_op |
2375 octave_value::op_eq_to_binary_op (assign_op op) | |
2376 { | |
2377 binary_op binop = unknown_binary_op; | |
2378 | |
2379 switch (op) | |
2380 { | |
3533 | 2381 case op_add_eq: |
2382 binop = op_add; | |
3204 | 2383 break; |
2384 | |
3533 | 2385 case op_sub_eq: |
2386 binop = op_sub; | |
3204 | 2387 break; |
2388 | |
3533 | 2389 case op_mul_eq: |
2390 binop = op_mul; | |
3204 | 2391 break; |
2392 | |
3533 | 2393 case op_div_eq: |
2394 binop = op_div; | |
3204 | 2395 break; |
2396 | |
3533 | 2397 case op_ldiv_eq: |
2398 binop = op_ldiv; | |
3204 | 2399 break; |
2400 | |
4018 | 2401 case op_pow_eq: |
2402 binop = op_pow; | |
2403 break; | |
2404 | |
3533 | 2405 case op_lshift_eq: |
2406 binop = op_lshift; | |
3204 | 2407 break; |
2408 | |
3533 | 2409 case op_rshift_eq: |
2410 binop = op_rshift; | |
3204 | 2411 break; |
2412 | |
3533 | 2413 case op_el_mul_eq: |
2414 binop = op_el_mul; | |
3204 | 2415 break; |
2416 | |
3533 | 2417 case op_el_div_eq: |
2418 binop = op_el_div; | |
3204 | 2419 break; |
2420 | |
3533 | 2421 case op_el_ldiv_eq: |
2422 binop = op_el_ldiv; | |
3204 | 2423 break; |
2424 | |
4018 | 2425 case op_el_pow_eq: |
2426 binop = op_el_pow; | |
2427 break; | |
2428 | |
3533 | 2429 case op_el_and_eq: |
2430 binop = op_el_and; | |
3204 | 2431 break; |
2432 | |
3533 | 2433 case op_el_or_eq: |
2434 binop = op_el_or; | |
3204 | 2435 break; |
2436 | |
2437 default: | |
2438 { | |
3523 | 2439 std::string on = assign_op_as_string (op); |
3204 | 2440 error ("operator %s: no binary operator found", on.c_str ()); |
2441 } | |
2442 } | |
2443 | |
2444 return binop; | |
2445 } | |
2446 | |
3933 | 2447 octave_value |
2448 octave_value::empty_conv (const std::string& type, const octave_value& rhs) | |
2449 { | |
2450 octave_value retval; | |
2451 | |
2452 if (type.length () > 0) | |
2453 { | |
2454 switch (type[0]) | |
2455 { | |
2456 case '(': | |
2457 { | |
2458 if (type.length () > 1 && type[1] == '.') | |
2459 retval = Octave_map (); | |
2460 else | |
2461 retval = octave_value (rhs.empty_clone ()); | |
2462 } | |
2463 break; | |
2464 | |
2465 case '{': | |
2466 retval = Cell (); | |
2467 break; | |
2468 | |
2469 case '.': | |
2470 retval = Octave_map (); | |
2471 break; | |
2472 | |
2473 default: | |
2474 panic_impossible (); | |
2475 } | |
2476 } | |
2477 else | |
2478 retval = octave_value (rhs.empty_clone ()); | |
2479 | |
2480 return retval; | |
2481 } | |
2482 | |
2376 | 2483 void |
2484 install_types (void) | |
2485 { | |
2486 octave_base_value::register_type (); | |
3928 | 2487 octave_cell::register_type (); |
2376 | 2488 octave_scalar::register_type (); |
2489 octave_complex::register_type (); | |
2490 octave_matrix::register_type (); | |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8346
diff
changeset
|
2491 octave_diag_matrix::register_type (); |
2376 | 2492 octave_complex_matrix::register_type (); |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8346
diff
changeset
|
2493 octave_complex_diag_matrix::register_type (); |
2376 | 2494 octave_range::register_type (); |
2825 | 2495 octave_bool::register_type (); |
2496 octave_bool_matrix::register_type (); | |
2376 | 2497 octave_char_matrix::register_type (); |
2498 octave_char_matrix_str::register_type (); | |
5279 | 2499 octave_char_matrix_sq_str::register_type (); |
4901 | 2500 octave_int8_scalar::register_type (); |
2501 octave_int16_scalar::register_type (); | |
2502 octave_int32_scalar::register_type (); | |
2503 octave_int64_scalar::register_type (); | |
2504 octave_uint8_scalar::register_type (); | |
2505 octave_uint16_scalar::register_type (); | |
2506 octave_uint32_scalar::register_type (); | |
2507 octave_uint64_scalar::register_type (); | |
2508 octave_int8_matrix::register_type (); | |
2509 octave_int16_matrix::register_type (); | |
2510 octave_int32_matrix::register_type (); | |
2511 octave_int64_matrix::register_type (); | |
2512 octave_uint8_matrix::register_type (); | |
2513 octave_uint16_matrix::register_type (); | |
2514 octave_uint32_matrix::register_type (); | |
2515 octave_uint64_matrix::register_type (); | |
5164 | 2516 octave_sparse_bool_matrix::register_type (); |
2517 octave_sparse_matrix::register_type (); | |
2518 octave_sparse_complex_matrix::register_type (); | |
2376 | 2519 octave_struct::register_type (); |
7336 | 2520 octave_class::register_type (); |
2880 | 2521 octave_list::register_type (); |
3977 | 2522 octave_cs_list::register_type (); |
2376 | 2523 octave_magic_colon::register_type (); |
2974 | 2524 octave_builtin::register_type (); |
2525 octave_user_function::register_type (); | |
4649 | 2526 octave_dld_function::register_type (); |
4643 | 2527 octave_fcn_handle::register_type (); |
4966 | 2528 octave_fcn_inline::register_type (); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
2529 octave_float_scalar::register_type (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
2530 octave_float_complex::register_type (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
2531 octave_float_matrix::register_type (); |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8346
diff
changeset
|
2532 octave_float_diag_matrix::register_type (); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
2533 octave_float_complex_matrix::register_type (); |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8346
diff
changeset
|
2534 octave_float_complex_diag_matrix::register_type (); |
8367
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
2535 octave_perm_matrix::register_type (); |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8039
diff
changeset
|
2536 octave_null_matrix::register_type (); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8039
diff
changeset
|
2537 octave_null_str::register_type (); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8039
diff
changeset
|
2538 octave_null_sq_str::register_type (); |
2376 | 2539 } |
2540 | |
4970 | 2541 #if 0 |
2542 DEFUN (cast, args, , | |
2543 "-*- texinfo -*-\n\ | |
2544 @deftypefn {Built-in Function} {} cast (@var{val}, @var{type})\n\ | |
2545 Convert @var{val} to the new data type @var{type}.\n\ | |
5642 | 2546 @seealso{class, typeinfo}\n\ |
2547 @end deftypefn") | |
4970 | 2548 { |
2549 octave_value retval; | |
2550 | |
2551 if (args.length () == 2) | |
2552 error ("cast: not implemented"); | |
2553 else | |
5823 | 2554 print_usage (); |
4970 | 2555 |
2556 return retval; | |
2557 } | |
2558 #endif | |
2559 | |
4791 | 2560 DEFUN (sizeof, args, , |
2561 "-*- texinfo -*-\n\ | |
2562 @deftypefn {Built-in Function} {} sizeof (@var{val})\n\ | |
2563 Return the size of @var{val} in bytes\n\ | |
2564 @end deftypefn") | |
2565 { | |
2566 octave_value retval; | |
2567 | |
2568 if (args.length () == 1) | |
2569 retval = args(0).byte_size (); | |
2570 else | |
5823 | 2571 print_usage (); |
4791 | 2572 |
2573 return retval; | |
2574 } | |
2575 | |
6153 | 2576 static void |
2577 decode_subscripts (const char* name, const octave_value& arg, | |
2578 std::string& type_string, | |
2579 std::list<octave_value_list>& idx) | |
2580 { | |
2581 Octave_map m = arg.map_value (); | |
2582 | |
2583 if (! error_state | |
6639 | 2584 && m.nfields () == 2 && m.contains ("type") && m.contains ("subs")) |
6153 | 2585 { |
2586 Cell& type = m.contents ("type"); | |
2587 Cell& subs = m.contents ("subs"); | |
2588 | |
2589 type_string = std::string (type.length(), '\0'); | |
2590 | |
2591 for (int k = 0; k < type.length (); k++) | |
2592 { | |
2593 std::string item = type(k).string_value (); | |
2594 | |
2595 if (! error_state) | |
2596 { | |
2597 if (item == "{}") | |
2598 type_string[k] = '{'; | |
2599 else if (item == "()") | |
2600 type_string[k] = '('; | |
2601 else if (item == ".") | |
2602 type_string[k] = '.'; | |
2603 else | |
2604 { | |
2605 error("%s: invalid indexing type `%s'", name, item.c_str ()); | |
2606 return; | |
2607 } | |
2608 } | |
2609 else | |
2610 { | |
2611 error ("%s: expecting type(%d) to be a character string", | |
2612 name, k+1); | |
2613 return; | |
2614 } | |
2615 | |
2616 octave_value_list idx_item; | |
2617 | |
2618 if (subs(k).is_string ()) | |
2619 idx_item(0) = subs(k); | |
2620 else if (subs(k).is_cell ()) | |
2621 { | |
2622 Cell subs_cell = subs(k).cell_value (); | |
2623 | |
2624 for (int n = 0; n < subs_cell.length (); n++) | |
2625 { | |
2626 if (subs_cell(n).is_string () | |
2627 && subs_cell(n).string_value () == ":") | |
2628 idx_item(n) = octave_value(octave_value::magic_colon_t); | |
2629 else | |
2630 idx_item(n) = subs_cell(n); | |
2631 } | |
2632 } | |
2633 else | |
2634 { | |
2635 error ("%s: expecting subs(%d) to be a character string or cell array", | |
2636 name, k+1); | |
2637 return; | |
2638 } | |
2639 | |
2640 idx.push_back (idx_item); | |
2641 } | |
2642 } | |
2643 else | |
2644 error ("%s: second argument must be a structure with fields `type' and `subs'", name); | |
2645 } | |
2646 | |
2647 DEFUN (subsref, args, nargout, | |
2648 "-*- texinfo -*-\n\ | |
2649 @deftypefn {Built-in Function} {} subsref (@var{val}, @var{idx})\n\ | |
2650 Perform the subscripted element selection operation according to\n\ | |
2651 the subscript specified by @var{idx}.\n\ | |
2652 \n\ | |
2653 The subscript @var{idx} is expected to be a structure array with\n\ | |
2654 fields @samp{type} and @samp{subs}. Valid values for @samp{type}\n\ | |
6550 | 2655 are @samp{\"()\"}, @samp{\"@{@}\"}, and @samp{\".\"}.\n\ |
6153 | 2656 The @samp{subs} field may be either @samp{\":\"} or a cell array\n\ |
2657 of index values.\n\ | |
6631 | 2658 \n\ |
2659 The following example shows how to extract the two first columns of\n\ | |
2660 a matrix\n\ | |
2661 \n\ | |
2662 @example\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8992
diff
changeset
|
2663 @group\n\ |
6631 | 2664 val = magic(3)\n\ |
2665 @result{} val = [ 8 1 6\n\ | |
2666 3 5 7\n\ | |
2667 4 9 2 ]\n\ | |
2668 idx.type = \"()\";\n\ | |
2669 idx.subs = @{\":\", 1:2@};\n\ | |
2670 subsref(val, idx)\n\ | |
2671 @result{} [ 8 1 \n\ | |
2672 3 5 \n\ | |
2673 4 9 ]\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8992
diff
changeset
|
2674 @end group\n\ |
6631 | 2675 @end example\n\ |
2676 \n\ | |
2677 @noindent\n\ | |
2678 Note that this is the same as writing @code{val(:,1:2)}.\n\ | |
6157 | 2679 @seealso{subsasgn, substruct}\n\ |
6153 | 2680 @end deftypefn") |
2681 { | |
2682 octave_value_list retval; | |
2683 | |
2684 if (args.length () == 2) | |
2685 { | |
2686 std::string type; | |
2687 std::list<octave_value_list> idx; | |
2688 | |
2689 decode_subscripts ("subsref", args(1), type, idx); | |
2690 | |
2691 if (! error_state) | |
2692 retval = args(0).subsref (type, idx, nargout); | |
2693 } | |
2694 else | |
2695 print_usage (); | |
2696 | |
2697 return retval; | |
2698 } | |
2699 | |
2700 DEFUN (subsasgn, args, , | |
2701 "-*- texinfo -*-\n\ | |
2702 @deftypefn {Built-in Function} {} subsasgn (@var{val}, @var{idx}, @var{rhs})\n\ | |
2703 Perform the subscripted assignment operation according to\n\ | |
2704 the subscript specified by @var{idx}.\n\ | |
2705 \n\ | |
2706 The subscript @var{idx} is expected to be a structure array with\n\ | |
2707 fields @samp{type} and @samp{subs}. Valid values for @samp{type}\n\ | |
6248 | 2708 are @samp{\"()\"}, @samp{\"@{@}\"}, and @samp{\".\"}.\n\ |
6153 | 2709 The @samp{subs} field may be either @samp{\":\"} or a cell array\n\ |
2710 of index values.\n\ | |
6631 | 2711 \n\ |
2712 The following example shows how to set the two first columns of a\n\ | |
2713 3-by-3 matrix to zero.\n\ | |
2714 \n\ | |
2715 @example\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8992
diff
changeset
|
2716 @group\n\ |
6631 | 2717 val = magic(3);\n\ |
2718 idx.type = \"()\";\n\ | |
2719 idx.subs = @{\":\", 1:2@};\n\ | |
2720 subsasgn (val, idx, 0)\n\ | |
2721 @result{} [ 0 0 6\n\ | |
2722 0 0 7\n\ | |
2723 0 0 2 ]\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8992
diff
changeset
|
2724 @end group\n\ |
6631 | 2725 @end example\n\ |
2726 \n\ | |
2727 Note that this is the same as writing @code{val(:,1:2) = 0}.\n\ | |
6157 | 2728 @seealso{subsref, substruct}\n\ |
6153 | 2729 @end deftypefn") |
2730 { | |
2731 octave_value retval; | |
2732 | |
2733 if (args.length () == 3) | |
2734 { | |
2735 std::string type; | |
2736 std::list<octave_value_list> idx; | |
2737 | |
2738 decode_subscripts ("subsasgn", args(1), type, idx); | |
2739 | |
9368
ff612fdaee95
properly unshare variable in subsasgn
Jaroslav Hajek <highegg@gmail.com>
parents:
9351
diff
changeset
|
2740 octave_value arg0 = args(0); |
ff612fdaee95
properly unshare variable in subsasgn
Jaroslav Hajek <highegg@gmail.com>
parents:
9351
diff
changeset
|
2741 |
ff612fdaee95
properly unshare variable in subsasgn
Jaroslav Hajek <highegg@gmail.com>
parents:
9351
diff
changeset
|
2742 arg0.make_unique (); |
ff612fdaee95
properly unshare variable in subsasgn
Jaroslav Hajek <highegg@gmail.com>
parents:
9351
diff
changeset
|
2743 |
6153 | 2744 if (! error_state) |
9368
ff612fdaee95
properly unshare variable in subsasgn
Jaroslav Hajek <highegg@gmail.com>
parents:
9351
diff
changeset
|
2745 retval = arg0.subsasgn (type, idx, args(2)); |
6153 | 2746 } |
2747 else | |
2748 print_usage (); | |
2749 | |
2750 return retval; | |
2751 } | |
2752 | |
2376 | 2753 /* |
2754 ;;; Local Variables: *** | |
2755 ;;; mode: C++ *** | |
2756 ;;; End: *** | |
2757 */ |