2376
|
1 /* |
|
2 |
7017
|
3 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2002, 2003, 2004, 2005, |
|
4 2006, 2007 John W. Eaton |
2376
|
5 |
|
6 This file is part of Octave. |
|
7 |
|
8 Octave is free software; you can redistribute it and/or modify it |
|
9 under the terms of the GNU General Public License as published by the |
7016
|
10 Free Software Foundation; either version 3 of the License, or (at your |
|
11 option) any later version. |
2376
|
12 |
|
13 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
16 for more details. |
|
17 |
|
18 You should have received a copy of the GNU General Public License |
7016
|
19 along with Octave; see the file COPYING. If not, see |
|
20 <http://www.gnu.org/licenses/>. |
2376
|
21 |
|
22 */ |
|
23 |
|
24 #ifdef HAVE_CONFIG_H |
|
25 #include <config.h> |
|
26 #endif |
|
27 |
4254
|
28 #include <climits> |
|
29 |
3503
|
30 #include <iostream> |
2901
|
31 |
2376
|
32 #include "lo-ieee.h" |
4732
|
33 #include "lo-mappers.h" |
4649
|
34 #include "so-array.h" |
2376
|
35 |
5759
|
36 #include "defun.h" |
2376
|
37 #include "gripes.h" |
|
38 #include "oct-map.h" |
2974
|
39 #include "oct-obj.h" |
2979
|
40 #include "oct-lvalue.h" |
3340
|
41 #include "oct-stream.h" |
2376
|
42 #include "ops.h" |
|
43 #include "ov-base.h" |
3928
|
44 #include "ov-cell.h" |
|
45 #include "ov-ch-mat.h" |
2376
|
46 #include "ov-complex.h" |
|
47 #include "ov-cx-mat.h" |
3928
|
48 #include "ov-list.h" |
|
49 #include "ov-range.h" |
|
50 #include "ov-re-mat.h" |
|
51 #include "ov-scalar.h" |
2376
|
52 #include "ov-str-mat.h" |
4343
|
53 #include "ov-fcn-handle.h" |
5759
|
54 #include "parse.h" |
|
55 #include "utils.h" |
2948
|
56 #include "variables.h" |
2376
|
57 |
4612
|
58 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_base_value, |
|
59 "<unknown type>", "unknown"); |
2376
|
60 |
5759
|
61 // If TRUE, turn off printing of results in functions (as if a |
|
62 // semicolon has been appended to each statement). |
7336
|
63 bool Vsilent_functions = false; |
5759
|
64 |
7193
|
65 // TRUE means to perform automatic sparse to real mutation if there |
|
66 // is memory to be saved |
|
67 bool Vsparse_auto_mutate = false; |
|
68 |
2376
|
69 octave_value |
4532
|
70 octave_base_value::squeeze (void) const |
|
71 { |
|
72 std::string nm = type_name (); |
|
73 error ("squeeze: invalid operation for %s type", nm.c_str ()); |
|
74 return octave_value (); |
|
75 } |
|
76 |
|
77 octave_value |
4247
|
78 octave_base_value::subsref (const std::string&, |
4219
|
79 const std::list<octave_value_list>&) |
3933
|
80 { |
|
81 std::string nm = type_name (); |
|
82 error ("can't perform indexing operations for %s type", nm.c_str ()); |
|
83 return octave_value (); |
|
84 } |
|
85 |
|
86 octave_value_list |
4247
|
87 octave_base_value::subsref (const std::string&, |
4219
|
88 const std::list<octave_value_list>&, int) |
3933
|
89 { |
|
90 std::string nm = type_name (); |
|
91 error ("can't perform indexing operations for %s type", nm.c_str ()); |
|
92 return octave_value (); |
|
93 } |
|
94 |
|
95 octave_value |
5885
|
96 octave_base_value::do_index_op (const octave_value_list&, bool) |
2974
|
97 { |
3523
|
98 std::string nm = type_name (); |
2974
|
99 error ("can't perform indexing operations for %s type", nm.c_str ()); |
|
100 return octave_value (); |
|
101 } |
|
102 |
|
103 octave_value_list |
3544
|
104 octave_base_value::do_multi_index_op (int, const octave_value_list&) |
2376
|
105 { |
3523
|
106 std::string nm = type_name (); |
2376
|
107 error ("can't perform indexing operations for %s type", nm.c_str ()); |
|
108 return octave_value (); |
|
109 } |
|
110 |
|
111 idx_vector |
|
112 octave_base_value::index_vector (void) const |
|
113 { |
3523
|
114 std::string nm = type_name (); |
2376
|
115 error ("%s type invalid as index value", nm.c_str ()); |
|
116 return idx_vector (); |
|
117 } |
|
118 |
5759
|
119 int |
|
120 octave_base_value::ndims (void) const |
|
121 { |
|
122 dim_vector dv = dims (); |
|
123 |
|
124 int n_dims = dv.length (); |
|
125 |
|
126 // Remove trailing singleton dimensions. |
|
127 |
|
128 for (int i = n_dims; i > 2; i--) |
|
129 { |
|
130 if (dv(i-1) == 1) |
|
131 n_dims--; |
|
132 else |
|
133 break; |
|
134 } |
|
135 |
|
136 // The result is always >= 2. |
|
137 |
|
138 if (n_dims < 2) |
|
139 n_dims = 2; |
|
140 |
|
141 return n_dims; |
|
142 } |
|
143 |
2376
|
144 octave_value |
4247
|
145 octave_base_value::subsasgn (const std::string& type, |
4219
|
146 const std::list<octave_value_list>& idx, |
3933
|
147 const octave_value& rhs) |
2376
|
148 { |
3933
|
149 octave_value retval; |
2376
|
150 |
3933
|
151 if (is_defined ()) |
|
152 { |
4139
|
153 if (is_numeric_type ()) |
|
154 { |
|
155 switch (type[0]) |
|
156 { |
|
157 case '(': |
|
158 { |
|
159 if (type.length () == 1) |
|
160 retval = numeric_assign (type, idx, rhs); |
4436
|
161 else if (is_empty ()) |
|
162 { |
|
163 // Allow conversion of empty matrix to some other |
|
164 // type in cases like |
|
165 // |
|
166 // x = []; x(i).f = rhs |
|
167 |
|
168 octave_value tmp = octave_value::empty_conv (type, rhs); |
|
169 |
|
170 retval = tmp.subsasgn (type, idx, rhs); |
|
171 } |
4139
|
172 else |
|
173 { |
|
174 std::string nm = type_name (); |
|
175 error ("in indexed assignment of %s, last rhs index must be ()", |
|
176 nm.c_str ()); |
|
177 } |
|
178 } |
|
179 break; |
|
180 |
|
181 case '{': |
|
182 case '.': |
|
183 { |
|
184 std::string nm = type_name (); |
|
185 error ("%s cannot be indexed with %c", nm.c_str (), type[0]); |
|
186 } |
|
187 break; |
|
188 |
|
189 default: |
|
190 panic_impossible (); |
|
191 } |
|
192 } |
|
193 else |
|
194 { |
|
195 std::string nm = type_name (); |
|
196 error ("can't perform indexed assignment for %s type", nm.c_str ()); |
|
197 } |
3933
|
198 } |
|
199 else |
|
200 { |
|
201 // Create new object of appropriate type for given index and rhs |
|
202 // types and then call subsasgn again for that object. |
|
203 |
|
204 octave_value tmp = octave_value::empty_conv (type, rhs); |
|
205 |
|
206 retval = tmp.subsasgn (type, idx, rhs); |
|
207 } |
|
208 |
|
209 return retval; |
2376
|
210 } |
|
211 |
5602
|
212 octave_idx_type |
|
213 octave_base_value::nnz (void) const |
|
214 { |
|
215 gripe_wrong_type_arg ("octave_base_value::nnz ()", type_name ()); |
|
216 return -1; |
|
217 } |
|
218 |
5604
|
219 octave_idx_type |
|
220 octave_base_value::nzmax (void) const |
|
221 { |
|
222 gripe_wrong_type_arg ("octave_base_value::nzmax ()", type_name ()); |
|
223 return -1; |
|
224 } |
|
225 |
5900
|
226 octave_idx_type |
|
227 octave_base_value::nfields (void) const |
|
228 { |
|
229 gripe_wrong_type_arg ("octave_base_value::nfields ()", type_name ()); |
|
230 return -1; |
|
231 } |
|
232 |
2376
|
233 octave_value |
4567
|
234 octave_base_value::reshape (const dim_vector&) const |
|
235 { |
|
236 gripe_wrong_type_arg ("octave_base_value::reshape ()", type_name ()); |
|
237 return octave_value (); |
|
238 } |
|
239 |
|
240 octave_value |
4593
|
241 octave_base_value::permute (const Array<int>&, bool) const |
|
242 { |
|
243 gripe_wrong_type_arg ("octave_base_value::permute ()", type_name ()); |
|
244 return octave_value (); |
|
245 } |
|
246 |
|
247 octave_value |
5731
|
248 octave_base_value::resize (const dim_vector&, bool) const |
4915
|
249 { |
|
250 gripe_wrong_type_arg ("octave_base_value::resize ()", type_name ()); |
|
251 return octave_value (); |
|
252 } |
|
253 |
5785
|
254 MatrixType |
|
255 octave_base_value::matrix_type (void) const |
|
256 { |
|
257 gripe_wrong_type_arg ("octave_base_value::matrix_type ()", type_name ()); |
|
258 return MatrixType (); |
|
259 } |
|
260 |
|
261 MatrixType |
|
262 octave_base_value::matrix_type (const MatrixType&) const |
|
263 { |
|
264 gripe_wrong_type_arg ("octave_base_value::matrix_type ()", type_name ()); |
|
265 return MatrixType (); |
|
266 } |
|
267 |
4915
|
268 octave_value |
5759
|
269 octave_base_value::all (int) const |
|
270 { |
|
271 return 0.0; |
|
272 } |
|
273 |
|
274 octave_value |
|
275 octave_base_value::any (int) const |
|
276 { |
|
277 return 0.0; |
|
278 } |
|
279 |
|
280 octave_value |
|
281 octave_base_value::convert_to_str (bool pad, bool force, char type) const |
|
282 { |
|
283 octave_value retval = convert_to_str_internal (pad, force, type); |
|
284 |
5781
|
285 if (! force && is_numeric_type ()) |
|
286 gripe_implicit_conversion ("Octave:num-to-str", |
|
287 type_name (), retval.type_name ()); |
5759
|
288 |
|
289 return retval; |
|
290 } |
|
291 |
|
292 octave_value |
5279
|
293 octave_base_value::convert_to_str_internal (bool, bool, char) const |
2376
|
294 { |
4452
|
295 gripe_wrong_type_arg ("octave_base_value::convert_to_str_internal ()", |
2376
|
296 type_name ()); |
|
297 return octave_value (); |
|
298 } |
|
299 |
|
300 void |
|
301 octave_base_value::convert_to_row_or_column_vector (void) |
|
302 { |
|
303 gripe_wrong_type_arg |
|
304 ("octave_base_value::convert_to_row_or_column_vector ()", |
|
305 type_name ()); |
|
306 } |
|
307 |
|
308 void |
3523
|
309 octave_base_value::print (std::ostream&, bool) const |
2376
|
310 { |
3195
|
311 gripe_wrong_type_arg ("octave_base_value::print ()", type_name ()); |
2376
|
312 } |
|
313 |
2901
|
314 void |
3523
|
315 octave_base_value::print_raw (std::ostream&, bool) const |
2901
|
316 { |
3195
|
317 gripe_wrong_type_arg ("octave_base_value::print_raw ()", type_name ()); |
2901
|
318 } |
|
319 |
|
320 bool |
3523
|
321 octave_base_value::print_name_tag (std::ostream& os, const std::string& name) const |
2901
|
322 { |
4604
|
323 bool retval = false; |
|
324 |
2901
|
325 indent (os); |
4604
|
326 |
|
327 if (print_as_scalar ()) |
|
328 os << name << " = "; |
|
329 else |
|
330 { |
|
331 os << name << " ="; |
|
332 newline (os); |
|
333 newline (os); |
|
334 retval = true; |
|
335 } |
|
336 |
|
337 return retval; |
2901
|
338 } |
|
339 |
3933
|
340 void |
5759
|
341 octave_base_value::print_with_name (std::ostream& output_buf, |
|
342 const std::string& name, |
|
343 bool print_padding) const |
|
344 { |
|
345 if (! (evaluating_function_body && Vsilent_functions)) |
|
346 { |
7336
|
347 bool pad_after = print_name_tag (output_buf, name); |
5759
|
348 |
|
349 print (output_buf); |
|
350 |
|
351 if (print_padding && pad_after) |
|
352 newline (output_buf); |
|
353 } |
|
354 } |
|
355 |
|
356 void |
3933
|
357 octave_base_value::print_info (std::ostream& os, |
4661
|
358 const std::string& /* prefix */) const |
3933
|
359 { |
|
360 os << "no info for type: " << type_name () << "\n"; |
|
361 } |
|
362 |
4254
|
363 #define INT_CONV_METHOD(T, F, MIN_LIMIT, MAX_LIMIT) \ |
|
364 T \ |
|
365 octave_base_value::F ## _value (bool require_int, bool frc_str_conv) const \ |
|
366 { \ |
|
367 T retval = 0; \ |
|
368 \ |
|
369 double d = double_value (frc_str_conv); \ |
|
370 \ |
|
371 if (! error_state) \ |
|
372 { \ |
|
373 if (require_int && D_NINT (d) != d) \ |
|
374 error ("conversion of %g to " #T " value failed", d); \ |
5054
|
375 else if (d < MIN_LIMIT) \ |
|
376 retval = MIN_LIMIT; \ |
|
377 else if (d > MAX_LIMIT) \ |
|
378 retval = MAX_LIMIT; \ |
4254
|
379 else \ |
4732
|
380 retval = static_cast<T> (fix (d)); \ |
4254
|
381 } \ |
|
382 else \ |
|
383 gripe_wrong_type_arg ("octave_base_value::" #F "_value ()", \ |
|
384 type_name ()); \ |
|
385 \ |
|
386 return retval; \ |
|
387 } |
3202
|
388 |
4254
|
389 INT_CONV_METHOD (short int, short, SHRT_MIN, SHRT_MAX) |
|
390 INT_CONV_METHOD (unsigned short int, ushort, 0, USHRT_MAX) |
3202
|
391 |
4254
|
392 INT_CONV_METHOD (int, int, INT_MIN, INT_MAX) |
|
393 INT_CONV_METHOD (unsigned int, uint, 0, UINT_MAX) |
3202
|
394 |
4254
|
395 INT_CONV_METHOD (long int, long, LONG_MIN, LONG_MAX) |
|
396 INT_CONV_METHOD (unsigned long int, ulong, 0, ULONG_MAX) |
3202
|
397 |
|
398 int |
|
399 octave_base_value::nint_value (bool frc_str_conv) const |
|
400 { |
|
401 int retval = 0; |
|
402 |
|
403 double d = double_value (frc_str_conv); |
|
404 |
|
405 if (! error_state) |
|
406 { |
|
407 if (xisnan (d)) |
|
408 { |
|
409 error ("conversion of NaN to integer value failed"); |
|
410 return retval; |
|
411 } |
|
412 |
4732
|
413 retval = static_cast<int> (fix (d)); |
3202
|
414 } |
|
415 else |
|
416 gripe_wrong_type_arg ("octave_base_value::nint_value ()", type_name ()); |
|
417 |
|
418 return retval; |
|
419 } |
|
420 |
2376
|
421 double |
|
422 octave_base_value::double_value (bool) const |
|
423 { |
4102
|
424 double retval = lo_ieee_nan_value (); |
2376
|
425 gripe_wrong_type_arg ("octave_base_value::double_value ()", type_name ()); |
|
426 return retval; |
|
427 } |
|
428 |
3351
|
429 Cell |
3539
|
430 octave_base_value::cell_value () const |
3351
|
431 { |
|
432 Cell retval; |
|
433 gripe_wrong_type_arg ("octave_base_value::cell_value()", type_name ()); |
|
434 return retval; |
|
435 } |
|
436 |
2376
|
437 Matrix |
|
438 octave_base_value::matrix_value (bool) const |
|
439 { |
|
440 Matrix retval; |
|
441 gripe_wrong_type_arg ("octave_base_value::matrix_value()", type_name ()); |
|
442 return retval; |
|
443 } |
|
444 |
4507
|
445 NDArray |
4550
|
446 octave_base_value::array_value (bool) const |
4505
|
447 { |
4507
|
448 NDArray retval; |
4550
|
449 gripe_wrong_type_arg ("octave_base_value::array_value()", type_name ()); |
4505
|
450 return retval; |
|
451 } |
|
452 |
2376
|
453 Complex |
|
454 octave_base_value::complex_value (bool) const |
|
455 { |
4102
|
456 double tmp = lo_ieee_nan_value (); |
|
457 Complex retval (tmp, tmp); |
2376
|
458 gripe_wrong_type_arg ("octave_base_value::complex_value()", type_name ()); |
|
459 return retval; |
|
460 } |
|
461 |
|
462 ComplexMatrix |
|
463 octave_base_value::complex_matrix_value (bool) const |
|
464 { |
|
465 ComplexMatrix retval; |
|
466 gripe_wrong_type_arg ("octave_base_value::complex_matrix_value()", |
|
467 type_name ()); |
|
468 return retval; |
|
469 } |
|
470 |
4550
|
471 ComplexNDArray |
|
472 octave_base_value::complex_array_value (bool) const |
|
473 { |
|
474 ComplexNDArray retval; |
|
475 gripe_wrong_type_arg ("octave_base_value::complex_array_value()", |
|
476 type_name ()); |
|
477 return retval; |
|
478 } |
|
479 |
|
480 bool |
5943
|
481 octave_base_value::bool_value (bool) const |
4550
|
482 { |
|
483 bool retval = false; |
|
484 gripe_wrong_type_arg ("octave_base_value::bool_value()", type_name ()); |
|
485 return retval; |
|
486 } |
|
487 |
|
488 boolMatrix |
5943
|
489 octave_base_value::bool_matrix_value (bool) const |
4550
|
490 { |
|
491 boolMatrix retval; |
|
492 gripe_wrong_type_arg ("octave_base_value::bool_matrix_value()", |
|
493 type_name ()); |
|
494 return retval; |
|
495 } |
|
496 |
|
497 boolNDArray |
5943
|
498 octave_base_value::bool_array_value (bool) const |
4550
|
499 { |
|
500 boolNDArray retval; |
|
501 gripe_wrong_type_arg ("octave_base_value::bool_array_value()", |
|
502 type_name ()); |
|
503 return retval; |
|
504 } |
|
505 |
2376
|
506 charMatrix |
4741
|
507 octave_base_value::char_matrix_value (bool force) const |
2376
|
508 { |
|
509 charMatrix retval; |
4257
|
510 |
4741
|
511 octave_value tmp = convert_to_str (false, force); |
4257
|
512 |
4452
|
513 if (! error_state) |
|
514 retval = tmp.char_matrix_value (); |
|
515 |
2376
|
516 return retval; |
|
517 } |
|
518 |
4550
|
519 charNDArray |
|
520 octave_base_value::char_array_value (bool) const |
|
521 { |
|
522 charNDArray retval; |
|
523 gripe_wrong_type_arg ("octave_base_value::char_array_value()", |
|
524 type_name ()); |
|
525 return retval; |
|
526 } |
|
527 |
5164
|
528 SparseMatrix |
|
529 octave_base_value::sparse_matrix_value (bool) const |
|
530 { |
|
531 SparseMatrix retval; |
|
532 gripe_wrong_type_arg ("octave_base_value::sparse_matrix_value()", type_name ()); |
|
533 return retval; |
|
534 } |
|
535 |
|
536 SparseComplexMatrix |
|
537 octave_base_value::sparse_complex_matrix_value (bool) const |
|
538 { |
|
539 SparseComplexMatrix retval; |
|
540 gripe_wrong_type_arg ("octave_base_value::sparse_complex_matrix_value()", type_name ()); |
|
541 return retval; |
|
542 } |
|
543 |
|
544 SparseBoolMatrix |
|
545 octave_base_value::sparse_bool_matrix_value (bool) const |
|
546 { |
|
547 SparseBoolMatrix retval; |
|
548 gripe_wrong_type_arg ("octave_base_value::sparse_bool_matrix_value()", type_name ()); |
|
549 return retval; |
|
550 } |
|
551 |
4910
|
552 octave_int8 |
|
553 octave_base_value::int8_scalar_value (void) const |
|
554 { |
|
555 octave_int8 retval; |
|
556 gripe_wrong_type_arg ("octave_base_value::int8_scalar_value()", |
|
557 type_name ()); |
|
558 return retval; |
|
559 } |
|
560 |
|
561 octave_int16 |
|
562 octave_base_value::int16_scalar_value (void) const |
|
563 { |
|
564 octave_int16 retval; |
|
565 gripe_wrong_type_arg ("octave_base_value::int16_scalar_value()", |
|
566 type_name ()); |
|
567 return retval; |
|
568 } |
|
569 |
|
570 octave_int32 |
|
571 octave_base_value::int32_scalar_value (void) const |
|
572 { |
|
573 octave_int32 retval; |
|
574 gripe_wrong_type_arg ("octave_base_value::int32_scalar_value()", |
|
575 type_name ()); |
|
576 return retval; |
|
577 } |
|
578 |
|
579 octave_int64 |
|
580 octave_base_value::int64_scalar_value (void) const |
|
581 { |
|
582 octave_int64 retval; |
|
583 gripe_wrong_type_arg ("octave_base_value::int64_scalar_value()", |
|
584 type_name ()); |
|
585 return retval; |
|
586 } |
|
587 |
|
588 octave_uint8 |
|
589 octave_base_value::uint8_scalar_value (void) const |
|
590 { |
|
591 octave_uint8 retval; |
|
592 gripe_wrong_type_arg ("octave_base_value::uint8_scalar_value()", |
|
593 type_name ()); |
|
594 return retval; |
|
595 } |
|
596 |
|
597 octave_uint16 |
|
598 octave_base_value::uint16_scalar_value (void) const |
|
599 { |
|
600 octave_uint16 retval; |
|
601 gripe_wrong_type_arg ("octave_base_value::uint16_scalar_value()", |
|
602 type_name ()); |
|
603 return retval; |
|
604 } |
|
605 |
|
606 octave_uint32 |
|
607 octave_base_value::uint32_scalar_value (void) const |
|
608 { |
|
609 octave_uint32 retval; |
|
610 gripe_wrong_type_arg ("octave_base_value::uint32_scalar_value()", |
|
611 type_name ()); |
|
612 return retval; |
|
613 } |
|
614 |
|
615 octave_uint64 |
|
616 octave_base_value::uint64_scalar_value (void) const |
|
617 { |
|
618 octave_uint64 retval; |
|
619 gripe_wrong_type_arg ("octave_base_value::uint64_scalar_value()", |
|
620 type_name ()); |
|
621 return retval; |
|
622 } |
|
623 |
4906
|
624 int8NDArray |
|
625 octave_base_value::int8_array_value (void) const |
|
626 { |
|
627 int8NDArray retval; |
|
628 gripe_wrong_type_arg ("octave_base_value::int8_array_value()", |
|
629 type_name ()); |
4910
|
630 return retval; |
4906
|
631 } |
|
632 |
|
633 int16NDArray |
|
634 octave_base_value::int16_array_value (void) const |
|
635 { |
|
636 int16NDArray retval; |
|
637 gripe_wrong_type_arg ("octave_base_value::int16_array_value()", |
|
638 type_name ()); |
4910
|
639 return retval; |
4906
|
640 } |
|
641 |
|
642 int32NDArray |
|
643 octave_base_value::int32_array_value (void) const |
|
644 { |
|
645 int32NDArray retval; |
|
646 gripe_wrong_type_arg ("octave_base_value::int32_array_value()", |
|
647 type_name ()); |
4910
|
648 return retval; |
4906
|
649 } |
|
650 |
|
651 int64NDArray |
|
652 octave_base_value::int64_array_value (void) const |
|
653 { |
|
654 int64NDArray retval; |
|
655 gripe_wrong_type_arg ("octave_base_value::int64_array_value()", |
|
656 type_name ()); |
4910
|
657 return retval; |
4906
|
658 } |
|
659 |
|
660 uint8NDArray |
|
661 octave_base_value::uint8_array_value (void) const |
|
662 { |
|
663 uint8NDArray retval; |
|
664 gripe_wrong_type_arg ("octave_base_value::uint8_array_value()", |
|
665 type_name ()); |
4910
|
666 return retval; |
4906
|
667 } |
|
668 |
|
669 uint16NDArray |
|
670 octave_base_value::uint16_array_value (void) const |
|
671 { |
|
672 uint16NDArray retval; |
|
673 gripe_wrong_type_arg ("octave_base_value::uint16_array_value()", |
|
674 type_name ()); |
4910
|
675 return retval; |
4906
|
676 } |
|
677 |
|
678 uint32NDArray |
|
679 octave_base_value::uint32_array_value (void) const |
|
680 { |
|
681 uint32NDArray retval; |
|
682 gripe_wrong_type_arg ("octave_base_value::uint32_array_value()", |
|
683 type_name ()); |
4910
|
684 return retval; |
4906
|
685 } |
|
686 |
|
687 uint64NDArray |
|
688 octave_base_value::uint64_array_value (void) const |
|
689 { |
|
690 uint64NDArray retval; |
|
691 gripe_wrong_type_arg ("octave_base_value::uint64_array_value()", |
|
692 type_name ()); |
4910
|
693 return retval; |
4906
|
694 } |
|
695 |
2493
|
696 string_vector |
5715
|
697 octave_base_value::all_strings (bool pad) const |
2376
|
698 { |
2493
|
699 string_vector retval; |
4257
|
700 |
5715
|
701 octave_value tmp = convert_to_str (pad, true); |
4257
|
702 |
4452
|
703 if (! error_state) |
|
704 retval = tmp.all_strings (); |
4257
|
705 |
2376
|
706 return retval; |
|
707 } |
|
708 |
3536
|
709 std::string |
4457
|
710 octave_base_value::string_value (bool force) const |
2376
|
711 { |
3523
|
712 std::string retval; |
4257
|
713 |
4457
|
714 octave_value tmp = convert_to_str (force); |
4257
|
715 |
4452
|
716 if (! error_state) |
|
717 retval = tmp.string_value (); |
4257
|
718 |
2376
|
719 return retval; |
|
720 } |
|
721 |
|
722 Range |
|
723 octave_base_value::range_value (void) const |
|
724 { |
|
725 Range retval; |
|
726 gripe_wrong_type_arg ("octave_base_value::range_value()", type_name ()); |
|
727 return retval; |
|
728 } |
|
729 |
|
730 Octave_map |
|
731 octave_base_value::map_value (void) const |
|
732 { |
|
733 Octave_map retval; |
|
734 gripe_wrong_type_arg ("octave_base_value::map_value()", type_name ()); |
|
735 return retval; |
|
736 } |
|
737 |
3933
|
738 string_vector |
|
739 octave_base_value::map_keys (void) const |
|
740 { |
|
741 string_vector retval; |
|
742 gripe_wrong_type_arg ("octave_base_value::map_keys()", type_name ()); |
|
743 return retval; |
|
744 } |
|
745 |
4645
|
746 std::streamoff |
4643
|
747 octave_base_value::streamoff_value (void) const |
|
748 { |
4649
|
749 std::streamoff retval (-1); |
4645
|
750 gripe_wrong_type_arg ("octave_base_value::streamoff_value()", type_name ()); |
|
751 return retval; |
|
752 } |
|
753 |
|
754 streamoff_array |
|
755 octave_base_value::streamoff_array_value (void) const |
|
756 { |
4643
|
757 streamoff_array retval; |
4645
|
758 gripe_wrong_type_arg ("octave_base_value::streamoff_array_value()", |
|
759 type_name ()); |
4643
|
760 return retval; |
|
761 } |
|
762 |
2974
|
763 octave_function * |
|
764 octave_base_value::function_value (bool silent) |
|
765 { |
|
766 octave_function *retval = 0; |
|
767 |
|
768 if (! silent) |
|
769 gripe_wrong_type_arg ("octave_base_value::function_value()", |
|
770 type_name ()); |
|
771 return retval; |
|
772 } |
|
773 |
4700
|
774 octave_user_function * |
|
775 octave_base_value::user_function_value (bool silent) |
|
776 { |
|
777 octave_user_function *retval = 0; |
|
778 |
|
779 if (! silent) |
|
780 gripe_wrong_type_arg ("octave_base_value::user_function_value()", |
|
781 type_name ()); |
|
782 return retval; |
|
783 } |
|
784 |
4346
|
785 octave_fcn_handle * |
4343
|
786 octave_base_value::fcn_handle_value (bool silent) |
|
787 { |
4346
|
788 octave_fcn_handle *retval = 0; |
4343
|
789 |
|
790 if (! silent) |
|
791 gripe_wrong_type_arg ("octave_base_value::fcn_handle_value()", |
|
792 type_name ()); |
|
793 return retval; |
|
794 } |
|
795 |
4933
|
796 octave_fcn_inline * |
|
797 octave_base_value::fcn_inline_value (bool silent) |
|
798 { |
|
799 octave_fcn_inline *retval = 0; |
|
800 |
|
801 if (! silent) |
|
802 gripe_wrong_type_arg ("octave_base_value::fcn_inline_value()", |
|
803 type_name ()); |
|
804 return retval; |
|
805 } |
|
806 |
2882
|
807 octave_value_list |
|
808 octave_base_value::list_value (void) const |
|
809 { |
|
810 octave_value_list retval; |
|
811 gripe_wrong_type_arg ("octave_base_value::list_value()", type_name ()); |
|
812 return retval; |
|
813 } |
|
814 |
4687
|
815 bool |
6974
|
816 octave_base_value::save_ascii (std::ostream&) |
4687
|
817 { |
|
818 gripe_wrong_type_arg ("octave_base_value::save_ascii()", type_name ()); |
|
819 return false; |
|
820 } |
|
821 |
|
822 bool |
|
823 octave_base_value::load_ascii (std::istream&) |
|
824 { |
|
825 gripe_wrong_type_arg ("octave_base_value::load_ascii()", type_name ()); |
|
826 return false; |
|
827 } |
|
828 |
|
829 bool |
|
830 octave_base_value::save_binary (std::ostream&, bool&) |
|
831 { |
|
832 gripe_wrong_type_arg ("octave_base_value::save_binary()", type_name ()); |
|
833 return false; |
|
834 } |
|
835 |
|
836 bool |
|
837 octave_base_value::load_binary (std::istream&, bool, |
|
838 oct_mach_info::float_format) |
|
839 { |
|
840 gripe_wrong_type_arg ("octave_base_value::load_binary()", type_name ()); |
|
841 return false; |
|
842 } |
|
843 |
|
844 #if defined (HAVE_HDF5) |
4944
|
845 |
4687
|
846 bool |
|
847 octave_base_value::save_hdf5 (hid_t, const char *, bool) |
|
848 { |
|
849 gripe_wrong_type_arg ("octave_base_value::save_binary()", type_name ()); |
|
850 |
|
851 return false; |
|
852 } |
|
853 |
|
854 bool |
|
855 octave_base_value::load_hdf5 (hid_t, const char *, bool) |
|
856 { |
|
857 gripe_wrong_type_arg ("octave_base_value::load_binary()", type_name ()); |
|
858 |
|
859 return false; |
|
860 } |
4944
|
861 |
4687
|
862 #endif |
|
863 |
4944
|
864 int |
|
865 octave_base_value::write (octave_stream&, int, oct_data_conv::data_type, |
|
866 int, oct_mach_info::float_format) const |
|
867 { |
|
868 gripe_wrong_type_arg ("octave_base_value::write()", type_name ()); |
|
869 |
|
870 return false; |
|
871 } |
|
872 |
5900
|
873 mxArray * |
|
874 octave_base_value::as_mxArray (void) const |
|
875 { |
|
876 gripe_wrong_type_arg ("octave_base_value::as_mxArray ()", type_name ()); |
|
877 |
|
878 return 0; |
|
879 } |
|
880 |
5759
|
881 static void |
|
882 gripe_indexed_assignment (const std::string& tn1, const std::string& tn2) |
|
883 { |
|
884 error ("assignment of `%s' to indexed `%s' not implemented", |
|
885 tn2.c_str (), tn1.c_str ()); |
|
886 } |
|
887 |
|
888 static void |
|
889 gripe_assign_conversion_failed (const std::string& tn1, |
|
890 const std::string& tn2) |
|
891 { |
|
892 error ("type conversion for assignment of `%s' to indexed `%s' failed", |
|
893 tn2.c_str (), tn1.c_str ()); |
|
894 } |
|
895 |
|
896 static void |
|
897 gripe_no_conversion (const std::string& on, const std::string& tn1, |
|
898 const std::string& tn2) |
|
899 { |
|
900 error ("operator %s: no conversion for assignment of `%s' to indexed `%s'", |
|
901 on.c_str (), tn2.c_str (), tn1.c_str ()); |
|
902 } |
|
903 |
|
904 octave_value |
|
905 octave_base_value::numeric_assign (const std::string& type, |
|
906 const std::list<octave_value_list>& idx, |
|
907 const octave_value& rhs) |
|
908 { |
|
909 octave_value retval; |
|
910 |
|
911 int t_lhs = type_id (); |
|
912 int t_rhs = rhs.type_id (); |
|
913 |
|
914 octave_value_typeinfo::assign_op_fcn f |
|
915 = octave_value_typeinfo::lookup_assign_op (octave_value::op_asn_eq, |
|
916 t_lhs, t_rhs); |
|
917 |
|
918 bool done = false; |
|
919 |
|
920 if (f) |
|
921 { |
|
922 f (*this, idx.front (), rhs.get_rep ()); |
|
923 |
|
924 done = (! error_state); |
|
925 } |
|
926 |
|
927 if (done) |
|
928 { |
|
929 count++; |
|
930 retval = octave_value (this); |
|
931 } |
|
932 else |
|
933 { |
|
934 int t_result |
|
935 = octave_value_typeinfo::lookup_pref_assign_conv (t_lhs, t_rhs); |
|
936 |
|
937 if (t_result >= 0) |
|
938 { |
|
939 octave_base_value::type_conv_fcn cf |
|
940 = octave_value_typeinfo::lookup_widening_op (t_lhs, t_result); |
|
941 |
|
942 if (cf) |
|
943 { |
5874
|
944 octave_base_value *tmp = cf (*this); |
5759
|
945 |
|
946 if (tmp) |
|
947 { |
5874
|
948 octave_value val (tmp); |
|
949 |
|
950 retval = val.subsasgn (type, idx, rhs); |
5759
|
951 |
|
952 done = (! error_state); |
|
953 } |
|
954 else |
|
955 gripe_assign_conversion_failed (type_name (), |
|
956 rhs.type_name ()); |
|
957 } |
|
958 else |
|
959 gripe_indexed_assignment (type_name (), rhs.type_name ()); |
|
960 } |
|
961 |
|
962 if (! (done || error_state)) |
|
963 { |
|
964 octave_value tmp_rhs; |
|
965 |
|
966 octave_base_value::type_conv_fcn cf_rhs |
|
967 = rhs.numeric_conversion_function (); |
|
968 |
|
969 if (cf_rhs) |
|
970 { |
|
971 octave_base_value *tmp = cf_rhs (rhs.get_rep ()); |
|
972 |
|
973 if (tmp) |
|
974 tmp_rhs = octave_value (tmp); |
|
975 else |
|
976 { |
|
977 gripe_assign_conversion_failed (type_name (), |
|
978 rhs.type_name ()); |
|
979 return octave_value (); |
|
980 } |
|
981 } |
|
982 else |
|
983 tmp_rhs = rhs; |
|
984 |
|
985 octave_base_value::type_conv_fcn cf_this |
|
986 = numeric_conversion_function (); |
|
987 |
5897
|
988 count++; |
|
989 octave_value tmp_lhs = octave_value (this); |
5759
|
990 |
|
991 if (cf_this) |
|
992 { |
|
993 octave_base_value *tmp = cf_this (*this); |
|
994 |
|
995 if (tmp) |
5897
|
996 tmp_lhs = octave_value (tmp); |
5759
|
997 else |
|
998 { |
|
999 gripe_assign_conversion_failed (type_name (), |
|
1000 rhs.type_name ()); |
|
1001 return octave_value (); |
|
1002 } |
|
1003 } |
|
1004 |
|
1005 if (cf_this || cf_rhs) |
|
1006 { |
5897
|
1007 retval = tmp_lhs.subsasgn (type, idx, tmp_rhs); |
5759
|
1008 |
|
1009 done = (! error_state); |
|
1010 } |
|
1011 else |
|
1012 gripe_no_conversion (octave_value::assign_op_as_string (octave_value::op_asn_eq), |
|
1013 type_name (), rhs.type_name ()); |
|
1014 } |
|
1015 } |
|
1016 |
|
1017 // The assignment may have converted to a type that is wider than |
|
1018 // necessary. |
|
1019 |
|
1020 retval.maybe_mutate (); |
|
1021 |
|
1022 return retval; |
|
1023 } |
|
1024 |
|
1025 // Current indentation. |
|
1026 int octave_base_value::curr_print_indent_level = 0; |
|
1027 |
|
1028 // TRUE means we are at the beginning of a line. |
|
1029 bool octave_base_value::beginning_of_line = true; |
|
1030 |
|
1031 // Each print() function should call this before printing anything. |
|
1032 // |
|
1033 // This doesn't need to be fast, but isn't there a better way? |
|
1034 |
|
1035 void |
|
1036 octave_base_value::indent (std::ostream& os) const |
|
1037 { |
|
1038 assert (curr_print_indent_level >= 0); |
|
1039 |
|
1040 if (beginning_of_line) |
|
1041 { |
5775
|
1042 // FIXME -- do we need this? |
5759
|
1043 // os << prefix; |
|
1044 |
|
1045 for (int i = 0; i < curr_print_indent_level; i++) |
|
1046 os << " "; |
|
1047 |
|
1048 beginning_of_line = false; |
|
1049 } |
|
1050 } |
|
1051 |
|
1052 // All print() functions should use this to print new lines. |
|
1053 |
|
1054 void |
|
1055 octave_base_value::newline (std::ostream& os) const |
|
1056 { |
|
1057 os << "\n"; |
|
1058 |
|
1059 beginning_of_line = true; |
|
1060 } |
|
1061 |
|
1062 // For ressetting print state. |
|
1063 |
|
1064 void |
|
1065 octave_base_value::reset (void) const |
|
1066 { |
|
1067 beginning_of_line = true; |
|
1068 curr_print_indent_level = 0; |
|
1069 } |
|
1070 |
3203
|
1071 CONVDECLX (matrix_conv) |
2376
|
1072 { |
|
1073 return new octave_matrix (); |
|
1074 } |
|
1075 |
3203
|
1076 CONVDECLX (complex_matrix_conv) |
2376
|
1077 { |
|
1078 return new octave_complex_matrix (); |
|
1079 } |
|
1080 |
3203
|
1081 CONVDECLX (string_conv) |
2376
|
1082 { |
|
1083 return new octave_char_matrix_str (); |
|
1084 } |
|
1085 |
3928
|
1086 CONVDECLX (cell_conv) |
|
1087 { |
|
1088 return new octave_cell (); |
|
1089 } |
|
1090 |
2376
|
1091 void |
|
1092 install_base_type_conversions (void) |
|
1093 { |
|
1094 INSTALL_ASSIGNCONV (octave_base_value, octave_scalar, octave_matrix); |
|
1095 INSTALL_ASSIGNCONV (octave_base_value, octave_matrix, octave_matrix); |
|
1096 INSTALL_ASSIGNCONV (octave_base_value, octave_complex, octave_complex_matrix); |
|
1097 INSTALL_ASSIGNCONV (octave_base_value, octave_complex_matrix, octave_complex_matrix); |
|
1098 INSTALL_ASSIGNCONV (octave_base_value, octave_range, octave_matrix); |
|
1099 INSTALL_ASSIGNCONV (octave_base_value, octave_char_matrix_str, octave_char_matrix_str); |
3928
|
1100 INSTALL_ASSIGNCONV (octave_base_value, octave_cell, octave_cell); |
2376
|
1101 |
|
1102 INSTALL_WIDENOP (octave_base_value, octave_matrix, matrix_conv); |
|
1103 INSTALL_WIDENOP (octave_base_value, octave_complex_matrix, complex_matrix_conv); |
|
1104 INSTALL_WIDENOP (octave_base_value, octave_char_matrix_str, string_conv); |
3928
|
1105 INSTALL_WIDENOP (octave_base_value, octave_cell, cell_conv); |
2376
|
1106 } |
|
1107 |
5794
|
1108 DEFUN (silent_functions, args, nargout, |
|
1109 "-*- texinfo -*-\n\ |
|
1110 @deftypefn {Built-in Function} {@var{val} =} silent_functions ()\n\ |
|
1111 @deftypefnx {Built-in Function} {@var{old_val} =} silent_functions (@var{new_val})\n\ |
|
1112 Query or set the internal variable that controls whether internal\n\ |
|
1113 output from a function is suppressed. If this option is disabled,\n\ |
|
1114 Octave will display the results produced by evaluating expressions\n\ |
|
1115 within a function body that are not terminated with a semicolon.\n\ |
|
1116 @end deftypefn") |
5759
|
1117 { |
5794
|
1118 return SET_INTERNAL_VARIABLE (silent_functions); |
5759
|
1119 } |
|
1120 |
7193
|
1121 DEFUN (sparse_auto_mutate, args, nargout, |
|
1122 "-*- texinfo -*-\n\ |
|
1123 @deftypefn {Built-in Function} {@var{val} =} sparse_auto_mutate ()\n\ |
|
1124 @deftypefnx {Built-in Function} {@var{old_val} =} sparse_auto_mutate (@var{new_val})\n\ |
|
1125 Query or set the internal variable that controls whether Octave will\n\ |
|
1126 automatically mutate sparse matrices to real matrices to save memory.\n\ |
|
1127 For example,\n\ |
|
1128 \n\ |
|
1129 @example\n\ |
|
1130 s = speye(3);\n\ |
|
1131 sparse_auto_mutate (false)\n\ |
|
1132 s (:, 1) = 1;\n\ |
|
1133 typeinfo (s)\n\ |
|
1134 @result{} sparse matrix\n\ |
|
1135 sparse_auto_mutate (true)\n\ |
|
1136 s (1, :) = 1;\n\ |
|
1137 typeinfo (s)\n\ |
|
1138 @result{} matrix\n\ |
|
1139 @end example\n\ |
|
1140 @end deftypefn") |
|
1141 { |
|
1142 return SET_INTERNAL_VARIABLE (sparse_auto_mutate); |
|
1143 } |
|
1144 |
2376
|
1145 /* |
|
1146 ;;; Local Variables: *** |
|
1147 ;;; mode: C++ *** |
|
1148 ;;; End: *** |
|
1149 */ |