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