Mercurial > octave-antonio
annotate src/ov.cc @ 13932:6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
* ov.cc (decode_subscripts): Move here.
* utils.cc: From here.
* utils.h: Delete decl.
* ov.cc (decode_subscripts): Empty type_string and idx and return
early if map is empty with fields type and subs.
(Fsubsref): Return VAL if subscript struct is empty.
(Fsubsasgn): Return RHS if subscript struct is empty.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 23 Nov 2011 02:35:37 -0500 |
parents | 605729cc5bbf |
children | 1734ebe27134 |
rev | line source |
---|---|
2376 | 1 /* |
2 | |
11523 | 3 Copyright (C) 1996-2011 John W. Eaton |
4 Copyright (C) 2009-2010 VZLU Prague | |
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" |
3977 | 68 #include "ov-cs-list.h" |
2376 | 69 #include "ov-colon.h" |
2974 | 70 #include "ov-builtin.h" |
4649 | 71 #include "ov-dld-fcn.h" |
2974 | 72 #include "ov-usr-fcn.h" |
4342 | 73 #include "ov-fcn-handle.h" |
4966 | 74 #include "ov-fcn-inline.h" |
2376 | 75 #include "ov-typeinfo.h" |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8039
diff
changeset
|
76 #include "ov-null-mat.h" |
10325
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
77 #include "ov-lazy-idx.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 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
584 ? dynamic_cast<octave_base_value *> (new octave_cs_list (c)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
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 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
591 ? dynamic_cast<octave_base_value *> (new octave_cs_list (Cell (a))) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
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 == '"' | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
783 ? new octave_char_matrix_dq_str (c) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
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 == '"' | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
791 ? new octave_char_matrix_dq_str (s) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
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 == '"' | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
799 ? new octave_char_matrix_dq_str (s) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
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 == '"' | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
807 ? new octave_char_matrix_dq_str (s) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
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 == '"' |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
815 ? new octave_char_matrix_dq_str (chm) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
816 : new octave_char_matrix_sq_str (chm)) |
9689
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 == '"' |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
823 ? new octave_char_matrix_dq_str (chm) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
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 == '"' |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
831 ? new octave_char_matrix_dq_str (chm) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
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 == '"' |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
839 ? new octave_char_matrix_dq_str (chm) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
840 : new octave_char_matrix_sq_str (chm)) |
9689
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 == '"' |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
847 ? new octave_char_matrix_dq_str (chm) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
848 : new octave_char_matrix_sq_str (chm)) |
9689
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 == '"' |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
855 ? new octave_char_matrix_dq_str (chm) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
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 |
10325
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1048 octave_value::octave_value (const idx_vector& idx, bool lazy) |
9479
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 |
10325
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1057 if (lazy) |
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1058 { |
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1059 // Only make lazy indices out of ranges and index vectors. |
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1060 switch (idx.idx_class ()) |
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1061 { |
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1062 case idx_vector::class_range: |
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1063 case idx_vector::class_vector: |
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1064 rep = new octave_lazy_index (idx); |
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1065 maybe_mutate (); |
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1066 return; |
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1067 default: |
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1068 break; |
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1069 } |
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1070 } |
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1071 |
9894
83bd7f34f9da
improve idx_vector->octave_value conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
9879
diff
changeset
|
1072 idx.unconvert (idx_class, scalar, range, array, mask); |
9479
d9716e3ee0dd
supply optimized compiled sub2ind & ind2sub
Jaroslav Hajek <highegg@gmail.com>
parents:
9368
diff
changeset
|
1073 |
d9716e3ee0dd
supply optimized compiled sub2ind & ind2sub
Jaroslav Hajek <highegg@gmail.com>
parents:
9368
diff
changeset
|
1074 switch (idx_class) |
d9716e3ee0dd
supply optimized compiled sub2ind & ind2sub
Jaroslav Hajek <highegg@gmail.com>
parents:
9368
diff
changeset
|
1075 { |
d9716e3ee0dd
supply optimized compiled sub2ind & ind2sub
Jaroslav Hajek <highegg@gmail.com>
parents:
9368
diff
changeset
|
1076 case idx_vector::class_colon: |
d9716e3ee0dd
supply optimized compiled sub2ind & ind2sub
Jaroslav Hajek <highegg@gmail.com>
parents:
9368
diff
changeset
|
1077 rep = new octave_magic_colon (); |
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 case idx_vector::class_range: |
9894
83bd7f34f9da
improve idx_vector->octave_value conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
9879
diff
changeset
|
1080 rep = new octave_range (range, idx); |
9479
d9716e3ee0dd
supply optimized compiled sub2ind & ind2sub
Jaroslav Hajek <highegg@gmail.com>
parents:
9368
diff
changeset
|
1081 break; |
d9716e3ee0dd
supply optimized compiled sub2ind & ind2sub
Jaroslav Hajek <highegg@gmail.com>
parents:
9368
diff
changeset
|
1082 case idx_vector::class_scalar: |
d9716e3ee0dd
supply optimized compiled sub2ind & ind2sub
Jaroslav Hajek <highegg@gmail.com>
parents:
9368
diff
changeset
|
1083 rep = new octave_scalar (scalar); |
d9716e3ee0dd
supply optimized compiled sub2ind & ind2sub
Jaroslav Hajek <highegg@gmail.com>
parents:
9368
diff
changeset
|
1084 break; |
d9716e3ee0dd
supply optimized compiled sub2ind & ind2sub
Jaroslav Hajek <highegg@gmail.com>
parents:
9368
diff
changeset
|
1085 case idx_vector::class_vector: |
9894
83bd7f34f9da
improve idx_vector->octave_value conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
9879
diff
changeset
|
1086 rep = new octave_matrix (array, idx); |
83bd7f34f9da
improve idx_vector->octave_value conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
9879
diff
changeset
|
1087 break; |
83bd7f34f9da
improve idx_vector->octave_value conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
9879
diff
changeset
|
1088 case idx_vector::class_mask: |
83bd7f34f9da
improve idx_vector->octave_value conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
9879
diff
changeset
|
1089 rep = new octave_bool_matrix (mask, idx); |
9479
d9716e3ee0dd
supply optimized compiled sub2ind & ind2sub
Jaroslav Hajek <highegg@gmail.com>
parents:
9368
diff
changeset
|
1090 break; |
d9716e3ee0dd
supply optimized compiled sub2ind & ind2sub
Jaroslav Hajek <highegg@gmail.com>
parents:
9368
diff
changeset
|
1091 default: |
d9716e3ee0dd
supply optimized compiled sub2ind & ind2sub
Jaroslav Hajek <highegg@gmail.com>
parents:
9368
diff
changeset
|
1092 assert (false); |
d9716e3ee0dd
supply optimized compiled sub2ind & ind2sub
Jaroslav Hajek <highegg@gmail.com>
parents:
9368
diff
changeset
|
1093 break; |
d9716e3ee0dd
supply optimized compiled sub2ind & ind2sub
Jaroslav Hajek <highegg@gmail.com>
parents:
9368
diff
changeset
|
1094 } |
d9716e3ee0dd
supply optimized compiled sub2ind & ind2sub
Jaroslav Hajek <highegg@gmail.com>
parents:
9368
diff
changeset
|
1095 |
d9716e3ee0dd
supply optimized compiled sub2ind & ind2sub
Jaroslav Hajek <highegg@gmail.com>
parents:
9368
diff
changeset
|
1096 // FIXME: needed? |
d9716e3ee0dd
supply optimized compiled sub2ind & ind2sub
Jaroslav Hajek <highegg@gmail.com>
parents:
9368
diff
changeset
|
1097 maybe_mutate (); |
d9716e3ee0dd
supply optimized compiled sub2ind & ind2sub
Jaroslav Hajek <highegg@gmail.com>
parents:
9368
diff
changeset
|
1098 } |
d9716e3ee0dd
supply optimized compiled sub2ind & ind2sub
Jaroslav Hajek <highegg@gmail.com>
parents:
9368
diff
changeset
|
1099 |
9725 | 1100 octave_value::octave_value (const Array<std::string>& cellstr) |
1101 : rep (new octave_cell (cellstr)) | |
1102 { | |
1103 maybe_mutate (); | |
1104 } | |
1105 | |
2376 | 1106 octave_value::octave_value (double base, double limit, double inc) |
2423 | 1107 : rep (new octave_range (base, limit, inc)) |
1108 { | |
1109 maybe_mutate (); | |
1110 } | |
2376 | 1111 |
1112 octave_value::octave_value (const Range& r) | |
2423 | 1113 : rep (new octave_range (r)) |
1114 { | |
1115 maybe_mutate (); | |
1116 } | |
2376 | 1117 |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10687
diff
changeset
|
1118 octave_value::octave_value (const octave_map& m) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10687
diff
changeset
|
1119 : rep (new octave_struct (m)) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10687
diff
changeset
|
1120 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10687
diff
changeset
|
1121 maybe_mutate (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10687
diff
changeset
|
1122 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10687
diff
changeset
|
1123 |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10687
diff
changeset
|
1124 octave_value::octave_value (const octave_scalar_map& m) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10687
diff
changeset
|
1125 : rep (new octave_scalar_struct (m)) |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10687
diff
changeset
|
1126 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10687
diff
changeset
|
1127 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10687
diff
changeset
|
1128 |
2376 | 1129 octave_value::octave_value (const Octave_map& m) |
2825 | 1130 : rep (new octave_struct (m)) |
1131 { | |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10687
diff
changeset
|
1132 maybe_mutate (); |
2880 | 1133 } |
1134 | |
13294
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13101
diff
changeset
|
1135 octave_value::octave_value (const Octave_map& m, const std::string& id, |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13101
diff
changeset
|
1136 const std::list<std::string>& plist) |
7dce7e110511
make concatenation of class objects work
John W. Eaton <jwe@octave.org>
parents:
13101
diff
changeset
|
1137 : rep (new octave_class (m, id, plist)) |
7336 | 1138 { |
1139 } | |
1140 | |
10232
0efd486813fe
remove deprecated list datatype
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
1141 octave_value::octave_value (const octave_value_list& l, bool) |
0efd486813fe
remove deprecated list datatype
Jaroslav Hajek <highegg@gmail.com>
parents:
10160
diff
changeset
|
1142 : rep (new octave_cs_list (l)) |
2880 | 1143 { |
1144 } | |
2376 | 1145 |
1146 octave_value::octave_value (octave_value::magic_colon) | |
2825 | 1147 : rep (new octave_magic_colon ()) |
1148 { | |
1149 } | |
2376 | 1150 |
9728
70925b11ba46
again allow the obsolete syntax for cellfun
Jaroslav Hajek <highegg@gmail.com>
parents:
9725
diff
changeset
|
1151 octave_value::octave_value (octave_base_value *new_rep, bool borrow) |
2825 | 1152 : rep (new_rep) |
1153 { | |
9728
70925b11ba46
again allow the obsolete syntax for cellfun
Jaroslav Hajek <highegg@gmail.com>
parents:
9725
diff
changeset
|
1154 if (borrow) |
70925b11ba46
again allow the obsolete syntax for cellfun
Jaroslav Hajek <highegg@gmail.com>
parents:
9725
diff
changeset
|
1155 rep->count++; |
2825 | 1156 } |
2376 | 1157 |
7336 | 1158 octave_value::octave_value (octave_base_value *new_rep, int xcount) |
1159 : rep (new_rep) | |
1160 { | |
1161 rep->count = xcount; | |
1162 } | |
1163 | |
5759 | 1164 octave_base_value * |
3933 | 1165 octave_value::clone (void) const |
2880 | 1166 { |
10325
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1167 return rep->clone (); |
2880 | 1168 } |
1169 | |
2409 | 1170 void |
1171 octave_value::maybe_mutate (void) | |
1172 { | |
5759 | 1173 octave_base_value *tmp = rep->try_narrowing_conversion (); |
2409 | 1174 |
1175 if (tmp && tmp != rep) | |
1176 { | |
1177 if (--rep->count == 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1178 delete rep; |
2409 | 1179 |
1180 rep = tmp; | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1181 } |
2409 | 1182 } |
1183 | |
4247 | 1184 octave_value |
4271 | 1185 octave_value::single_subsref (const std::string& type, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1186 const octave_value_list& idx) |
4247 | 1187 { |
1188 std::list<octave_value_list> i; | |
1189 | |
1190 i.push_back (idx); | |
1191 | |
1192 return rep->subsref (type, i); | |
1193 } | |
1194 | |
2974 | 1195 octave_value_list |
4247 | 1196 octave_value::subsref (const std::string& type, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1197 const std::list<octave_value_list>& idx, int nargout) |
3933 | 1198 { |
7651
443a8f5a50fd
require both subsref variants to be defined in octave_value subclasses
John W. Eaton <jwe@octave.org>
parents:
7503
diff
changeset
|
1199 if (nargout == 1) |
3933 | 1200 return rep->subsref (type, idx); |
1201 else | |
1202 return rep->subsref (type, idx, nargout); | |
1203 } | |
1204 | |
10832
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10768
diff
changeset
|
1205 octave_value_list |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10768
diff
changeset
|
1206 octave_value::subsref (const std::string& type, |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10768
diff
changeset
|
1207 const std::list<octave_value_list>& idx, int nargout, |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10768
diff
changeset
|
1208 const std::list<octave_lvalue> *lvalue_list) |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10768
diff
changeset
|
1209 { |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10768
diff
changeset
|
1210 if (lvalue_list) |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10768
diff
changeset
|
1211 return rep->subsref (type, idx, nargout, lvalue_list); |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10768
diff
changeset
|
1212 else |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10768
diff
changeset
|
1213 return subsref (type, idx, nargout); |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10768
diff
changeset
|
1214 } |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10768
diff
changeset
|
1215 |
3933 | 1216 octave_value |
4247 | 1217 octave_value::next_subsref (const std::string& type, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1218 const std::list<octave_value_list>& idx, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1219 size_t skip) |
3933 | 1220 { |
4582 | 1221 if (! error_state && idx.size () > skip) |
3933 | 1222 { |
4219 | 1223 std::list<octave_value_list> new_idx (idx); |
4233 | 1224 for (size_t i = 0; i < skip; i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1225 new_idx.erase (new_idx.begin ()); |
3933 | 1226 return subsref (type.substr (skip), new_idx); |
1227 } | |
1228 else | |
1229 return *this; | |
1230 } | |
1231 | |
1232 octave_value_list | |
4994 | 1233 octave_value::next_subsref (int nargout, const std::string& type, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1234 const std::list<octave_value_list>& idx, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1235 size_t skip) |
4994 | 1236 { |
1237 if (! error_state && idx.size () > skip) | |
1238 { | |
1239 std::list<octave_value_list> new_idx (idx); | |
1240 for (size_t i = 0; i < skip; i++) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1241 new_idx.erase (new_idx.begin ()); |
4994 | 1242 return subsref (type.substr (skip), new_idx, nargout); |
1243 } | |
1244 else | |
1245 return *this; | |
1246 } | |
1247 | |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8531
diff
changeset
|
1248 octave_value |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8531
diff
changeset
|
1249 octave_value::next_subsref (bool auto_add, const std::string& type, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1250 const std::list<octave_value_list>& idx, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1251 size_t skip) |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8531
diff
changeset
|
1252 { |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8531
diff
changeset
|
1253 if (! error_state && idx.size () > skip) |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8531
diff
changeset
|
1254 { |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8531
diff
changeset
|
1255 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
|
1256 for (size_t i = 0; i < skip; i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1257 new_idx.erase (new_idx.begin ()); |
8551
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8531
diff
changeset
|
1258 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
|
1259 } |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8531
diff
changeset
|
1260 else |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8531
diff
changeset
|
1261 return *this; |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8531
diff
changeset
|
1262 } |
906f976d35a8
further improve struct&cell indexing & indexed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
8531
diff
changeset
|
1263 |
4994 | 1264 octave_value_list |
3544 | 1265 octave_value::do_multi_index_op (int nargout, const octave_value_list& idx) |
2974 | 1266 { |
3544 | 1267 return rep->do_multi_index_op (nargout, idx); |
2974 | 1268 } |
1269 | |
10832
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10768
diff
changeset
|
1270 octave_value_list |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10768
diff
changeset
|
1271 octave_value::do_multi_index_op (int nargout, const octave_value_list& idx, |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10768
diff
changeset
|
1272 const std::list<octave_lvalue> *lvalue_list) |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10768
diff
changeset
|
1273 { |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10768
diff
changeset
|
1274 return rep->do_multi_index_op (nargout, idx, lvalue_list); |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10768
diff
changeset
|
1275 } |
1b2fcd122c6a
allow user detect ignored outputs in m-functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10768
diff
changeset
|
1276 |
3933 | 1277 #if 0 |
3204 | 1278 static void |
3933 | 1279 gripe_assign_failed (const std::string& on, const std::string& tn1, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1280 const std::string& tn2) |
3204 | 1281 { |
1282 error ("assignment failed for `%s %s %s'", | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1283 tn1.c_str (), on.c_str (), tn2.c_str ()); |
3204 | 1284 } |
3933 | 1285 #endif |
3204 | 1286 |
1287 static void | |
3933 | 1288 gripe_assign_failed_or_no_method (const std::string& on, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1289 const std::string& tn1, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1290 const std::string& tn2) |
3204 | 1291 { |
1292 error ("assignment failed, or no method for `%s %s %s'", | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1293 tn1.c_str (), on.c_str (), tn2.c_str ()); |
3204 | 1294 } |
1295 | |
3933 | 1296 octave_value |
4247 | 1297 octave_value::subsasgn (const std::string& type, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1298 const std::list<octave_value_list>& idx, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1299 const octave_value& rhs) |
3933 | 1300 { |
1301 return rep->subsasgn (type, idx, rhs); | |
1302 } | |
1303 | |
12171
d08901c05c1b
fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
1304 octave_value |
d08901c05c1b
fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
1305 octave_value::undef_subsasgn (const std::string& type, |
d08901c05c1b
fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
1306 const std::list<octave_value_list>& idx, |
d08901c05c1b
fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
1307 const octave_value& rhs) |
d08901c05c1b
fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
1308 { |
d08901c05c1b
fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
1309 return rep->undef_subsasgn (type, idx, rhs); |
d08901c05c1b
fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
1310 } |
d08901c05c1b
fix bug in class assignment to undefined object with index
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
1311 |
10544
9961fc022d9d
fix assignment to non-existing variables and octave_value::assign
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
1312 octave_value& |
4247 | 1313 octave_value::assign (assign_op op, const std::string& type, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1314 const std::list<octave_value_list>& idx, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1315 const octave_value& rhs) |
3933 | 1316 { |
1317 octave_value retval; | |
1318 | |
1319 make_unique (); | |
1320 | |
1321 octave_value t_rhs = rhs; | |
1322 | |
1323 if (op != op_asn_eq) | |
1324 { | |
10544
9961fc022d9d
fix assignment to non-existing variables and octave_value::assign
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
1325 if (is_defined ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1326 { |
10544
9961fc022d9d
fix assignment to non-existing variables and octave_value::assign
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
1327 octave_value t = subsref (type, idx); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1328 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1329 if (! error_state) |
10544
9961fc022d9d
fix assignment to non-existing variables and octave_value::assign
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
1330 { |
9961fc022d9d
fix assignment to non-existing variables and octave_value::assign
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
1331 binary_op binop = op_eq_to_binary_op (op); |
9961fc022d9d
fix assignment to non-existing variables and octave_value::assign
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
1332 |
9961fc022d9d
fix assignment to non-existing variables and octave_value::assign
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
1333 if (! error_state) |
9961fc022d9d
fix assignment to non-existing variables and octave_value::assign
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
1334 t_rhs = do_binary_op (binop, t, rhs); |
9961fc022d9d
fix assignment to non-existing variables and octave_value::assign
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
1335 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1336 } |
10544
9961fc022d9d
fix assignment to non-existing variables and octave_value::assign
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
1337 else |
9961fc022d9d
fix assignment to non-existing variables and octave_value::assign
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
1338 error ("in computed assignment A(index) OP= X, A must be defined first"); |
3933 | 1339 } |
1340 | |
1341 if (! error_state) | |
1342 { | |
10871
333bf09e3b6e
only allow struct assignments to non-struct values for empty arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
10832
diff
changeset
|
1343 octave_value tmp = subsasgn (type, idx, t_rhs); |
9693
1c19877799d3
improve error reports for computed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
9690
diff
changeset
|
1344 |
1c19877799d3
improve error reports for computed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
9690
diff
changeset
|
1345 if (error_state) |
1c19877799d3
improve error reports for computed assignment
Jaroslav Hajek <highegg@gmail.com>
parents:
9690
diff
changeset
|
1346 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
|
1347 type_name (), rhs.type_name ()); |
10871
333bf09e3b6e
only allow struct assignments to non-struct values for empty arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
10832
diff
changeset
|
1348 else |
333bf09e3b6e
only allow struct assignments to non-struct values for empty arrays
Jaroslav Hajek <highegg@gmail.com>
parents:
10832
diff
changeset
|
1349 *this = tmp; |
3933 | 1350 } |
1351 | |
10544
9961fc022d9d
fix assignment to non-existing variables and octave_value::assign
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
1352 return *this; |
3933 | 1353 } |
1354 | |
10544
9961fc022d9d
fix assignment to non-existing variables and octave_value::assign
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
1355 octave_value& |
3203 | 1356 octave_value::assign (assign_op op, const octave_value& rhs) |
2880 | 1357 { |
3533 | 1358 if (op == op_asn_eq) |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8039
diff
changeset
|
1359 // 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
|
1360 operator = (rhs.storable_value ()); |
10544
9961fc022d9d
fix assignment to non-existing variables and octave_value::assign
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
1361 else if (is_defined ()) |
3203 | 1362 { |
9546
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9479
diff
changeset
|
1363 octave_value_typeinfo::assign_op_fcn f = 0; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1364 |
9546
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9479
diff
changeset
|
1365 // 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
|
1366 if (rep->count == 1) |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9479
diff
changeset
|
1367 { |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9479
diff
changeset
|
1368 int tthis = this->type_id (); |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9479
diff
changeset
|
1369 int trhs = rhs.type_id (); |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9479
diff
changeset
|
1370 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1371 f = octave_value_typeinfo::lookup_assign_op (op, tthis, trhs); |
9546
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9479
diff
changeset
|
1372 } |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9479
diff
changeset
|
1373 |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9479
diff
changeset
|
1374 if (f) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1375 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1376 try |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1377 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1378 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
|
1379 maybe_mutate (); // Usually unnecessary, but may be needed (complex arrays). |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1380 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1381 catch (octave_execution_exception) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1382 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1383 gripe_library_execution_error (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1384 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1385 } |
9546
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9479
diff
changeset
|
1386 else |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9479
diff
changeset
|
1387 { |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9479
diff
changeset
|
1388 |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9479
diff
changeset
|
1389 binary_op binop = op_eq_to_binary_op (op); |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9479
diff
changeset
|
1390 |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9479
diff
changeset
|
1391 if (! error_state) |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9479
diff
changeset
|
1392 { |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9479
diff
changeset
|
1393 octave_value t = do_binary_op (binop, *this, rhs); |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9479
diff
changeset
|
1394 |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9479
diff
changeset
|
1395 if (! error_state) |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9479
diff
changeset
|
1396 operator = (t); |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9479
diff
changeset
|
1397 } |
1beb23d2b892
optimize op= in common cases
Jaroslav Hajek <highegg@gmail.com>
parents:
9479
diff
changeset
|
1398 } |
3204 | 1399 } |
10544
9961fc022d9d
fix assignment to non-existing variables and octave_value::assign
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
1400 else |
9961fc022d9d
fix assignment to non-existing variables and octave_value::assign
Jaroslav Hajek <highegg@gmail.com>
parents:
10521
diff
changeset
|
1401 error ("in computed assignment A OP= X, A must be defined first"); |
3204 | 1402 |
3933 | 1403 return *this; |
2376 | 1404 } |
1405 | |
5275 | 1406 octave_idx_type |
4563 | 1407 octave_value::length (void) const |
1408 { | |
10654
984b8b6bee02
simplify octave_value::length
Jaroslav Hajek <highegg@gmail.com>
parents:
10614
diff
changeset
|
1409 octave_idx_type retval = 0; |
984b8b6bee02
simplify octave_value::length
Jaroslav Hajek <highegg@gmail.com>
parents:
10614
diff
changeset
|
1410 |
984b8b6bee02
simplify octave_value::length
Jaroslav Hajek <highegg@gmail.com>
parents:
10614
diff
changeset
|
1411 const dim_vector dv = dims (); |
4584 | 1412 |
4563 | 1413 for (int i = 0; i < dv.length (); i++) |
1414 { | |
4584 | 1415 if (dv(i) == 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1416 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1417 retval = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1418 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1419 } |
4584 | 1420 |
4563 | 1421 if (dv(i) > retval) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1422 retval = dv(i); |
4563 | 1423 } |
1424 | |
1425 return retval; | |
1426 } | |
1427 | |
8346
8302788f09db
fix empty matrix handling in switch statement
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
1428 bool |
8302788f09db
fix empty matrix handling in switch statement
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
1429 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
|
1430 { |
8302788f09db
fix empty matrix handling in switch statement
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
1431 bool retval = false; |
8302788f09db
fix empty matrix handling in switch statement
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
1432 |
8302788f09db
fix empty matrix handling in switch statement
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
1433 // 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
|
1434 |
8302788f09db
fix empty matrix handling in switch statement
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
1435 if (rows () == test.rows () && columns () == test.columns ()) |
8302788f09db
fix empty matrix handling in switch statement
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
1436 { |
8302788f09db
fix empty matrix handling in switch statement
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
1437 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
|
1438 |
8302788f09db
fix empty matrix handling in switch statement
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
1439 // Empty array also means a match. |
8302788f09db
fix empty matrix handling in switch statement
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
1440 if (! error_state && tmp.is_defined ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1441 retval = tmp.is_true () || tmp.is_empty (); |
8346
8302788f09db
fix empty matrix handling in switch statement
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
1442 } |
8302788f09db
fix empty matrix handling in switch statement
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
1443 |
8302788f09db
fix empty matrix handling in switch statement
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
1444 return retval; |
8302788f09db
fix empty matrix handling in switch statement
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
1445 } |
8302788f09db
fix empty matrix handling in switch statement
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
1446 |
3351 | 1447 Cell |
1448 octave_value::cell_value (void) const | |
1449 { | |
1450 return rep->cell_value (); | |
1451 } | |
1452 | |
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
|
1453 // 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
|
1454 // 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
|
1455 |
260294a5520f
octave_value::idx_type_value: move definition to ov.cc from ov.h
John W. Eaton <jwe@octave.org>
parents:
8011
diff
changeset
|
1456 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
|
1457 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
|
1458 { |
260294a5520f
octave_value::idx_type_value: move definition to ov.cc from ov.h
John W. Eaton <jwe@octave.org>
parents:
8011
diff
changeset
|
1459 #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
|
1460 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
|
1461 #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
|
1462 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
|
1463 #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
|
1464 #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
|
1465 #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
|
1466 } |
260294a5520f
octave_value::idx_type_value: move definition to ov.cc from ov.h
John W. Eaton <jwe@octave.org>
parents:
8011
diff
changeset
|
1467 |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10687
diff
changeset
|
1468 octave_map |
2376 | 1469 octave_value::map_value (void) const |
1470 { | |
1471 return rep->map_value (); | |
1472 } | |
1473 | |
10742
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10687
diff
changeset
|
1474 octave_scalar_map |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10687
diff
changeset
|
1475 octave_value::scalar_map_value (void) const |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10687
diff
changeset
|
1476 { |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10687
diff
changeset
|
1477 return rep->scalar_map_value (); |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10687
diff
changeset
|
1478 } |
604e13a89c7f
initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents:
10687
diff
changeset
|
1479 |
2974 | 1480 octave_function * |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
1481 octave_value::function_value (bool silent) const |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
1482 { |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
1483 return rep->function_value (silent); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
1484 } |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
1485 |
4700 | 1486 octave_user_function * |
10075
84b0725f4b09
return class types by reference in const Array element access functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10033
diff
changeset
|
1487 octave_value::user_function_value (bool silent) const |
4700 | 1488 { |
1489 return rep->user_function_value (silent); | |
1490 } | |
1491 | |
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
|
1492 octave_user_script * |
10075
84b0725f4b09
return class types by reference in const Array element access functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10033
diff
changeset
|
1493 octave_value::user_script_value (bool silent) const |
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
|
1494 { |
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
|
1495 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
|
1496 } |
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
|
1497 |
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
|
1498 octave_user_code * |
10075
84b0725f4b09
return class types by reference in const Array element access functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10033
diff
changeset
|
1499 octave_value::user_code_value (bool silent) const |
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
|
1500 { |
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
|
1501 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
|
1502 } |
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
|
1503 |
4346 | 1504 octave_fcn_handle * |
10075
84b0725f4b09
return class types by reference in const Array element access functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10033
diff
changeset
|
1505 octave_value::fcn_handle_value (bool silent) const |
4343 | 1506 { |
1507 return rep->fcn_handle_value (silent); | |
1508 } | |
1509 | |
4933 | 1510 octave_fcn_inline * |
10075
84b0725f4b09
return class types by reference in const Array element access functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10033
diff
changeset
|
1511 octave_value::fcn_inline_value (bool silent) const |
4933 | 1512 { |
1513 return rep->fcn_inline_value (silent); | |
1514 } | |
1515 | |
2880 | 1516 octave_value_list |
1517 octave_value::list_value (void) const | |
1518 { | |
1519 return rep->list_value (); | |
1520 } | |
1521 | |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1522 static dim_vector |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1523 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
|
1524 const std::string& my_type, const std::string& wanted_type) |
3419 | 1525 { |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1526 dim_vector retval (dv); |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1527 retval.chop_trailing_singletons (); |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1528 octave_idx_type nel = dv.numel (); |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1529 |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1530 if (retval.length () > 2 || (retval(0) != 1 && retval(1) != 1)) |
3419 | 1531 { |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1532 if (!force_vector_conversion) |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1533 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
|
1534 my_type.c_str (), wanted_type.c_str ()); |
10350
12884915a8e4
merge MArray classes & improve Array interface
Jaroslav Hajek <highegg@gmail.com>
parents:
10325
diff
changeset
|
1535 retval = dim_vector (nel, 1); |
3419 | 1536 } |
1537 | |
1538 return retval; | |
1539 } | |
1540 | |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1541 ColumnVector |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1542 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
|
1543 bool frc_vec_conv) const |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1544 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1545 return ColumnVector (vector_value (force_string_conv, |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1546 frc_vec_conv)); |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1547 } |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1548 |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1549 ComplexColumnVector |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1550 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
|
1551 bool frc_vec_conv) const |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1552 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1553 return ComplexColumnVector (complex_vector_value (force_string_conv, |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1554 frc_vec_conv)); |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1555 } |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1556 |
3419 | 1557 RowVector |
1558 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
|
1559 bool frc_vec_conv) const |
3419 | 1560 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1561 return RowVector (vector_value (force_string_conv, |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1562 frc_vec_conv)); |
3419 | 1563 } |
1564 | |
1565 ComplexRowVector | |
1566 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
|
1567 bool frc_vec_conv) const |
3419 | 1568 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1569 return ComplexRowVector (complex_vector_value (force_string_conv, |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1570 frc_vec_conv)); |
3419 | 1571 } |
1572 | |
1573 Array<double> | |
2376 | 1574 octave_value::vector_value (bool force_string_conv, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1575 bool force_vector_conversion) const |
2376 | 1576 { |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1577 Array<double> retval = array_value (force_string_conv); |
2376 | 1578 |
1579 if (error_state) | |
1580 return retval; | |
1581 else | |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1582 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
|
1583 force_vector_conversion, |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1584 type_name (), "real vector")); |
2376 | 1585 } |
1586 | |
7997
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1587 template <class T> |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1588 static Array<int> |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1589 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
|
1590 { |
7999 | 1591 Array<int> retval (A.dims ()); |
7997
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1592 octave_idx_type n = A.numel (); |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1593 |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1594 for (octave_idx_type i = 0; i < n; i++) |
7999 | 1595 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
|
1596 |
7999 | 1597 return retval; |
7997
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1598 } |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1599 |
4044 | 1600 Array<int> |
1601 octave_value::int_vector_value (bool force_string_conv, bool require_int, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1602 bool force_vector_conversion) const |
4044 | 1603 { |
1604 Array<int> retval; | |
1605 | |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1606 if (is_integer_type ()) |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1607 { |
7997
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1608 if (is_int32_type ()) |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1609 retval = convert_to_int_array (int32_array_value ()); |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1610 else if (is_int64_type ()) |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1611 retval = convert_to_int_array (int64_array_value ()); |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1612 else if (is_int16_type ()) |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1613 retval = convert_to_int_array (int16_array_value ()); |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1614 else if (is_int8_type ()) |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1615 retval = convert_to_int_array (int8_array_value ()); |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1616 else if (is_uint32_type ()) |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1617 retval = convert_to_int_array (uint32_array_value ()); |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1618 else if (is_uint64_type ()) |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1619 retval = convert_to_int_array (uint64_array_value ()); |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1620 else if (is_uint16_type ()) |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1621 retval = convert_to_int_array (uint16_array_value ()); |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1622 else if (is_uint8_type ()) |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1623 retval = convert_to_int_array (uint8_array_value ()); |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1624 else |
2b8952e133c9
implement checked conversions between integers
Jaroslav Hajek <highegg@gmail.com>
parents:
7892
diff
changeset
|
1625 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
|
1626 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1627 else |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1628 { |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1629 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
|
1630 if (! error_state) |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1631 { |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1632 if (require_int) |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1633 { |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1634 retval.resize (a.dims ()); |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1635 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
|
1636 { |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1637 double ai = a.elem (i); |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1638 int v = static_cast<int> (ai); |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1639 if (ai == v) |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1640 retval.xelem (i) = v; |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1641 else |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1642 { |
9753
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
1643 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
|
1644 break; |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1645 } |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1646 } |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1647 } |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1648 else |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1649 retval = Array<int> (a); |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1650 } |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1651 } |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1652 |
4044 | 1653 |
1654 if (error_state) | |
1655 return retval; | |
1656 else | |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1657 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
|
1658 force_vector_conversion, |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1659 type_name (), "integer vector")); |
4044 | 1660 } |
1661 | |
8811 | 1662 template <class T> |
1663 static Array<octave_idx_type> | |
1664 convert_to_octave_idx_type_array (const Array<octave_int<T> >& A) | |
1665 { | |
1666 Array<octave_idx_type> retval (A.dims ()); | |
1667 octave_idx_type n = A.numel (); | |
1668 | |
1669 for (octave_idx_type i = 0; i < n; i++) | |
1670 retval.xelem (i) = octave_int<octave_idx_type> (A.xelem (i)); | |
1671 | |
1672 return retval; | |
1673 } | |
1674 | |
1675 Array<octave_idx_type> | |
9479
d9716e3ee0dd
supply optimized compiled sub2ind & ind2sub
Jaroslav Hajek <highegg@gmail.com>
parents:
9368
diff
changeset
|
1676 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
|
1677 bool force_string_conv, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1678 bool force_vector_conversion) const |
8811 | 1679 { |
1680 Array<octave_idx_type> retval; | |
1681 | |
1682 if (is_integer_type ()) | |
1683 { | |
1684 if (is_int32_type ()) | |
1685 retval = convert_to_octave_idx_type_array (int32_array_value ()); | |
1686 else if (is_int64_type ()) | |
1687 retval = convert_to_octave_idx_type_array (int64_array_value ()); | |
1688 else if (is_int16_type ()) | |
1689 retval = convert_to_octave_idx_type_array (int16_array_value ()); | |
1690 else if (is_int8_type ()) | |
1691 retval = convert_to_octave_idx_type_array (int8_array_value ()); | |
1692 else if (is_uint32_type ()) | |
1693 retval = convert_to_octave_idx_type_array (uint32_array_value ()); | |
1694 else if (is_uint64_type ()) | |
1695 retval = convert_to_octave_idx_type_array (uint64_array_value ()); | |
1696 else if (is_uint16_type ()) | |
1697 retval = convert_to_octave_idx_type_array (uint16_array_value ()); | |
1698 else if (is_uint8_type ()) | |
1699 retval = convert_to_octave_idx_type_array (uint8_array_value ()); | |
1700 else | |
1701 retval = array_value (force_string_conv); | |
1702 } | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1703 else |
8811 | 1704 { |
1705 const NDArray a = array_value (force_string_conv); | |
1706 if (! error_state) | |
1707 { | |
1708 if (require_int) | |
1709 { | |
1710 retval.resize (a.dims ()); | |
1711 for (octave_idx_type i = 0; i < a.numel (); i++) | |
1712 { | |
1713 double ai = a.elem (i); | |
1714 octave_idx_type v = static_cast<octave_idx_type> (ai); | |
1715 if (ai == v) | |
1716 retval.xelem (i) = v; | |
1717 else | |
1718 { | |
9753
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9732
diff
changeset
|
1719 error_with_cfn ("conversion to integer value failed"); |
8811 | 1720 break; |
1721 } | |
1722 } | |
1723 } | |
1724 else | |
1725 retval = Array<octave_idx_type> (a); | |
1726 } | |
1727 } | |
1728 | |
1729 | |
1730 if (error_state) | |
1731 return retval; | |
1732 else | |
1733 return retval.reshape (make_vector_dims (retval.dims (), | |
1734 force_vector_conversion, | |
1735 type_name (), "integer vector")); | |
1736 } | |
1737 | |
3419 | 1738 Array<Complex> |
2376 | 1739 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
|
1740 bool force_vector_conversion) const |
2376 | 1741 { |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1742 Array<Complex> retval = complex_array_value (force_string_conv); |
2376 | 1743 |
1744 if (error_state) | |
1745 return retval; | |
1746 else | |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1747 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
|
1748 force_vector_conversion, |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1749 type_name (), "complex vector")); |
2376 | 1750 } |
1751 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1752 FloatColumnVector |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1753 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
|
1754 bool frc_vec_conv) const |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1755 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1756 return FloatColumnVector (float_vector_value (force_string_conv, |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1757 frc_vec_conv)); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1758 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1759 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1760 FloatComplexColumnVector |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1761 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
|
1762 bool frc_vec_conv) const |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1763 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1764 return FloatComplexColumnVector (float_complex_vector_value (force_string_conv, |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1765 frc_vec_conv)); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1766 } |
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 FloatRowVector |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1769 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
|
1770 bool frc_vec_conv) const |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1771 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1772 return FloatRowVector (float_vector_value (force_string_conv, |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1773 frc_vec_conv)); |
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 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1776 FloatComplexRowVector |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1777 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
|
1778 bool frc_vec_conv) const |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1779 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1780 return FloatComplexRowVector (float_complex_vector_value (force_string_conv, |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1781 frc_vec_conv)); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1782 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1783 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1784 Array<float> |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1785 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
|
1786 bool force_vector_conversion) const |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1787 { |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1788 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
|
1789 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1790 if (error_state) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1791 return retval; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1792 else |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1793 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
|
1794 force_vector_conversion, |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1795 type_name (), "real vector")); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1796 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1797 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1798 Array<FloatComplex> |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1799 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
|
1800 bool force_vector_conversion) const |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1801 { |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1802 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
|
1803 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1804 if (error_state) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1805 return retval; |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1806 else |
7892
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1807 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
|
1808 force_vector_conversion, |
7ca2735d74c2
simplify & cleanup octave_value::XXX_vector_value functions
Jaroslav Hajek <highegg@gmail.com>
parents:
7885
diff
changeset
|
1809 type_name (), "complex vector")); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1810 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
1811 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1812 octave_value |
8523
ad3afaaa19c1
implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
1813 octave_value::storable_value (void) const |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8039
diff
changeset
|
1814 { |
8523
ad3afaaa19c1
implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
1815 octave_value retval = *this; |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8039
diff
changeset
|
1816 if (is_null_value ()) |
8523
ad3afaaa19c1
implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
1817 retval = octave_value (rep->empty_clone ()); |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8039
diff
changeset
|
1818 else |
8523
ad3afaaa19c1
implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
1819 retval.maybe_economize (); |
ad3afaaa19c1
implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
1820 |
ad3afaaa19c1
implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
1821 return retval; |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8039
diff
changeset
|
1822 } |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8039
diff
changeset
|
1823 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1824 void |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1825 octave_value::make_storable_value (void) |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8039
diff
changeset
|
1826 { |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8039
diff
changeset
|
1827 if (is_null_value ()) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8039
diff
changeset
|
1828 { |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8039
diff
changeset
|
1829 octave_base_value *rc = rep->empty_clone (); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8039
diff
changeset
|
1830 if (--rep->count == 0) |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8039
diff
changeset
|
1831 delete rep; |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8039
diff
changeset
|
1832 rep = rc; |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8039
diff
changeset
|
1833 } |
8523
ad3afaaa19c1
implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
1834 else |
ad3afaaa19c1
implement non-copying contiguous range indexing
Jaroslav Hajek <highegg@gmail.com>
parents:
8367
diff
changeset
|
1835 maybe_economize (); |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8039
diff
changeset
|
1836 } |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8039
diff
changeset
|
1837 |
4944 | 1838 int |
1839 octave_value::write (octave_stream& os, int block_size, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1840 oct_data_conv::data_type output_type, int skip, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1841 oct_mach_info::float_format flt_fmt) const |
4944 | 1842 { |
1843 return rep->write (os, block_size, output_type, skip, flt_fmt); | |
1844 } | |
1845 | |
2413 | 1846 static void |
3933 | 1847 gripe_binary_op (const std::string& on, const std::string& tn1, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1848 const std::string& tn2) |
2376 | 1849 { |
2903 | 1850 error ("binary operator `%s' not implemented for `%s' by `%s' operations", |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1851 on.c_str (), tn1.c_str (), tn2.c_str ()); |
2376 | 1852 } |
1853 | |
3203 | 1854 static void |
3523 | 1855 gripe_binary_op_conv (const std::string& on) |
3203 | 1856 { |
1857 error ("type conversion failed for binary operator `%s'", on.c_str ()); | |
1858 } | |
1859 | |
2376 | 1860 octave_value |
3933 | 1861 do_binary_op (octave_value::binary_op op, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1862 const octave_value& v1, const octave_value& v2) |
2376 | 1863 { |
1864 octave_value retval; | |
1865 | |
1866 int t1 = v1.type_id (); | |
1867 int t2 = v2.type_id (); | |
1868 | |
7336 | 1869 if (t1 == octave_class::static_type_id () |
1870 || t2 == octave_class::static_type_id ()) | |
1871 { | |
1872 octave_value_typeinfo::binary_class_op_fcn f | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1873 = octave_value_typeinfo::lookup_binary_class_op (op); |
2376 | 1874 |
7336 | 1875 if (f) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1876 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1877 try |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1878 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1879 retval = f (v1, v2); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1880 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1881 catch (octave_execution_exception) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1882 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1883 gripe_library_execution_error (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1884 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1885 } |
7336 | 1886 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1887 gripe_binary_op (octave_value::binary_op_as_string (op), |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1888 v1.class_name (), v2.class_name ()); |
7336 | 1889 } |
2376 | 1890 else |
1891 { | |
7336 | 1892 // FIXME -- we need to handle overloading operators for built-in |
1893 // classes (double, char, int8, etc.) | |
2376 | 1894 |
7336 | 1895 octave_value_typeinfo::binary_op_fcn f |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1896 = octave_value_typeinfo::lookup_binary_op (op, t1, t2); |
7336 | 1897 |
1898 if (f) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1899 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1900 try |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1901 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1902 retval = f (*v1.rep, *v2.rep); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1903 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1904 catch (octave_execution_exception) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1905 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1906 gripe_library_execution_error (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1907 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1908 } |
7336 | 1909 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1910 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1911 octave_value tv1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1912 octave_base_value::type_conv_info cf1 = v1.numeric_conversion_function (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1913 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1914 octave_value tv2; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1915 octave_base_value::type_conv_info cf2 = v2.numeric_conversion_function (); |
8345
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1916 |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1917 // Try biased (one-sided) conversions first. |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1918 if (cf2.type_id () >= 0 && |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1919 octave_value_typeinfo::lookup_binary_op (op, t1, cf2.type_id ())) |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1920 cf1 = 0; |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1921 else if (cf1.type_id () >= 0 && |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1922 octave_value_typeinfo::lookup_binary_op (op, cf1.type_id (), t2)) |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1923 cf2 = 0; |
7336 | 1924 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1925 if (cf1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1926 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1927 octave_base_value *tmp = cf1 (*v1.rep); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1928 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1929 if (tmp) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1930 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1931 tv1 = octave_value (tmp); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1932 t1 = tv1.type_id (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1933 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1934 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1935 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1936 gripe_binary_op_conv (octave_value::binary_op_as_string (op)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1937 return retval; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1938 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1939 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1940 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1941 tv1 = v1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1942 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1943 if (cf2) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1944 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1945 octave_base_value *tmp = cf2 (*v2.rep); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1946 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1947 if (tmp) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1948 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1949 tv2 = octave_value (tmp); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1950 t2 = tv2.type_id (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1951 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1952 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1953 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1954 gripe_binary_op_conv (octave_value::binary_op_as_string (op)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1955 return retval; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1956 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1957 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1958 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1959 tv2 = v2; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1960 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1961 if (cf1 || cf2) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1962 { |
8345
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1963 retval = do_binary_op (op, tv1, tv2); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1964 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1965 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1966 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1967 //demote double -> single and try again |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1968 cf1 = tv1.numeric_demotion_function (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1969 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1970 cf2 = tv2.numeric_demotion_function (); |
8345
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1971 |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1972 // Try biased (one-sided) conversions first. |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1973 if (cf2.type_id () >= 0 |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1974 && octave_value_typeinfo::lookup_binary_op (op, t1, cf2.type_id ())) |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1975 cf1 = 0; |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1976 else if (cf1.type_id () >= 0 |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1977 && octave_value_typeinfo::lookup_binary_op (op, cf1.type_id (), t2)) |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1978 cf2 = 0; |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
1979 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1980 if (cf1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1981 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1982 octave_base_value *tmp = cf1 (*tv1.rep); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1983 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1984 if (tmp) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1985 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1986 tv1 = octave_value (tmp); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1987 t1 = tv1.type_id (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1988 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1989 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1990 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1991 gripe_binary_op_conv (octave_value::binary_op_as_string (op)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1992 return retval; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1993 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1994 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1995 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1996 if (cf2) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1997 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1998 octave_base_value *tmp = cf2 (*tv2.rep); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
1999 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2000 if (tmp) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2001 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2002 tv2 = octave_value (tmp); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2003 t2 = tv2.type_id (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2004 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2005 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2006 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2007 gripe_binary_op_conv (octave_value::binary_op_as_string (op)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2008 return retval; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2009 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2010 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2011 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2012 if (cf1 || cf2) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2013 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2014 f = octave_value_typeinfo::lookup_binary_op (op, t1, t2); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2015 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2016 if (f) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2017 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2018 try |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2019 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2020 retval = f (*tv1.rep, *tv2.rep); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2021 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2022 catch (octave_execution_exception) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2023 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2024 gripe_library_execution_error (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2025 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2026 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2027 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2028 gripe_binary_op (octave_value::binary_op_as_string (op), |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2029 v1.type_name (), v2.type_name ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2030 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2031 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2032 gripe_binary_op (octave_value::binary_op_as_string (op), |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2033 v1.type_name (), v2.type_name ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2034 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2035 } |
2376 | 2036 } |
2037 | |
2038 return retval; | |
2039 } | |
2040 | |
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
|
2041 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
|
2042 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
|
2043 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
|
2044 { |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
2045 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
|
2046 |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
2047 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
|
2048 { |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
2049 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
|
2050 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
|
2051 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
|
2052 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
|
2053 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
|
2054 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
|
2055 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
|
2056 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
|
2057 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
|
2058 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
|
2059 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
|
2060 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
|
2061 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
|
2062 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
|
2063 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
|
2064 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
|
2065 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
|
2066 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
|
2067 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
|
2068 break; |
9661
afcf852256d2
optimize / and '\ for triangular matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
9608
diff
changeset
|
2069 case octave_value::op_trans_ldiv: |
afcf852256d2
optimize / and '\ for triangular matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
9608
diff
changeset
|
2070 retval = do_binary_op (octave_value::op_ldiv, |
afcf852256d2
optimize / and '\ for triangular matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
9608
diff
changeset
|
2071 do_unary_op (octave_value::op_transpose, v1), |
afcf852256d2
optimize / and '\ for triangular matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
9608
diff
changeset
|
2072 v2); |
afcf852256d2
optimize / and '\ for triangular matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
9608
diff
changeset
|
2073 break; |
afcf852256d2
optimize / and '\ for triangular matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
9608
diff
changeset
|
2074 case octave_value::op_herm_ldiv: |
afcf852256d2
optimize / and '\ for triangular matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
9608
diff
changeset
|
2075 retval = do_binary_op (octave_value::op_ldiv, |
afcf852256d2
optimize / and '\ for triangular matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
9608
diff
changeset
|
2076 do_unary_op (octave_value::op_hermitian, v1), |
afcf852256d2
optimize / and '\ for triangular matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
9608
diff
changeset
|
2077 v2); |
afcf852256d2
optimize / and '\ for triangular matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
9608
diff
changeset
|
2078 break; |
8982
dc6bda6f9994
implement compound logical ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
2079 case octave_value::op_el_not_and: |
dc6bda6f9994
implement compound logical ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
2080 retval = do_binary_op (octave_value::op_el_and, |
dc6bda6f9994
implement compound logical ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
2081 do_unary_op (octave_value::op_not, v1), |
dc6bda6f9994
implement compound logical ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
2082 v2); |
dc6bda6f9994
implement compound logical ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
2083 break; |
dc6bda6f9994
implement compound logical ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
2084 case octave_value::op_el_not_or: |
dc6bda6f9994
implement compound logical ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
2085 retval = do_binary_op (octave_value::op_el_or, |
dc6bda6f9994
implement compound logical ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
2086 do_unary_op (octave_value::op_not, v1), |
dc6bda6f9994
implement compound logical ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
2087 v2); |
dc6bda6f9994
implement compound logical ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
2088 break; |
dc6bda6f9994
implement compound logical ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
2089 case octave_value::op_el_and_not: |
dc6bda6f9994
implement compound logical ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
2090 retval = do_binary_op (octave_value::op_el_and, |
dc6bda6f9994
implement compound logical ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
2091 v1, |
dc6bda6f9994
implement compound logical ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
2092 do_unary_op (octave_value::op_not, v2)); |
dc6bda6f9994
implement compound logical ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
2093 break; |
dc6bda6f9994
implement compound logical ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
2094 case octave_value::op_el_or_not: |
dc6bda6f9994
implement compound logical ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
2095 retval = do_binary_op (octave_value::op_el_or, |
dc6bda6f9994
implement compound logical ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
2096 v1, |
dc6bda6f9994
implement compound logical ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
2097 do_unary_op (octave_value::op_not, v2)); |
dc6bda6f9994
implement compound logical ops
Jaroslav Hajek <highegg@gmail.com>
parents:
8960
diff
changeset
|
2098 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
|
2099 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
|
2100 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
|
2101 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
|
2102 } |
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 |
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 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
|
2105 } |
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 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
|
2108 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
|
2109 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
|
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 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
|
2112 |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
2113 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
|
2114 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
|
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 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
|
2117 || 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
|
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 octave_value_typeinfo::binary_class_op_fcn f |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2120 = octave_value_typeinfo::lookup_binary_class_op (op); |
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
|
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 if (f) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2123 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2124 try |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2125 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2126 retval = f (v1, v2); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2127 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2128 catch (octave_execution_exception) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2129 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2130 gripe_library_execution_error (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2131 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
2132 } |
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
|
2133 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
|
2134 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
|
2135 } |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
2136 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
|
2137 { |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
2138 octave_value_typeinfo::binary_op_fcn f |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2139 = octave_value_typeinfo::lookup_binary_op (op, t1, t2); |
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
|
2140 |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
2141 if (f) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2142 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2143 try |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2144 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2145 retval = f (*v1.rep, *v2.rep); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2146 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2147 catch (octave_execution_exception) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2148 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2149 gripe_library_execution_error (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2150 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2151 } |
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
|
2152 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
|
2153 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
|
2154 } |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
2155 |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
2156 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
|
2157 } |
5861b95e9879
support for compound operators, implement trans_mul, mul_trans, herm_mul and mul_herm
Jaroslav Hajek <highegg@gmail.com>
parents:
7789
diff
changeset
|
2158 |
4915 | 2159 static void |
2160 gripe_cat_op (const std::string& tn1, const std::string& tn2) | |
2161 { | |
2162 error ("concatenation operator not implemented for `%s' by `%s' operations", | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2163 tn1.c_str (), tn2.c_str ()); |
4915 | 2164 } |
2165 | |
2166 static void | |
2167 gripe_cat_op_conv (void) | |
2168 { | |
2169 error ("type conversion failed for concatenation operator"); | |
2170 } | |
2171 | |
2172 octave_value | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
2173 do_cat_op (const octave_value& v1, const octave_value& v2, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2174 const Array<octave_idx_type>& ra_idx) |
4915 | 2175 { |
2176 octave_value retval; | |
2177 | |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7800
diff
changeset
|
2178 // 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
|
2179 // something like cat(1,[],single([]) must return the correct type. |
5164 | 2180 |
4915 | 2181 int t1 = v1.type_id (); |
2182 int t2 = v2.type_id (); | |
2183 | |
5759 | 2184 octave_value_typeinfo::cat_op_fcn f |
2185 = octave_value_typeinfo::lookup_cat_op (t1, t2); | |
4915 | 2186 |
2187 if (f) | |
7487
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2188 { |
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2189 try |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2190 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2191 retval = f (*v1.rep, *v2.rep, ra_idx); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2192 } |
7487
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2193 catch (octave_execution_exception) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2194 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2195 gripe_library_execution_error (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2196 } |
7487
1e01db14700b
catch octave_execution_exception for built-in and mex functions
John W. Eaton <jwe@octave.org>
parents:
7433
diff
changeset
|
2197 } |
4915 | 2198 else |
2199 { | |
2200 octave_value tv1; | |
8345
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
2201 octave_base_value::type_conv_info cf1 = v1.numeric_conversion_function (); |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
2202 |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
2203 octave_value tv2; |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
2204 octave_base_value::type_conv_info cf2 = v2.numeric_conversion_function (); |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
2205 |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
2206 // Try biased (one-sided) conversions first. |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
2207 if (cf2.type_id () >= 0 |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
2208 && octave_value_typeinfo::lookup_cat_op (t1, cf2.type_id ())) |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
2209 cf1 = 0; |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
2210 else if (cf1.type_id () >= 0 |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
2211 && octave_value_typeinfo::lookup_cat_op (cf1.type_id (), t2)) |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
2212 cf2 = 0; |
4915 | 2213 |
2214 if (cf1) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2215 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2216 octave_base_value *tmp = cf1 (*v1.rep); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2217 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2218 if (tmp) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2219 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2220 tv1 = octave_value (tmp); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2221 t1 = tv1.type_id (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2222 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2223 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2224 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2225 gripe_cat_op_conv (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2226 return retval; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2227 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2228 } |
4915 | 2229 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2230 tv1 = v1; |
4915 | 2231 |
2232 if (cf2) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2233 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2234 octave_base_value *tmp = cf2 (*v2.rep); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2235 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2236 if (tmp) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2237 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2238 tv2 = octave_value (tmp); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2239 t2 = tv2.type_id (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2240 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2241 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2242 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2243 gripe_cat_op_conv (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2244 return retval; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2245 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2246 } |
4915 | 2247 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2248 tv2 = v2; |
4915 | 2249 |
2250 if (cf1 || cf2) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2251 { |
8345
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
2252 retval = do_cat_op (tv1, tv2, ra_idx); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2253 } |
4915 | 2254 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2255 gripe_cat_op (v1.type_name (), v2.type_name ()); |
4915 | 2256 } |
2257 | |
2258 return retval; | |
2259 } | |
2260 | |
3933 | 2261 void |
2262 octave_value::print_info (std::ostream& os, const std::string& prefix) const | |
2263 { | |
2264 os << prefix << "type_name: " << type_name () << "\n" | |
2265 << prefix << "count: " << get_count () << "\n" | |
2266 << prefix << "rep info: "; | |
2267 | |
2268 rep->print_info (os, prefix + " "); | |
2269 } | |
2270 | |
3203 | 2271 static void |
3523 | 2272 gripe_unary_op (const std::string& on, const std::string& tn) |
3203 | 2273 { |
2274 error ("unary operator `%s' not implemented for `%s' operands", | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2275 on.c_str (), tn.c_str ()); |
3203 | 2276 } |
2277 | |
2278 static void | |
3523 | 2279 gripe_unary_op_conv (const std::string& on) |
3203 | 2280 { |
2281 error ("type conversion failed for unary operator `%s'", on.c_str ()); | |
2282 } | |
2283 | |
2284 octave_value | |
2285 do_unary_op (octave_value::unary_op op, const octave_value& v) | |
2286 { | |
2287 octave_value retval; | |
2288 | |
2289 int t = v.type_id (); | |
2290 | |
7336 | 2291 if (t == octave_class::static_type_id ()) |
2292 { | |
2293 octave_value_typeinfo::unary_class_op_fcn f | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2294 = octave_value_typeinfo::lookup_unary_class_op (op); |
3203 | 2295 |
7336 | 2296 if (f) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2297 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2298 try |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2299 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2300 retval = f (v); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2301 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2302 catch (octave_execution_exception) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2303 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2304 gripe_library_execution_error (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2305 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2306 } |
7336 | 2307 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2308 gripe_unary_op (octave_value::unary_op_as_string (op), |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2309 v.class_name ()); |
7336 | 2310 } |
3203 | 2311 else |
2312 { | |
7336 | 2313 // FIXME -- we need to handle overloading operators for built-in |
2314 // classes (double, char, int8, etc.) | |
2315 | |
2316 octave_value_typeinfo::unary_op_fcn f | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2317 = octave_value_typeinfo::lookup_unary_op (op, t); |
3203 | 2318 |
7336 | 2319 if (f) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2320 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2321 try |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2322 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2323 retval = f (*v.rep); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2324 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2325 catch (octave_execution_exception) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2326 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2327 gripe_library_execution_error (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2328 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2329 } |
7336 | 2330 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2331 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2332 octave_value tv; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2333 octave_base_value::type_conv_fcn cf |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2334 = v.numeric_conversion_function (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2335 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2336 if (cf) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2337 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2338 octave_base_value *tmp = cf (*v.rep); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2339 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2340 if (tmp) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2341 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2342 tv = octave_value (tmp); |
8345
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8150
diff
changeset
|
2343 retval = do_unary_op (op, tv); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2344 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2345 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2346 gripe_unary_op_conv (octave_value::unary_op_as_string (op)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2347 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2348 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2349 gripe_unary_op (octave_value::unary_op_as_string (op), |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2350 v.type_name ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2351 } |
3203 | 2352 } |
2353 | |
2354 return retval; | |
2355 } | |
2356 | |
2357 static void | |
3933 | 2358 gripe_unary_op_conversion_failed (const std::string& op, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2359 const std::string& tn) |
3203 | 2360 { |
2361 error ("operator %s: type conversion for `%s' failed", | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2362 op.c_str (), tn.c_str ()); |
3203 | 2363 } |
2364 | |
10614
d1194069e58c
optimize code handling ++,--
Jaroslav Hajek <highegg@gmail.com>
parents:
10544
diff
changeset
|
2365 octave_value& |
3933 | 2366 octave_value::do_non_const_unary_op (unary_op op) |
3203 | 2367 { |
9607
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
2368 if (op == op_incr || op == op_decr) |
3203 | 2369 { |
10614
d1194069e58c
optimize code handling ++,--
Jaroslav Hajek <highegg@gmail.com>
parents:
10544
diff
changeset
|
2370 // We want the gripe just here, because in the other branch this should |
d1194069e58c
optimize code handling ++,--
Jaroslav Hajek <highegg@gmail.com>
parents:
10544
diff
changeset
|
2371 // not happen, and if it did anyway (internal error), the message would |
d1194069e58c
optimize code handling ++,--
Jaroslav Hajek <highegg@gmail.com>
parents:
10544
diff
changeset
|
2372 // be confusing. |
d1194069e58c
optimize code handling ++,--
Jaroslav Hajek <highegg@gmail.com>
parents:
10544
diff
changeset
|
2373 if (is_undefined ()) |
d1194069e58c
optimize code handling ++,--
Jaroslav Hajek <highegg@gmail.com>
parents:
10544
diff
changeset
|
2374 { |
d1194069e58c
optimize code handling ++,--
Jaroslav Hajek <highegg@gmail.com>
parents:
10544
diff
changeset
|
2375 std::string op_str = unary_op_as_string (op); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
2376 error ("in x%s or %sx, x must be defined first", |
10614
d1194069e58c
optimize code handling ++,--
Jaroslav Hajek <highegg@gmail.com>
parents:
10544
diff
changeset
|
2377 op_str.c_str (), op_str.c_str ()); |
d1194069e58c
optimize code handling ++,--
Jaroslav Hajek <highegg@gmail.com>
parents:
10544
diff
changeset
|
2378 return *this; |
d1194069e58c
optimize code handling ++,--
Jaroslav Hajek <highegg@gmail.com>
parents:
10544
diff
changeset
|
2379 } |
d1194069e58c
optimize code handling ++,--
Jaroslav Hajek <highegg@gmail.com>
parents:
10544
diff
changeset
|
2380 |
9607
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
2381 // Genuine. |
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
2382 int t = type_id (); |
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 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
|
2385 = 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
|
2386 |
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
2387 if (f) |
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
2388 { |
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
2389 make_unique (); |
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 try |
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 f (*rep); |
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
2394 } |
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
2395 catch (octave_execution_exception) |
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 gripe_library_execution_error (); |
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
2398 } |
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
2399 } |
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
2400 else |
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 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
|
2403 |
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
2404 if (cf) |
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
2405 { |
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
2406 octave_base_value *tmp = cf (*rep); |
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
2407 |
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
2408 if (tmp) |
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
2409 { |
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
2410 octave_base_value *old_rep = rep; |
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
2411 rep = tmp; |
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 t = type_id (); |
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
2414 |
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 |
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
2428 if (old_rep && --old_rep->count == 0) |
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
2429 delete old_rep; |
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
2430 } |
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
2431 else |
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
2432 { |
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
2433 if (old_rep) |
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
2434 { |
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
2435 if (--rep->count == 0) |
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
2436 delete rep; |
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
2437 |
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
2438 rep = old_rep; |
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
2439 } |
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
2440 |
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
2441 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
|
2442 type_name ()); |
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
2443 } |
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
2444 } |
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
2445 else |
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
2446 gripe_unary_op_conversion_failed |
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
2447 (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
|
2448 } |
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
2449 else |
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
2450 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
|
2451 } |
3203 | 2452 } |
2453 else | |
2454 { | |
9607
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
2455 // Non-genuine. |
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
2456 int t = type_id (); |
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
2457 |
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
2458 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
|
2459 |
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
2460 // 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
|
2461 if (rep->count == 1) |
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
2462 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
|
2463 |
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
2464 if (f) |
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
2465 { |
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
2466 try |
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
2467 { |
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
2468 f (*rep); |
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
2469 } |
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
2470 catch (octave_execution_exception) |
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
2471 { |
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
2472 gripe_library_execution_error (); |
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
2473 } |
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
2474 } |
3203 | 2475 else |
9607
1be3c73ed7b5
reuse temporary arrays in nested expressions
Jaroslav Hajek <highegg@gmail.com>
parents:
9546
diff
changeset
|
2476 *this = do_unary_op (op, *this); |
3203 | 2477 } |
3933 | 2478 |
2479 return *this; | |
3203 | 2480 } |
2481 | |
10614
d1194069e58c
optimize code handling ++,--
Jaroslav Hajek <highegg@gmail.com>
parents:
10544
diff
changeset
|
2482 octave_value& |
4247 | 2483 octave_value::do_non_const_unary_op (unary_op op, const std::string& type, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2484 const std::list<octave_value_list>& idx) |
3933 | 2485 { |
2486 if (idx.empty ()) | |
10614
d1194069e58c
optimize code handling ++,--
Jaroslav Hajek <highegg@gmail.com>
parents:
10544
diff
changeset
|
2487 do_non_const_unary_op (op); |
3933 | 2488 else |
2489 { | |
5775 | 2490 // FIXME -- only do the following stuff if we can't find a |
3933 | 2491 // specific function to call to handle the op= operation for the |
2492 // types we have. | |
3205 | 2493 |
3933 | 2494 assign_op assop = unary_op_to_assign_op (op); |
2495 | |
10614
d1194069e58c
optimize code handling ++,--
Jaroslav Hajek <highegg@gmail.com>
parents:
10544
diff
changeset
|
2496 assign (assop, type, idx, 1.0); |
3933 | 2497 } |
2498 | |
10614
d1194069e58c
optimize code handling ++,--
Jaroslav Hajek <highegg@gmail.com>
parents:
10544
diff
changeset
|
2499 return *this; |
3205 | 2500 } |
2501 | |
2502 octave_value::assign_op | |
2503 octave_value::unary_op_to_assign_op (unary_op op) | |
2504 { | |
2505 assign_op binop = unknown_assign_op; | |
2506 | |
2507 switch (op) | |
2508 { | |
3533 | 2509 case op_incr: |
2510 binop = op_add_eq; | |
3205 | 2511 break; |
2512 | |
3533 | 2513 case op_decr: |
2514 binop = op_sub_eq; | |
3205 | 2515 break; |
2516 | |
2517 default: | |
2518 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2519 std::string on = unary_op_as_string (op); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2520 error ("operator %s: no assign operator found", on.c_str ()); |
3205 | 2521 } |
2522 } | |
2523 | |
2524 return binop; | |
2525 } | |
2526 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
2527 octave_value::binary_op |
3204 | 2528 octave_value::op_eq_to_binary_op (assign_op op) |
2529 { | |
2530 binary_op binop = unknown_binary_op; | |
2531 | |
2532 switch (op) | |
2533 { | |
3533 | 2534 case op_add_eq: |
2535 binop = op_add; | |
3204 | 2536 break; |
2537 | |
3533 | 2538 case op_sub_eq: |
2539 binop = op_sub; | |
3204 | 2540 break; |
2541 | |
3533 | 2542 case op_mul_eq: |
2543 binop = op_mul; | |
3204 | 2544 break; |
2545 | |
3533 | 2546 case op_div_eq: |
2547 binop = op_div; | |
3204 | 2548 break; |
2549 | |
3533 | 2550 case op_ldiv_eq: |
2551 binop = op_ldiv; | |
3204 | 2552 break; |
2553 | |
4018 | 2554 case op_pow_eq: |
2555 binop = op_pow; | |
2556 break; | |
2557 | |
3533 | 2558 case op_lshift_eq: |
2559 binop = op_lshift; | |
3204 | 2560 break; |
2561 | |
3533 | 2562 case op_rshift_eq: |
2563 binop = op_rshift; | |
3204 | 2564 break; |
2565 | |
3533 | 2566 case op_el_mul_eq: |
2567 binop = op_el_mul; | |
3204 | 2568 break; |
2569 | |
3533 | 2570 case op_el_div_eq: |
2571 binop = op_el_div; | |
3204 | 2572 break; |
2573 | |
3533 | 2574 case op_el_ldiv_eq: |
2575 binop = op_el_ldiv; | |
3204 | 2576 break; |
2577 | |
4018 | 2578 case op_el_pow_eq: |
2579 binop = op_el_pow; | |
2580 break; | |
2581 | |
3533 | 2582 case op_el_and_eq: |
2583 binop = op_el_and; | |
3204 | 2584 break; |
2585 | |
3533 | 2586 case op_el_or_eq: |
2587 binop = op_el_or; | |
3204 | 2588 break; |
2589 | |
2590 default: | |
2591 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2592 std::string on = assign_op_as_string (op); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2593 error ("operator %s: no binary operator found", on.c_str ()); |
3204 | 2594 } |
2595 } | |
2596 | |
2597 return binop; | |
2598 } | |
2599 | |
3933 | 2600 octave_value |
2601 octave_value::empty_conv (const std::string& type, const octave_value& rhs) | |
2602 { | |
2603 octave_value retval; | |
2604 | |
2605 if (type.length () > 0) | |
2606 { | |
2607 switch (type[0]) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2608 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2609 case '(': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2610 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2611 if (type.length () > 1 && type[1] == '.') |
10754
92eb5fb58ebc
fix resize with structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10753
diff
changeset
|
2612 retval = octave_map (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2613 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2614 retval = octave_value (rhs.empty_clone ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2615 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2616 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2617 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2618 case '{': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2619 retval = Cell (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2620 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2621 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2622 case '.': |
10754
92eb5fb58ebc
fix resize with structs
Jaroslav Hajek <highegg@gmail.com>
parents:
10753
diff
changeset
|
2623 retval = octave_scalar_map (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2624 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2625 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2626 default: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2627 panic_impossible (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10232
diff
changeset
|
2628 } |
3933 | 2629 } |
2630 else | |
2631 retval = octave_value (rhs.empty_clone ()); | |
2632 | |
2633 return retval; | |
2634 } | |
2635 | |
2376 | 2636 void |
2637 install_types (void) | |
2638 { | |
2639 octave_base_value::register_type (); | |
3928 | 2640 octave_cell::register_type (); |
2376 | 2641 octave_scalar::register_type (); |
2642 octave_complex::register_type (); | |
2643 octave_matrix::register_type (); | |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8346
diff
changeset
|
2644 octave_diag_matrix::register_type (); |
2376 | 2645 octave_complex_matrix::register_type (); |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8346
diff
changeset
|
2646 octave_complex_diag_matrix::register_type (); |
2376 | 2647 octave_range::register_type (); |
2825 | 2648 octave_bool::register_type (); |
2649 octave_bool_matrix::register_type (); | |
2376 | 2650 octave_char_matrix_str::register_type (); |
5279 | 2651 octave_char_matrix_sq_str::register_type (); |
4901 | 2652 octave_int8_scalar::register_type (); |
2653 octave_int16_scalar::register_type (); | |
2654 octave_int32_scalar::register_type (); | |
2655 octave_int64_scalar::register_type (); | |
2656 octave_uint8_scalar::register_type (); | |
2657 octave_uint16_scalar::register_type (); | |
2658 octave_uint32_scalar::register_type (); | |
2659 octave_uint64_scalar::register_type (); | |
2660 octave_int8_matrix::register_type (); | |
2661 octave_int16_matrix::register_type (); | |
2662 octave_int32_matrix::register_type (); | |
2663 octave_int64_matrix::register_type (); | |
2664 octave_uint8_matrix::register_type (); | |
2665 octave_uint16_matrix::register_type (); | |
2666 octave_uint32_matrix::register_type (); | |
2667 octave_uint64_matrix::register_type (); | |
5164 | 2668 octave_sparse_bool_matrix::register_type (); |
2669 octave_sparse_matrix::register_type (); | |
2670 octave_sparse_complex_matrix::register_type (); | |
2376 | 2671 octave_struct::register_type (); |
10753
bee1b1a2e29a
yield compatible dims from cell2struct + more fixes. build & tests OK
Jaroslav Hajek <highegg@gmail.com>
parents:
10742
diff
changeset
|
2672 octave_scalar_struct::register_type (); |
7336 | 2673 octave_class::register_type (); |
3977 | 2674 octave_cs_list::register_type (); |
2376 | 2675 octave_magic_colon::register_type (); |
2974 | 2676 octave_builtin::register_type (); |
2677 octave_user_function::register_type (); | |
4649 | 2678 octave_dld_function::register_type (); |
4643 | 2679 octave_fcn_handle::register_type (); |
4966 | 2680 octave_fcn_inline::register_type (); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
2681 octave_float_scalar::register_type (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
2682 octave_float_complex::register_type (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
2683 octave_float_matrix::register_type (); |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8346
diff
changeset
|
2684 octave_float_diag_matrix::register_type (); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7761
diff
changeset
|
2685 octave_float_complex_matrix::register_type (); |
8366
8b1a2555c4e2
implement diagonal matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8346
diff
changeset
|
2686 octave_float_complex_diag_matrix::register_type (); |
8367
445d27d79f4e
support permutation matrix objects
Jaroslav Hajek <highegg@gmail.com>
parents:
8366
diff
changeset
|
2687 octave_perm_matrix::register_type (); |
8150
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8039
diff
changeset
|
2688 octave_null_matrix::register_type (); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8039
diff
changeset
|
2689 octave_null_str::register_type (); |
283989f2da9b
make null assignment matlab compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
8039
diff
changeset
|
2690 octave_null_sq_str::register_type (); |
10325
8b3cfc1288e2
implement lazy index conversions
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
2691 octave_lazy_index::register_type (); |
2376 | 2692 } |
2693 | |
4791 | 2694 DEFUN (sizeof, args, , |
2695 "-*- texinfo -*-\n\ | |
2696 @deftypefn {Built-in Function} {} sizeof (@var{val})\n\ | |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10654
diff
changeset
|
2697 Return the size of @var{val} in bytes.\n\ |
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10654
diff
changeset
|
2698 @seealso{whos}\n\ |
4791 | 2699 @end deftypefn") |
2700 { | |
2701 octave_value retval; | |
2702 | |
2703 if (args.length () == 1) | |
2704 retval = args(0).byte_size (); | |
2705 else | |
5823 | 2706 print_usage (); |
4791 | 2707 |
2708 return retval; | |
2709 } | |
2710 | |
13100
06bf445ee778
Add 6 tests for ov.cc
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12642
diff
changeset
|
2711 /* |
06bf445ee778
Add 6 tests for ov.cc
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12642
diff
changeset
|
2712 %!assert (sizeof (uint64 (ones (3))), 72) |
06bf445ee778
Add 6 tests for ov.cc
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12642
diff
changeset
|
2713 %!assert (sizeof (double (zeros (2,4))), 64) |
06bf445ee778
Add 6 tests for ov.cc
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12642
diff
changeset
|
2714 %!assert (sizeof ({"foo", "bar", "baaz"}), 10) |
06bf445ee778
Add 6 tests for ov.cc
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12642
diff
changeset
|
2715 */ |
06bf445ee778
Add 6 tests for ov.cc
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12642
diff
changeset
|
2716 |
13932
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2717 static void |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2718 decode_subscripts (const char* name, const octave_value& arg, |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2719 std::string& type_string, |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2720 std::list<octave_value_list>& idx) |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2721 { |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2722 const octave_map m = arg.map_value (); |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2723 |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2724 if (! error_state |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2725 && m.nfields () == 2 && m.contains ("type") && m.contains ("subs")) |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2726 { |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2727 octave_idx_type nel = m.numel (); |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2728 |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2729 type_string = std::string (nel, '\0'); |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2730 idx = std::list<octave_value_list> (); |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2731 |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2732 if (nel == 0) |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2733 return; |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2734 |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2735 const Cell type = m.contents ("type"); |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2736 const Cell subs = m.contents ("subs"); |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2737 |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2738 for (int k = 0; k < nel; k++) |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2739 { |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2740 std::string item = type(k).string_value (); |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2741 |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2742 if (! error_state) |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2743 { |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2744 if (item == "{}") |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2745 type_string[k] = '{'; |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2746 else if (item == "()") |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2747 type_string[k] = '('; |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2748 else if (item == ".") |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2749 type_string[k] = '.'; |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2750 else |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2751 { |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2752 error("%s: invalid indexing type `%s'", name, item.c_str ()); |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2753 return; |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2754 } |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2755 } |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2756 else |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2757 { |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2758 error ("%s: expecting type(%d) to be a character string", |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2759 name, k+1); |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2760 return; |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2761 } |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2762 |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2763 octave_value_list idx_item; |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2764 |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2765 if (subs(k).is_string ()) |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2766 idx_item(0) = subs(k); |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2767 else if (subs(k).is_cell ()) |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2768 { |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2769 Cell subs_cell = subs(k).cell_value (); |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2770 |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2771 for (int n = 0; n < subs_cell.length (); n++) |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2772 { |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2773 if (subs_cell(n).is_string () |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2774 && subs_cell(n).string_value () == ":") |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2775 idx_item(n) = octave_value(octave_value::magic_colon_t); |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2776 else |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2777 idx_item(n) = subs_cell(n); |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2778 } |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2779 } |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2780 else |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2781 { |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2782 error ("%s: expecting subs(%d) to be a character string or cell array", |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2783 name, k+1); |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2784 return; |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2785 } |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2786 |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2787 idx.push_back (idx_item); |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2788 } |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2789 } |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2790 else |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2791 error ("%s: second argument must be a structure with fields `type' and `subs'", name); |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2792 } |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2793 |
6153 | 2794 DEFUN (subsref, args, nargout, |
2795 "-*- texinfo -*-\n\ | |
2796 @deftypefn {Built-in Function} {} subsref (@var{val}, @var{idx})\n\ | |
2797 Perform the subscripted element selection operation according to\n\ | |
2798 the subscript specified by @var{idx}.\n\ | |
2799 \n\ | |
2800 The subscript @var{idx} is expected to be a structure array with\n\ | |
2801 fields @samp{type} and @samp{subs}. Valid values for @samp{type}\n\ | |
6550 | 2802 are @samp{\"()\"}, @samp{\"@{@}\"}, and @samp{\".\"}.\n\ |
6153 | 2803 The @samp{subs} field may be either @samp{\":\"} or a cell array\n\ |
2804 of index values.\n\ | |
6631 | 2805 \n\ |
2806 The following example shows how to extract the two first columns of\n\ | |
2807 a matrix\n\ | |
2808 \n\ | |
2809 @example\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8992
diff
changeset
|
2810 @group\n\ |
6631 | 2811 val = magic(3)\n\ |
2812 @result{} val = [ 8 1 6\n\ | |
2813 3 5 7\n\ | |
2814 4 9 2 ]\n\ | |
2815 idx.type = \"()\";\n\ | |
2816 idx.subs = @{\":\", 1:2@};\n\ | |
2817 subsref(val, idx)\n\ | |
12642
f96b9b9f141b
doc: Periodic grammarcheck and spellcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents:
12171
diff
changeset
|
2818 @result{} [ 8 1\n\ |
f96b9b9f141b
doc: Periodic grammarcheck and spellcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents:
12171
diff
changeset
|
2819 3 5\n\ |
6631 | 2820 4 9 ]\n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8992
diff
changeset
|
2821 @end group\n\ |
6631 | 2822 @end example\n\ |
2823 \n\ | |
2824 @noindent\n\ | |
2825 Note that this is the same as writing @code{val(:,1:2)}.\n\ | |
13932
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2826 \n\ |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2827 If @var{idx} is an empty structure array with fields @samp{type}\n\ |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2828 and @samp{subs}, return @var{val}.\n\ |
6157 | 2829 @seealso{subsasgn, substruct}\n\ |
6153 | 2830 @end deftypefn") |
2831 { | |
2832 octave_value_list retval; | |
2833 | |
2834 if (args.length () == 2) | |
2835 { | |
2836 std::string type; | |
2837 std::list<octave_value_list> idx; | |
2838 | |
2839 decode_subscripts ("subsref", args(1), type, idx); | |
2840 | |
2841 if (! error_state) | |
10075
84b0725f4b09
return class types by reference in const Array element access functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10033
diff
changeset
|
2842 { |
13932
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2843 octave_value arg0 = args(0); |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2844 |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2845 if (type.empty ()) |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2846 retval = arg0; |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2847 else |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2848 retval = arg0.subsref (type, idx, nargout); |
10075
84b0725f4b09
return class types by reference in const Array element access functions
Jaroslav Hajek <highegg@gmail.com>
parents:
10033
diff
changeset
|
2849 } |
6153 | 2850 } |
2851 else | |
2852 print_usage (); | |
2853 | |
2854 return retval; | |
2855 } | |
2856 | |
2857 DEFUN (subsasgn, args, , | |
2858 "-*- texinfo -*-\n\ | |
2859 @deftypefn {Built-in Function} {} subsasgn (@var{val}, @var{idx}, @var{rhs})\n\ | |
2860 Perform the subscripted assignment operation according to\n\ | |
2861 the subscript specified by @var{idx}.\n\ | |
2862 \n\ | |
2863 The subscript @var{idx} is expected to be a structure array with\n\ | |
2864 fields @samp{type} and @samp{subs}. Valid values for @samp{type}\n\ | |
6248 | 2865 are @samp{\"()\"}, @samp{\"@{@}\"}, and @samp{\".\"}.\n\ |
6153 | 2866 The @samp{subs} field may be either @samp{\":\"} or a cell array\n\ |
2867 of index values.\n\ | |
6631 | 2868 \n\ |
2869 The following example shows how to set the two first columns of a\n\ | |
2870 3-by-3 matrix to zero.\n\ | |
2871 \n\ | |
2872 @example\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8992
diff
changeset
|
2873 @group\n\ |
6631 | 2874 val = magic(3);\n\ |
2875 idx.type = \"()\";\n\ | |
2876 idx.subs = @{\":\", 1:2@};\n\ | |
2877 subsasgn (val, idx, 0)\n\ | |
2878 @result{} [ 0 0 6\n\ | |
2879 0 0 7\n\ | |
2880 0 0 2 ]\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8992
diff
changeset
|
2881 @end group\n\ |
6631 | 2882 @end example\n\ |
2883 \n\ | |
2884 Note that this is the same as writing @code{val(:,1:2) = 0}.\n\ | |
13932
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2885 \n\ |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2886 If @var{idx} is an empty structure array with fields @samp{type}\n\ |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2887 and @samp{subs}, return @var{rhs}.\n\ |
6157 | 2888 @seealso{subsref, substruct}\n\ |
6153 | 2889 @end deftypefn") |
2890 { | |
2891 octave_value retval; | |
2892 | |
2893 if (args.length () == 3) | |
2894 { | |
2895 std::string type; | |
2896 std::list<octave_value_list> idx; | |
2897 | |
2898 decode_subscripts ("subsasgn", args(1), type, idx); | |
2899 | |
2900 if (! error_state) | |
13932
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2901 { |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2902 if (type.empty ()) |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2903 { |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2904 // Regularize a null matrix if stored into a variable. |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2905 |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2906 retval = args(2).storable_value (); |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2907 } |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2908 else |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2909 { |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2910 octave_value arg0 = args(0); |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2911 |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2912 arg0.make_unique (); |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2913 |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2914 if (! error_state) |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2915 retval= arg0.subsasgn (type, idx, args(2)); |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2916 } |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2917 } |
6153 | 2918 } |
2919 else | |
2920 print_usage (); | |
2921 | |
2922 return retval; | |
2923 } | |
13100
06bf445ee778
Add 6 tests for ov.cc
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12642
diff
changeset
|
2924 |
06bf445ee778
Add 6 tests for ov.cc
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12642
diff
changeset
|
2925 /* |
06bf445ee778
Add 6 tests for ov.cc
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12642
diff
changeset
|
2926 %!test |
06bf445ee778
Add 6 tests for ov.cc
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12642
diff
changeset
|
2927 %! a = reshape ([1:25], 5,5); |
13932
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2928 %! idx1 = substruct ("()", {3, 3}); |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2929 %! idx2 = substruct ("()", {2:2:5, 2:2:5}); |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2930 %! idx3 = substruct ("()", {":", [1,5]}); |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2931 %! idx4 = struct ("type", {}, "subs", {}); |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2932 %! assert (subsref (a, idx1), 13); |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2933 %! assert (subsref (a, idx2), [7 17; 9 19]); |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2934 %! assert (subsref (a, idx3), [1:5; 21:25]'); |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2935 %! assert (subsref (a, idx4), a); |
13100
06bf445ee778
Add 6 tests for ov.cc
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12642
diff
changeset
|
2936 %! a = subsasgn (a, idx1, 0); |
06bf445ee778
Add 6 tests for ov.cc
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12642
diff
changeset
|
2937 %! a = subsasgn (a, idx2, 0); |
06bf445ee778
Add 6 tests for ov.cc
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12642
diff
changeset
|
2938 %! a = subsasgn (a, idx3, 0); |
13932
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2939 %!# a = subsasgn (a, idx4, 0); |
13100
06bf445ee778
Add 6 tests for ov.cc
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12642
diff
changeset
|
2940 %! b = [0 6 11 16 0 |
06bf445ee778
Add 6 tests for ov.cc
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12642
diff
changeset
|
2941 %! 0 0 12 0 0 |
06bf445ee778
Add 6 tests for ov.cc
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12642
diff
changeset
|
2942 %! 0 8 0 18 0 |
06bf445ee778
Add 6 tests for ov.cc
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12642
diff
changeset
|
2943 %! 0 0 14 0 0 |
06bf445ee778
Add 6 tests for ov.cc
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12642
diff
changeset
|
2944 %! 0 10 15 20 0]; |
06bf445ee778
Add 6 tests for ov.cc
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12642
diff
changeset
|
2945 %! assert (a,b); |
06bf445ee778
Add 6 tests for ov.cc
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12642
diff
changeset
|
2946 |
06bf445ee778
Add 6 tests for ov.cc
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12642
diff
changeset
|
2947 %!test |
06bf445ee778
Add 6 tests for ov.cc
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12642
diff
changeset
|
2948 %! c = num2cell (reshape ([1:25],5,5)); |
13932
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2949 %! idx1 = substruct ("{}", {3, 3}); |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2950 %! idx2 = substruct ("()", {2:2:5, 2:2:5}); |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2951 %! idx3 = substruct ("()", {":", [1,5]}); |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2952 %! idx2p = substruct ("{}", {2:2:5, 2:2:5}); |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2953 %! idx3p = substruct ("{}", {":", [1,5]}); |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2954 %! idx4 = struct ("type", {}, "subs", {}); |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2955 %! assert ({ subsref(c, idx1) }, {13}); |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2956 %! assert ({ subsref(c, idx2p) }, {7 9 17 19}); |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2957 %! assert ({ subsref(c, idx3p) }, num2cell ([1:5, 21:25])); |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2958 %! assert (subsref(c, idx4), c); |
13100
06bf445ee778
Add 6 tests for ov.cc
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12642
diff
changeset
|
2959 %! c = subsasgn (c, idx1, 0); |
06bf445ee778
Add 6 tests for ov.cc
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12642
diff
changeset
|
2960 %! c = subsasgn (c, idx2, 0); |
06bf445ee778
Add 6 tests for ov.cc
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12642
diff
changeset
|
2961 %! c = subsasgn (c, idx3, 0); |
13932
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2962 %!# c = subsasgn (c, idx4, 0); |
13100
06bf445ee778
Add 6 tests for ov.cc
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12642
diff
changeset
|
2963 %! d = {0 6 11 16 0 |
06bf445ee778
Add 6 tests for ov.cc
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12642
diff
changeset
|
2964 %! 0 0 12 0 0 |
06bf445ee778
Add 6 tests for ov.cc
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12642
diff
changeset
|
2965 %! 0 8 0 18 0 |
06bf445ee778
Add 6 tests for ov.cc
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12642
diff
changeset
|
2966 %! 0 0 14 0 0 |
06bf445ee778
Add 6 tests for ov.cc
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12642
diff
changeset
|
2967 %! 0 10 15 20 0}; |
13932
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2968 %! assert (c, d); |
13100
06bf445ee778
Add 6 tests for ov.cc
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12642
diff
changeset
|
2969 |
06bf445ee778
Add 6 tests for ov.cc
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12642
diff
changeset
|
2970 %!test |
06bf445ee778
Add 6 tests for ov.cc
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12642
diff
changeset
|
2971 %! s.a = "ohai"; |
06bf445ee778
Add 6 tests for ov.cc
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12642
diff
changeset
|
2972 %! s.b = "dere"; |
06bf445ee778
Add 6 tests for ov.cc
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12642
diff
changeset
|
2973 %! s.c = 42; |
06bf445ee778
Add 6 tests for ov.cc
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12642
diff
changeset
|
2974 %! idx1 = substruct (".", "a"); |
06bf445ee778
Add 6 tests for ov.cc
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12642
diff
changeset
|
2975 %! idx2 = substruct (".", "b"); |
06bf445ee778
Add 6 tests for ov.cc
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12642
diff
changeset
|
2976 %! idx3 = substruct (".", "c"); |
13932
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2977 %! idx4 = struct ("type", {}, "subs", {}); |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2978 %! assert (subsref (s, idx1), "ohai"); |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2979 %! assert (subsref (s, idx2), "dere"); |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2980 %! assert (subsref (s, idx3), 42); |
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2981 %! assert (subsref (s, idx4), s); |
13100
06bf445ee778
Add 6 tests for ov.cc
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12642
diff
changeset
|
2982 %! s = subsasgn (s, idx1, "Hello"); |
06bf445ee778
Add 6 tests for ov.cc
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12642
diff
changeset
|
2983 %! s = subsasgn (s, idx2, "There"); |
06bf445ee778
Add 6 tests for ov.cc
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12642
diff
changeset
|
2984 %! s = subsasgn (s, idx3, 163); |
13932
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2985 %!# s = subsasgn (s, idx4, 163); |
13100
06bf445ee778
Add 6 tests for ov.cc
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12642
diff
changeset
|
2986 %! t.a = "Hello"; |
06bf445ee778
Add 6 tests for ov.cc
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12642
diff
changeset
|
2987 %! t.b = "There"; |
06bf445ee778
Add 6 tests for ov.cc
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12642
diff
changeset
|
2988 %! t.c = 163; |
13932
6ead4dc1ca55
subsref, subsasgn: allow empty subscript structs
John W. Eaton <jwe@octave.org>
parents:
13793
diff
changeset
|
2989 %! assert (s, t); |
13100
06bf445ee778
Add 6 tests for ov.cc
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12642
diff
changeset
|
2990 |
06bf445ee778
Add 6 tests for ov.cc
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12642
diff
changeset
|
2991 */ |
06bf445ee778
Add 6 tests for ov.cc
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12642
diff
changeset
|
2992 |
13712
f80473f24553
new functions is_sq_string and is_dq_string
John W. Eaton <jwe@octave.org>
parents:
13294
diff
changeset
|
2993 DEFUN (is_sq_string, args, , |
f80473f24553
new functions is_sq_string and is_dq_string
John W. Eaton <jwe@octave.org>
parents:
13294
diff
changeset
|
2994 "-*- texinfo -*-\n\ |
13793
605729cc5bbf
Add seealso links to docstrings for is_sq_string and is_dq_string
Rik <octave@nomad.inbox5.com>
parents:
13712
diff
changeset
|
2995 @deftypefn {Built-in Function} {} is_sq_string (@var{x})\n\ |
605729cc5bbf
Add seealso links to docstrings for is_sq_string and is_dq_string
Rik <octave@nomad.inbox5.com>
parents:
13712
diff
changeset
|
2996 Return true if @var{x} is a single-quoted character string.\n\ |
605729cc5bbf
Add seealso links to docstrings for is_sq_string and is_dq_string
Rik <octave@nomad.inbox5.com>
parents:
13712
diff
changeset
|
2997 @seealso{is_dq_string, ischar}\n\ |
13712
f80473f24553
new functions is_sq_string and is_dq_string
John W. Eaton <jwe@octave.org>
parents:
13294
diff
changeset
|
2998 @end deftypefn") |
f80473f24553
new functions is_sq_string and is_dq_string
John W. Eaton <jwe@octave.org>
parents:
13294
diff
changeset
|
2999 { |
f80473f24553
new functions is_sq_string and is_dq_string
John W. Eaton <jwe@octave.org>
parents:
13294
diff
changeset
|
3000 octave_value retval; |
f80473f24553
new functions is_sq_string and is_dq_string
John W. Eaton <jwe@octave.org>
parents:
13294
diff
changeset
|
3001 |
f80473f24553
new functions is_sq_string and is_dq_string
John W. Eaton <jwe@octave.org>
parents:
13294
diff
changeset
|
3002 if (args.length () == 1) |
f80473f24553
new functions is_sq_string and is_dq_string
John W. Eaton <jwe@octave.org>
parents:
13294
diff
changeset
|
3003 retval = args(0).is_sq_string (); |
f80473f24553
new functions is_sq_string and is_dq_string
John W. Eaton <jwe@octave.org>
parents:
13294
diff
changeset
|
3004 else |
f80473f24553
new functions is_sq_string and is_dq_string
John W. Eaton <jwe@octave.org>
parents:
13294
diff
changeset
|
3005 print_usage (); |
f80473f24553
new functions is_sq_string and is_dq_string
John W. Eaton <jwe@octave.org>
parents:
13294
diff
changeset
|
3006 |
f80473f24553
new functions is_sq_string and is_dq_string
John W. Eaton <jwe@octave.org>
parents:
13294
diff
changeset
|
3007 return retval; |
f80473f24553
new functions is_sq_string and is_dq_string
John W. Eaton <jwe@octave.org>
parents:
13294
diff
changeset
|
3008 } |
f80473f24553
new functions is_sq_string and is_dq_string
John W. Eaton <jwe@octave.org>
parents:
13294
diff
changeset
|
3009 |
f80473f24553
new functions is_sq_string and is_dq_string
John W. Eaton <jwe@octave.org>
parents:
13294
diff
changeset
|
3010 /* |
f80473f24553
new functions is_sq_string and is_dq_string
John W. Eaton <jwe@octave.org>
parents:
13294
diff
changeset
|
3011 %!assert (is_sq_string ('foo'), true); |
f80473f24553
new functions is_sq_string and is_dq_string
John W. Eaton <jwe@octave.org>
parents:
13294
diff
changeset
|
3012 %!assert (is_sq_string ("foo"), false); |
f80473f24553
new functions is_sq_string and is_dq_string
John W. Eaton <jwe@octave.org>
parents:
13294
diff
changeset
|
3013 %!assert (is_sq_string (1.0), false); |
f80473f24553
new functions is_sq_string and is_dq_string
John W. Eaton <jwe@octave.org>
parents:
13294
diff
changeset
|
3014 %!assert (is_sq_string ({2.0}), false); |
f80473f24553
new functions is_sq_string and is_dq_string
John W. Eaton <jwe@octave.org>
parents:
13294
diff
changeset
|
3015 %!error is_sq_string () |
f80473f24553
new functions is_sq_string and is_dq_string
John W. Eaton <jwe@octave.org>
parents:
13294
diff
changeset
|
3016 %!error is_sq_string ('foo', 2) |
f80473f24553
new functions is_sq_string and is_dq_string
John W. Eaton <jwe@octave.org>
parents:
13294
diff
changeset
|
3017 */ |
f80473f24553
new functions is_sq_string and is_dq_string
John W. Eaton <jwe@octave.org>
parents:
13294
diff
changeset
|
3018 |
f80473f24553
new functions is_sq_string and is_dq_string
John W. Eaton <jwe@octave.org>
parents:
13294
diff
changeset
|
3019 DEFUN (is_dq_string, args, , |
f80473f24553
new functions is_sq_string and is_dq_string
John W. Eaton <jwe@octave.org>
parents:
13294
diff
changeset
|
3020 "-*- texinfo -*-\n\ |
13793
605729cc5bbf
Add seealso links to docstrings for is_sq_string and is_dq_string
Rik <octave@nomad.inbox5.com>
parents:
13712
diff
changeset
|
3021 @deftypefn {Built-in Function} {} is_dq_string (@var{x})\n\ |
605729cc5bbf
Add seealso links to docstrings for is_sq_string and is_dq_string
Rik <octave@nomad.inbox5.com>
parents:
13712
diff
changeset
|
3022 Return true if @var{x} is a double-quoted character string.\n\ |
605729cc5bbf
Add seealso links to docstrings for is_sq_string and is_dq_string
Rik <octave@nomad.inbox5.com>
parents:
13712
diff
changeset
|
3023 @seealso{is_sq_string, ischar}\n\ |
13712
f80473f24553
new functions is_sq_string and is_dq_string
John W. Eaton <jwe@octave.org>
parents:
13294
diff
changeset
|
3024 @end deftypefn") |
f80473f24553
new functions is_sq_string and is_dq_string
John W. Eaton <jwe@octave.org>
parents:
13294
diff
changeset
|
3025 { |
f80473f24553
new functions is_sq_string and is_dq_string
John W. Eaton <jwe@octave.org>
parents:
13294
diff
changeset
|
3026 octave_value retval; |
f80473f24553
new functions is_sq_string and is_dq_string
John W. Eaton <jwe@octave.org>
parents:
13294
diff
changeset
|
3027 |
f80473f24553
new functions is_sq_string and is_dq_string
John W. Eaton <jwe@octave.org>
parents:
13294
diff
changeset
|
3028 if (args.length () == 1) |
f80473f24553
new functions is_sq_string and is_dq_string
John W. Eaton <jwe@octave.org>
parents:
13294
diff
changeset
|
3029 retval = args(0).is_dq_string (); |
f80473f24553
new functions is_sq_string and is_dq_string
John W. Eaton <jwe@octave.org>
parents:
13294
diff
changeset
|
3030 else |
f80473f24553
new functions is_sq_string and is_dq_string
John W. Eaton <jwe@octave.org>
parents:
13294
diff
changeset
|
3031 print_usage (); |
f80473f24553
new functions is_sq_string and is_dq_string
John W. Eaton <jwe@octave.org>
parents:
13294
diff
changeset
|
3032 |
f80473f24553
new functions is_sq_string and is_dq_string
John W. Eaton <jwe@octave.org>
parents:
13294
diff
changeset
|
3033 return retval; |
f80473f24553
new functions is_sq_string and is_dq_string
John W. Eaton <jwe@octave.org>
parents:
13294
diff
changeset
|
3034 } |
f80473f24553
new functions is_sq_string and is_dq_string
John W. Eaton <jwe@octave.org>
parents:
13294
diff
changeset
|
3035 |
f80473f24553
new functions is_sq_string and is_dq_string
John W. Eaton <jwe@octave.org>
parents:
13294
diff
changeset
|
3036 /* |
f80473f24553
new functions is_sq_string and is_dq_string
John W. Eaton <jwe@octave.org>
parents:
13294
diff
changeset
|
3037 %!assert (is_dq_string ("foo"), true); |
f80473f24553
new functions is_sq_string and is_dq_string
John W. Eaton <jwe@octave.org>
parents:
13294
diff
changeset
|
3038 %!assert (is_dq_string ('foo'), false); |
f80473f24553
new functions is_sq_string and is_dq_string
John W. Eaton <jwe@octave.org>
parents:
13294
diff
changeset
|
3039 %!assert (is_dq_string (1.0), false); |
f80473f24553
new functions is_sq_string and is_dq_string
John W. Eaton <jwe@octave.org>
parents:
13294
diff
changeset
|
3040 %!assert (is_dq_string ({2.0}), false); |
f80473f24553
new functions is_sq_string and is_dq_string
John W. Eaton <jwe@octave.org>
parents:
13294
diff
changeset
|
3041 %!error is_dq_string () |
f80473f24553
new functions is_sq_string and is_dq_string
John W. Eaton <jwe@octave.org>
parents:
13294
diff
changeset
|
3042 %!error is_dq_string ("foo", 2) |
f80473f24553
new functions is_sq_string and is_dq_string
John W. Eaton <jwe@octave.org>
parents:
13294
diff
changeset
|
3043 */ |